net.sf.asyncobjects
Class AsyncAction<T>

java.lang.Object
  extended by net.sf.asyncobjects.AsyncAction<T>
Type Parameters:
T - a value type

public abstract class AsyncAction<T>
extends Object

Asynchronous action. This utility class allows creating temporary vat locally and communicate with objects in some other vat.

Author:
const

Constructor Summary
AsyncAction()
           
 
Method Summary
 T doInCurrentThread()
          Execute this action in the current thread.
 T doInCurrentThread(ThreadBasedRunner runner)
          Execute this action in the current thread.
 Promise<T> doInOtherVat(Vat vat)
          Execute action in context of other vat.
 Promise<T> executeLater()
          Execute action in current vat.
 Promise<T> executeNow()
          Execute action in current vat.
 void executeNow(AResolver<? super T> resolver)
          Execute action in current vat.
abstract  Promise<? extends T> run()
          This abstract method is basically "main" for vat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncAction

public AsyncAction()
Method Detail

run

public abstract Promise<? extends T> run()
                                  throws Throwable
This abstract method is basically "main" for vat. The vat terminates under the following conditions:

Returns:
a promise that case vat termination when it is smashed or resolved.
Throws:
Throwable - if any problem occurs

doInOtherVat

public final Promise<T> doInOtherVat(Vat vat)
Execute action in context of other vat. The method should be executed in context of some vat.

Parameters:
vat - a vat where body of action should be executed.
Returns:
a promise for result of action.

executeNow

public final Promise<T> executeNow()
Execute action in current vat. The action is executed in current turn. However if result is not a promise, it is wrapped into promise.

Returns:
a promise for action

executeNow

public final void executeNow(AResolver<? super T> resolver)
Execute action in current vat. The action is executed in current turn. However if result is not a promise, it is wrapped into promise.

Parameters:
resolver - a resolver for action

executeLater

public final Promise<T> executeLater()
Execute action in current vat. The action is executed in current turn. However if result is not a promise, it is wrapped into promise.

Returns:
a promise for action

doInCurrentThread

public T doInCurrentThread()
                    throws InvocationTargetException
Execute this action in the current thread. This method requires that there is no runner running with this tread.

Returns:
a value that is result of execution.
Throws:
InvocationTargetException - if promise has been smashed.

doInCurrentThread

public T doInCurrentThread(ThreadBasedRunner runner)
                    throws InvocationTargetException
Execute this action in the current thread. This method requires that there is no runner running with this tread.

Parameters:
runner - a runner to use for execution. The runner must be in the VatRunner.VatRunnerState.NOT_STARTED state.
Returns:
a value that is result of execution.
Throws:
InvocationTargetException - if promise has been smashed.


Copyright © 2002-2007 Constantine Plotnikov. All Rights Reserved.