AMETAS.util.context
Class AMETASContextManager

java.lang.Object
  extended byAMETAS.util.context.AMETASContextManager
All Implemented Interfaces:
java.io.Serializable

public class AMETASContextManager
extends java.lang.Object
implements java.io.Serializable

Context manager. This class cares for looking up the required context for any incoming message. Note that it does not automatically retrieve messages.

Since:
2.6.0
See Also:
Serialized Form

Constructor Summary
AMETASContextManager(java.lang.Class clsContext, AMETASContextControl cct, AMETASPlaceUser pu)
          Constructor.
AMETASContextManager(java.lang.Class clsContext, AMETASPlaceUser pu)
          Constructor.
 
Method Summary
 boolean allDone()
          Determines whether there is any active context.
 boolean checkNonstableContext(AMETASContext ctx)
          Processes one nonstable context.
 void checkNonstableContexts()
          Processes nonstable contexts.
 int[] getAllContextIDs()
          Returns the set of all context IDs.
 AMETASContext[] getAllContexts()
          Returns the set of all contexts.
 AMETASContext getContext(AMETASMessage msg, boolean bCreate)
          Returns the context for this message.
 AMETASContext getContext(AMETASMessage msg, boolean bCreate, java.lang.Object[] aParam)
          Invokes the context which this message belongs to.
 AMETASContext getContext(int nID)
          Returns a context.
 AMETASContext[] getNonstableContexts()
          Returns the set of currently unstable and semistable (=nonstable) contexts.
 boolean newContextRequested()
          Determines whether a new context shall be created.
 void prepareMigration(AMETASContext ctx)
          Prepares for migration.
 void processInContext(AMETASMessage msg)
          Invokes the context which this message belongs to.
 void processInContext(AMETASMessage msg, java.lang.Object[] aParam)
          Invokes the contexts which the new messages belong to.
 void setServiceObject(AMETASServiceObject so)
          Sets the reference to the service object.
 void startNewContext()
          Creates a new context.
 void startNewContext(java.lang.Object[] aParam)
          Creates a new context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AMETASContextManager

public AMETASContextManager(java.lang.Class clsContext,
                            AMETASPlaceUser pu)
                     throws java.lang.NullPointerException
Constructor. It is assumed that message ID need not be memorized. Furthermore, the start state is stable.

Parameters:
clsContext - Class to be used for instantiating new contexts.
pu - Reference to the Place User.
Throws:
java.lang.NullPointerException - if the given class is null.

AMETASContextManager

public AMETASContextManager(java.lang.Class clsContext,
                            AMETASContextControl cct,
                            AMETASPlaceUser pu)
                     throws java.lang.NullPointerException
Constructor.

Parameters:
clsContext - Class to be used for instantiating new contexts.
cct - Control object which decides whether a new context is required.
pu - Reference to the Place User.
Throws:
java.lang.NullPointerException - if the context class is null.
Method Detail

setServiceObject

public void setServiceObject(AMETASServiceObject so)
Sets the reference to the service object.

Parameters:
so - Service object.
Since:
2.6.3

startNewContext

public void startNewContext()
                     throws java.lang.InstantiationException
Creates a new context. The new context will be started as well. No initialization data will be passed. The context will be able to retrieve data directly from the Place User.

Throws:
java.lang.InstantiationException - if the context instance could not be instantiated.

startNewContext

public void startNewContext(java.lang.Object[] aParam)
                     throws java.lang.InstantiationException
Creates a new context. The new context will be started as well.

Parameters:
aParam - Initialization parameters. Can be references to other objects which the context should consult to retrieve the data.
Throws:
java.lang.InstantiationException - if the context instance could not be instantiated.

getContext

public AMETASContext getContext(AMETASMessage msg,
                                boolean bCreate)
                         throws UnknownContextException,
                                FinalizedContextException,
                                java.lang.InstantiationException
Returns the context for this message. There are no initialization parameters.

Parameters:
msg - Message the context of which shall be determined.
bCreate - if true, a new context will be created if there is no such context for this message.
Throws:
java.lang.InstantiationException - if the context could not be instantiated.
UnknownContextException - if the context of a message is unknown.
FinalizedContextException - if the context is already finalized.

getContext

public AMETASContext getContext(AMETASMessage msg,
                                boolean bCreate,
                                java.lang.Object[] aParam)
                         throws UnknownContextException,
                                FinalizedContextException,
                                java.lang.InstantiationException
Invokes the context which this message belongs to.

Parameters:
msg - Message the context of which shall be determined.
bCreate - if true, a new context will be created if there is no such context for this message.
aParam - Initialization parameters.
Throws:
java.lang.InstantiationException - if the context could not be instantiated.
UnknownContextException - if the context of a message is unknown.
FinalizedContextException - if the context is already finalized.

processInContext

public void processInContext(AMETASMessage msg)
                      throws UnknownContextException,
                             FinalizedContextException,
                             java.lang.InstantiationException,
                             MessagePushbackException,
                             MessageRejectedException
Invokes the context which this message belongs to. There are no initialization parameters.

Parameters:
msg - Message to be processed.
Throws:
java.lang.InstantiationException - if the context could not be instantiated.
UnknownContextException - if the context of a message is unknown.
FinalizedContextException - if the context is already finalized.
MessagePushbackException - if the message was pushed back by the context.
MessageRejectedException - if the message was rejected by the context.

processInContext

public void processInContext(AMETASMessage msg,
                             java.lang.Object[] aParam)
                      throws UnknownContextException,
                             FinalizedContextException,
                             java.lang.InstantiationException,
                             MessagePushbackException,
                             MessageRejectedException
Invokes the contexts which the new messages belong to.

Throws:
java.lang.InstantiationException - if the context could not be instantiated.
UnknownContextException - if the context of a message is unknown.
FinalizedContextException - if the context is already finalized.
MessagePushbackException - if the message was pushed back by the context.
MessageRejectedException - if the message was rejected by the context.

prepareMigration

public void prepareMigration(AMETASContext ctx)
Prepares for migration. This is necessary to be called before the migration because otherwise the context processing will be interrupted. Here, the context is checked for being unstable or semistable or to be finalized.


getAllContexts

public AMETASContext[] getAllContexts()
Returns the set of all contexts.

Returns:
Array of contexts.

getAllContextIDs

public int[] getAllContextIDs()
Returns the set of all context IDs.

Returns:
Array of context IDs.

getContext

public AMETASContext getContext(int nID)
                         throws UnknownContextException,
                                FinalizedContextException
Returns a context.

Parameters:
nID - Context ID
Returns:
Corresponding context.
Throws:
UnknownContextException - if the context is unknown.
FinalizedContextException - if the context was already finalized.

getNonstableContexts

public AMETASContext[] getNonstableContexts()
Returns the set of currently unstable and semistable (=nonstable) contexts.

Returns:
Array of nonstable contexts.

checkNonstableContext

public boolean checkNonstableContext(AMETASContext ctx)
Processes one nonstable context. When this context becomes stable, it will be automatically removed from the list of nonstable contexts.

Parameters:
ctx - Context instance.

checkNonstableContexts

public void checkNonstableContexts()
Processes nonstable contexts. This method must be called in order to allow the unstable contexts (which do not wait for messages) to have any progress.


allDone

public boolean allDone()
Determines whether there is any active context.

Returns:
true if there is any active context, else false.

newContextRequested

public boolean newContextRequested()
Determines whether a new context shall be created. Calls the ContextControl instance which actually decides.

Returns:
true if there is a context control object and a new context shall be created, else false.