Bees v0.5.0 API

bees.core
Class Coroutine

java.lang.Object
  |
  +--bees.core.Coroutine
Direct Known Subclasses:
BDomainRegisterCoroutine, ExternalCoroutine, JSICoroutine, ListBDomainCoroutine, LocalFlowCoroutine, RemoteFlowCoroutine, ResponderCoroutine, RevokeCapabilityCoroutine

public abstract class Coroutine
extends java.lang.Object

A Coroutine is a base class for handling events exchanged between domains.


Field Summary
static long DEFAULT_TIMEOUT
          Default timeout for events sent between coroutines.
static long INVALID_ID
          An invalid coroutine identifier.
static int STATE_ANY
           
static int STATE_COMPLETE
           
static int STATE_ERROR
           
static int STATE_ERROR_CAGED
           
static int STATE_ERROR_INTERNAL
           
static int STATE_ERROR_TIMEOUT
           
static int STATE_ERROR_USER
           
static int STATE_NEWBORN
           
static int STATE_USER
           
 
Constructor Summary
protected Coroutine()
          Construct a coroutine and initialize it with a unique identifier.
 
Method Summary
 void cleanup()
          Call back used to cleanup coroutines that are still in progress when a BDomain has been shutdown.
 void drop()
          Drop the Coroutine, which entails setting the unique identifier to INVALID_ID.
protected  void finalize()
           
static Coroutine getCoroutine(BeesEvent ae)
           
 long getID()
           
 int getState()
           
 java.lang.Throwable getThrowable()
           
abstract  void handle(BeesEvent ae)
          Callback used to handle BeesEvents directed to this Coroutine.
protected  void setState(int newState)
          Set the state of the Coroutine and notify any waiting threads.
protected  void setThrowable(java.lang.Throwable throwable)
           
 java.lang.String toString()
           
 boolean waitForCompletion()
          Wait for the Coroutine to reach STATE_COMPLETE.
 boolean waitForCompletion(long timeout)
          Wait for the Coroutine to reach STATE_COMPLETE.
 int waitForState(int state)
           
 int waitForState(int nextState, long timeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INVALID_ID

public static final long INVALID_ID
An invalid coroutine identifier.

STATE_ERROR_USER

public static final int STATE_ERROR_USER

STATE_ERROR_TIMEOUT

public static final int STATE_ERROR_TIMEOUT

STATE_ERROR_CAGED

public static final int STATE_ERROR_CAGED

STATE_ERROR_INTERNAL

public static final int STATE_ERROR_INTERNAL

STATE_ERROR

public static final int STATE_ERROR

STATE_ANY

public static final int STATE_ANY

STATE_NEWBORN

public static final int STATE_NEWBORN

STATE_USER

public static final int STATE_USER

STATE_COMPLETE

public static final int STATE_COMPLETE

DEFAULT_TIMEOUT

public static final long DEFAULT_TIMEOUT
Default timeout for events sent between coroutines.
Constructor Detail

Coroutine

protected Coroutine()
Construct a coroutine and initialize it with a unique identifier.
Method Detail

getCoroutine

public static Coroutine getCoroutine(BeesEvent ae)
Parameters:
ae - The BeesEvent that should be matched to a coroutine.
Returns:
The Coroutine matching the given event or a newly created Coroutine object if one doesn't already exist.

getID

public final long getID()
Returns:
The Coroutines unique identifier or INVALID_ID if the Coroutine has reached an error or completed state.

setState

protected void setState(int newState)
Set the state of the Coroutine and notify any waiting threads. If the new state value is less than the current state it is ignored. If the new state value is an error or STATE_COMPLETE the Coroutine is disabled.
Parameters:
newState - The new state value.

getState

public final int getState()
Returns:
The current state of the Coroutine.

setThrowable

protected final void setThrowable(java.lang.Throwable throwable)
Parameters:
throwable - The exception that disabled this Coroutine.

getThrowable

public final java.lang.Throwable getThrowable()
Returns:
The exception that disabled this Coroutine.

waitForState

public int waitForState(int nextState,
                        long timeout)
Parameters:
nextState - The state to wait for.
timeout - The amount of time to wait before setting the state to STATE_ERROR_TIMEOUT and returning.
Returns:
The state reached during the wait.

waitForState

public int waitForState(int state)
Parameters:
state - The state to wait for.
Returns:
The state reached during the wait.

waitForCompletion

public boolean waitForCompletion(long timeout)
Wait for the Coroutine to reach STATE_COMPLETE.
Parameters:
timeout - The amount of time to wait before setting the state to STATE_ERROR_TIMEOUT and returning.
Returns:
True if the Coroutine reached STATE_COMPLETE.

waitForCompletion

public boolean waitForCompletion()
Wait for the Coroutine to reach STATE_COMPLETE.
Returns:
True if the Coroutine reached STATE_COMPLETE.

handle

public abstract void handle(BeesEvent ae)
Callback used to handle BeesEvents directed to this Coroutine.
Parameters:
ae - The BeesEvent to handle.

cleanup

public void cleanup()
Call back used to cleanup coroutines that are still in progress when a BDomain has been shutdown.

drop

public void drop()
Drop the Coroutine, which entails setting the unique identifier to INVALID_ID.

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object
See Also:
Object.finalize()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

Bees v0.5.0 API

This documentation is Copyright (C) 2002 The University of Utah. All Rights Reserved. See the individual source files for distribution terms.
Documentation, software, and mailing lists for Bees v0.5.0 can be found at the Janos Project: http://www.cs.utah.edu/flux/janos/