net.sf.asyncobjects.vats
Class VatUtils

java.lang.Object
  extended by net.sf.asyncobjects.vats.VatUtils

public class VatUtils
extends Object

This class contains some experimental vat utilities

Author:
const

Constructor Summary
VatUtils()
           
 
Method Summary
static
<T> T
runInCurrentThread(Vat targetVat, AsyncAction<T> action)
          The version of runInCurrentThread(Vat, ThreadBasedRunner, AsyncAction) that uses SingleThreadRunner as runner.
static
<T> T
runInCurrentThread(Vat targetVat, ThreadBasedRunner runner, AsyncAction<T> action)
          This is an extremely tricky method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VatUtils

public VatUtils()
Method Detail

runInCurrentThread

@Experimental
public static <T> T runInCurrentThread(Vat targetVat,
                                                    ThreadBasedRunner runner,
                                                    AsyncAction<T> action)
                            throws InvocationTargetException

This is an extremely tricky method. Use it only if you are sure that you understand what it does and have studied its source code. You have chances to break you application otherwise. The method basically allows the vat to be temporary run in the current thread.

The method basically does the following:

  1. It starts runner and creates a control vat for it.
  2. In the context of the control vat it detaches the target vat from its original runner and attaches it the current runner.
  3. An asynchronous action is started in the taget vat from the control vat using the method AsyncAction.doInOtherVat(Vat).
  4. After method is finished. The target vat is detached from the current runner and is reattached to the original runner.
  5. Then method extis returning the value of the action or by throwing InvocationTargetException if the action failed.

So logic is extremly similar to the logic of the AsyncAction.doInCurrentThread(ThreadBasedRunner) except for vat migration logic and the fact that action body is executed in the specified vat.

Type Parameters:
T - a value type, typically it is a Void
Parameters:
targetVat - a vat to migrate from one runner to the current runner
runner - a runner to use in the current thread
action - an action to execute in the context of the targetVat
Returns:
a result of the cation
Throws:
InvocationTargetException - an failure returned from the action

runInCurrentThread

@Experimental
public static <T> T runInCurrentThread(Vat targetVat,
                                                    AsyncAction<T> action)
                            throws InvocationTargetException
The version of runInCurrentThread(Vat, ThreadBasedRunner, AsyncAction) that uses SingleThreadRunner as runner.

Type Parameters:
T - a value type, typically it is a Void
Parameters:
targetVat - a vat to migrate from one runner to the current runner
action - an action to execute in the context of the targetVat
Returns:
a result of the cation
Throws:
InvocationTargetException - an failure returned from the action


Copyright 2002-2007 Constantine Plotnikov. All Rights Reserved.