net.sf.asyncobjects.vats
Class Vat

java.lang.Object
  extended by net.sf.asyncobjects.vats.Vat
Direct Known Subclasses:
NIOSelectorVat

public class Vat
extends Object

Vat is managed collection of objects. Mapping between vats and threads is generally speaking dynamic and is provide by VatRunner.


Nested Class Summary
protected static class Vat.VatState
          Vat state
 
Field Summary
protected  Object attachmentLock
          a lock for detach/attache operations
protected  Semaphore detach
          a semaphore for detach process, guared by state lock
protected  Vat.VatState state
          state of vat, guarded by state lock
protected  Object stateLock
          state lock
protected  Object ticket
          a running ticket, guarded by state lock
 
Constructor Summary
Vat()
          a constructor
Vat(String name)
          a constructor
Vat(VatRunner runner)
          a constructor
Vat(VatRunner runner, String name)
          a constructor
 
Method Summary
 void attachToRunner(VatRunner newRunner)
          Attach to runner
static Vat current()
          Current vat for current thread.
 void detachFromRunner(boolean waitForIt)
          Detach from runner.
 int dispatchEventBatch(int n)
          Dispatch events without setting context
 int dispatchVatEvents(Object ticket, int n)
          Dispatch at most n events for the vat.
 void enqueue(Runnable r)
          enqueue runnuable
static String generateVatName(Class<?> c)
          Generate vat name
 String getName()
          get vat name
 VatRunner getRunner()
           
 boolean hasEvents()
           
 boolean isDetached()
           
static void offerSensor(Class cls)
          Offer sensor to vat
protected  void resetCurrentVat()
          Disassociate thread from vat
 VatRunner runner()
           
protected  boolean setCurrentVat(Object queueTicket)
          Associate this thread with this vat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

state

protected Vat.VatState state
state of vat, guarded by state lock


stateLock

protected Object stateLock
state lock


ticket

protected Object ticket
a running ticket, guarded by state lock


attachmentLock

protected Object attachmentLock
a lock for detach/attache operations


detach

protected Semaphore detach
a semaphore for detach process, guared by state lock

Constructor Detail

Vat

public Vat(VatRunner runner,
           String name)
a constructor

Parameters:
runner - a vat runner
name - name of vat

Vat

public Vat(VatRunner runner)
a constructor

Parameters:
runner - a vat runner

Vat

public Vat(String name)
a constructor

Parameters:
name - name of vat

Vat

public Vat()
a constructor

Method Detail

generateVatName

public static String generateVatName(Class<?> c)
Generate vat name

Parameters:
c - a class
Returns:
generated name

isDetached

public boolean isDetached()
Returns:
true if vat is not attached to any runner

detachFromRunner

public void detachFromRunner(boolean waitForIt)
                      throws InterruptedException
Detach from runner.

Parameters:
waitForIt - if true, the method does not returns until vat
Throws:
InterruptedException - operation was interrupted, detach process is possibly incomplete

runner

public VatRunner runner()
Returns:
runner for the current vat

attachToRunner

public void attachToRunner(VatRunner newRunner)
Attach to runner

Parameters:
newRunner - a new runner for the vat

getName

public String getName()
get vat name

Returns:
vat name

current

public static Vat current()
Current vat for current thread.

Returns:
current vat for current thread

setCurrentVat

protected boolean setCurrentVat(Object queueTicket)
Associate this thread with this vat

Parameters:
queueTicket - a ticket with which vat was enqueued
Returns:
true if vat wants to be run in the supplied runner, false is returned if runner has changed since than

resetCurrentVat

protected void resetCurrentVat()
Disassociate thread from vat


enqueue

public void enqueue(Runnable r)
enqueue runnuable

Parameters:
r - runnable to enqueue

hasEvents

public boolean hasEvents()
Returns:
true if vat has events pending

dispatchVatEvents

public int dispatchVatEvents(Object ticket,
                             int n)
Dispatch at most n events for the vat. The methods sets current vat context.

Parameters:
ticket - a ticket associated with events
n - an maximum amount of events to dispatch
Returns:
actual number of dispatched events. The amount is negative if runner should not continue dispatching.

dispatchEventBatch

public int dispatchEventBatch(int n)
Dispatch events without setting context

Parameters:
n - events to dispatcy
Returns:
amount of dispatched events. The amount is negative if runner should not continue dispatching.

offerSensor

public static void offerSensor(Class cls)
Offer sensor to vat

Parameters:
cls - a sensor class

getRunner

public VatRunner getRunner()
Returns:
a current runner for the vat


Copyright 2002-2007 Constantine Plotnikov. All Rights Reserved.