AMETAS.util.context
Class AMETASStandardContext

java.lang.Object
  extended byAMETAS.util.context.AMETASStandardContext
All Implemented Interfaces:
AMETASContext, java.io.Serializable

public abstract class AMETASStandardContext
extends java.lang.Object
implements AMETASContext

Provides a standard implementation for contexts. This class should be used whenever you need not pay attention for application class hierarchies.

Since:
2.6.0
See Also:
Serialized Form

Field Summary
protected  java.lang.Object[] m_aParam
          Initialization parameters.
 
Fields inherited from interface AMETAS.util.context.AMETASContext
CURRENT_CONTEXT, FINAL, INITIAL, NEW_CONTEXT, NO_CONTEXT, SEMISTABLE, STABLE, UNSTABLE
 
Constructor Summary
AMETASStandardContext()
          Constructor.
 
Method Summary
 int getContextID()
          Returns the ID of this context.
 int getContextIDOf(AMETASPlaceUserID puidPartner)
          Returns the ID of the context for the recipient.
 short getMode()
          Delivers the mode of the state of this context (stable, unstable, semistable).
protected  java.lang.Object[] getParameters()
          Gets the parameters of the context.
 AMETASPlaceUser getPlaceUser()
          Returns the reference to the Place User.
 AMETASPlaceUserID getPrimaryPeer()
          Returns the primary peer.
 AMETASMessage getRecentMessage()
          Returns the recent message processed by this context.
 AMETASServiceObject getServiceObject()
          Returns the reference to the service object.
 int getStateID()
          Returns the current state by its ID.
 boolean inFinalState()
          Determines whether this context is in a final state.
 void nextState(int nState)
          Puts the context in the given state.
 void nextState(int nState, short nMode)
          Puts the context in the given state.
abstract  void processMessage(AMETASMessage msg)
          Processes this message.
 void saveSenderContext(AMETASMessage msg)
          Stored the context of the sender.
 void setContextID(int nID)
          Definess the context ID.
 void setDefaultContexts(AMETASMessage msg)
          Sets the default contexts.
 void setParameters(java.lang.Object[] aParam)
          Set the parameters of the context.
 void setPlaceUser(AMETASPlaceUser pu)
          Defines the reference to the Place User.
 void setPrimaryPeer(AMETASPlaceUserID puid)
          Sets the primary peer.
 void setServiceObject(AMETASServiceObject so)
          Defines the reference to the service object.
 void submitMessage(AMETASMessage msg)
          Submits a message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_aParam

protected java.lang.Object[] m_aParam
Initialization parameters.

Constructor Detail

AMETASStandardContext

public AMETASStandardContext()
Constructor. Sets the current state to the initial state, assuming this state to be stable. Attention: If you overwrite this constructor, bear in mind that there are still initialization actions after the instantiation. Specifically, the Place User and service object reference and the parameters are set afterwards, so that they are still null while the constructor is executed.

Method Detail

setContextID

public void setContextID(int nID)
Definess the context ID. This method may only be called once for this instance.

Specified by:
setContextID in interface AMETASContext
Parameters:
nID - Context ID.

getContextID

public int getContextID()
Returns the ID of this context.

Specified by:
getContextID in interface AMETASContext
Returns:
ID of this context.

setPlaceUser

public final void setPlaceUser(AMETASPlaceUser pu)
Defines the reference to the Place User. This is required for this context object to access the Place User. Due to limitations of the Java language, context classes cannot be implemented as an inner class of the Place User.

Specified by:
setPlaceUser in interface AMETASContext
Parameters:
pu - Reference to the Place User.

setServiceObject

public final void setServiceObject(AMETASServiceObject so)
Defines the reference to the service object. This is required for this context object to access the service object. Due to limitations of the Java language, context classes cannot be implemented as an inner class of the service object.

Specified by:
setServiceObject in interface AMETASContext
Since:
2.6.3

getPlaceUser

public final AMETASPlaceUser getPlaceUser()
Returns the reference to the Place User. This is required for this context object to access the Place User. Due to limitations of the Java language, context classes cannot be implemented as an inner class of the Place User.

Specified by:
getPlaceUser in interface AMETASContext
Returns:
Reference to the Place User.

getServiceObject

public final AMETASServiceObject getServiceObject()
Returns the reference to the service object. This is required for this context object to access the service object. Due to limitations of the Java language, context classes cannot be implemented as an inner class of the service object.

Specified by:
getServiceObject in interface AMETASContext
Returns:
Reference to the service object or null if the context belongs to an agent or user adapter.
Since:
2.6.3

getRecentMessage

public final AMETASMessage getRecentMessage()
Returns the recent message processed by this context.

Returns:
Recent message.

saveSenderContext

public void saveSenderContext(AMETASMessage msg)
Stored the context of the sender. This is required for later replies if you want to retrieve the context ID of the reply recipient using getContextIDOf.

Parameters:
msg - New message to be processed. If null, the method returns without any action.

inFinalState

public final boolean inFinalState()
Determines whether this context is in a final state.

Returns:
true if the context is in a final state, else false.

getMode

public short getMode()
Delivers the mode of the state of this context (stable, unstable, semistable).

Specified by:
getMode in interface AMETASContext
Returns:
STABLE, UNSTABLE, SEMISTABLE.

getStateID

public final int getStateID()
Returns the current state by its ID.

Specified by:
getStateID in interface AMETASContext
Returns:
ID of the state.

nextState

public final void nextState(int nState)
Puts the context in the given state. The mode is assumed to be stable.

Parameters:
nState - State ID.

nextState

public final void nextState(int nState,
                            short nMode)
Puts the context in the given state.

Specified by:
nextState in interface AMETASContext
Parameters:
nState - State ID. If final, the mode is assumed to be STABLE.
nMode - STABLE, UNSTABLE, SEMISTABLE. Other values are ignored, and STABLE is assumed.

setParameters

public void setParameters(java.lang.Object[] aParam)
Set the parameters of the context. This might be necessary to retrieve data from objects different from the Place User.

Specified by:
setParameters in interface AMETASContext
Parameters:
aParam - Parameters.

getParameters

protected java.lang.Object[] getParameters()
Gets the parameters of the context. This might be necessary to retrieve data from objects different from the Place User.


getContextIDOf

public int getContextIDOf(AMETASPlaceUserID puidPartner)
Returns the ID of the context for the recipient. This implementation assumes that a Place User may only be in one context with another Place User at the same time. Other implementations may have different behavior.

Parameters:
puidPartner - PlaceUserID of the communication peer.
Returns:
NO_CONTEXT if the peer is unknown, else the context ID.

setPrimaryPeer

public void setPrimaryPeer(AMETASPlaceUserID puid)
Sets the primary peer. Note that this primary peer must be explicitely defined and need not be the first communication partner in the protocol. In the Hybrid Type system, the primary peer is the non-attributed sender or receiver. This implementation only allows this value to be set once.

Parameters:
puid - PlaceUserID of the primary peer.

getPrimaryPeer

public AMETASPlaceUserID getPrimaryPeer()
Returns the primary peer. Note that this primary peer must be explicitely defined and need not be the first communication partner in the protocol. In the Hybrid Type system, the primary peer is the non-attributed sender or receiver.

Returns:
PlaceUserID of the primary peer, or null if not set.

setDefaultContexts

public void setDefaultContexts(AMETASMessage msg)
Sets the default contexts. The receiver context is retrieved from an internal table which is filled by saveSenderContext; the sender context ID is retrieved from this context. If the recipient is unknown, NO_CONTEXT is automatically set; this also happens if the recipient is not specified by a unicast mask.

Parameters:
msg - Message to be specified for sender and receiver contexts.

submitMessage

public void submitMessage(AMETASMessage msg)
Submits a message. Default contexts will be set in the message.

Parameters:
msg - Message to be submitted.

processMessage

public abstract void processMessage(AMETASMessage msg)
                             throws MessagePushbackException,
                                    MessageRejectedException,
                                    ContextTerminatedException
Processes this message. This method must be implemented by subclasses.

Specified by:
processMessage in interface AMETASContext
Parameters:
msg - Current message for this context.
Throws:
MessagePushbackException - if the message shall not be processed but neither rejected.
MessageRejectedException - if the message cannot be processed in this state.
ContextTerminatedException - if this context must be aborted.