AMETAS.util.context
Class AMETASSequentialContextProcessor

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

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

Executes contexts sequentially.

Since:
2.6.0
See Also:
Serialized Form

Field Summary
protected  AMETASContextManager m_ContextManager
          Reference to the context manager.
protected  long m_nIdleTime
          Idle time for the polling interval.
protected  long m_nLastMsgTime
          Time when the last message was accepted.
protected  long m_nTimeoutInterval
          Timeout value.
protected  AMETASPlaceUser m_pu
          Reference to the Place User.
protected  AMETASMessageRetriever m_Retriever
          Reference to the message retriever.
 
Constructor Summary
AMETASSequentialContextProcessor(AMETASPlaceUser pu, AMETASContextManager cm, AMETASMessageRetriever ret, long nDefaultIdle, long nTimeout)
          Constructor.
 
Method Summary
 long getIdleTime()
          Returns the pause value.
 long getTimeout()
          Returns the value for the timeout.
protected  void messagePushback(MessagePushbackException rex)
          Called when a message shall be pushed back during execution of startProcessing.
protected  void messageRejected(MessageRejectedException rex)
          Called when a message is rejected during execution of startProcessing.
 void resetTimeout()
          Touches the timeout checker.
 void setIdleTime(long nIdle)
          Defines the value for the pause.
 void setTimeout(long nTimeout)
          Sets the value for the timeout.
 void startProcessing()
          Executes contexts in a default way.
 void startProcessing(boolean bCheckNewContext, java.lang.Object[] aParam)
          Executes contexts in a default way.
 void startProcessing(java.lang.Object[] aParam)
          Executes contexts in a default way.
 boolean timeoutOccured()
          Determines whether a timeout has occured.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_nIdleTime

protected long m_nIdleTime
Idle time for the polling interval.


m_nTimeoutInterval

protected long m_nTimeoutInterval
Timeout value.


m_nLastMsgTime

protected long m_nLastMsgTime
Time when the last message was accepted.


m_ContextManager

protected AMETASContextManager m_ContextManager
Reference to the context manager.


m_Retriever

protected AMETASMessageRetriever m_Retriever
Reference to the message retriever.


m_pu

protected AMETASPlaceUser m_pu
Reference to the Place User.

Constructor Detail

AMETASSequentialContextProcessor

public AMETASSequentialContextProcessor(AMETASPlaceUser pu,
                                        AMETASContextManager cm,
                                        AMETASMessageRetriever ret,
                                        long nDefaultIdle,
                                        long nTimeout)
Constructor.

Parameters:
pu - Reference to the Place User.
cm - Context manager.
ret - Object which retrieves the messages.
nDefaultIdle - Default time in milliseconds for idling the driver.
nTimeout - Timeout value.
Method Detail

getIdleTime

public long getIdleTime()
Returns the pause value. This value may be used for idling the driver.

Returns:
Pause value in milliseconds.

setIdleTime

public void setIdleTime(long nIdle)
Defines the value for the pause. This value may be used for idling the driver. The default implementation startContextProcessing uses this value for this purpose.

Parameters:
nIdle - Pause value in milliseconds.

getTimeout

public long getTimeout()
Returns the value for the timeout. This value may be used to signal a timeout when no more messages arrived in the meantime. The default implementation startContextProcessing uses this value for this purpose.

Returns:
Timeout value in milliseconds.

setTimeout

public void setTimeout(long nTimeout)
Sets the value for the timeout. This value may be used to signal a timeout when no more messages arrived in the meantime. The default implementation startContextProcessing uses this value for this purpose.

Parameters:
nTimeout - Timeout value in milliseconds.

resetTimeout

public void resetTimeout()
Touches the timeout checker.


timeoutOccured

public boolean timeoutOccured()
Determines whether a timeout has occured. The timeout is measured on a global base, not with respect to separate contexts.

Returns:
true if there is a timeout, else false.

startProcessing

public void startProcessing()
                     throws ContextException,
                            TimeoutException
Executes contexts in a default way. There will be no check whether new unstable contexts shall be created.

Throws:
ContextException - if there has been a problem with a context.
TimeoutException - if there was a timeout; this may happen when a reply did not arrive in time or when the first request never came.

startProcessing

public void startProcessing(java.lang.Object[] aParam)
                     throws ContextException,
                            TimeoutException
Executes contexts in a default way. There will be no check whether new unstable contexts shall be created.

Parameters:
aParam - Initialization parameters. May for example contain a reference to the service object.
Throws:
ContextException - if there has been a problem with a context.
TimeoutException - if there was a timeout; this may happen when a reply did not arrive in time or when the first request never came.

startProcessing

public void startProcessing(boolean bCheckNewContext,
                            java.lang.Object[] aParam)
                     throws ContextException,
                            TimeoutException
Executes contexts in a default way. Here, only one thread will be utilized, mainly the Place User driver. This happens as follows: The method loops infinitely. At first new messages are attempted to be retrieved and given to the respective contexts. After that, unstable contexts are called. This is repeated until all messages are processed. Then new messages are retrieved if available. If not, a timeout occurs. In order to avoid active waiting, a value for the pause may be given; this will be used to put the driver in the idle state.

Parameters:
bCheckNewContext - if true, the processor will repeatedly check whether a new (unstable) context shall be created. This also depends on whether the context manager has got a reference to a context controller.
aParam - Initialization parameters. May for example contain a reference to the service object.
Throws:
ContextException - if there has been a problem with a context.
TimeoutException - if there was a timeout; this may happen when a reply did not arrive in time or when the first request never came.

messageRejected

protected void messageRejected(MessageRejectedException rex)
Called when a message is rejected during execution of startProcessing. This implementation merely output a notice to the log and returns. If a specific behavior is desired, this method should be overwritten.

Parameters:
rex - Exception which was thrown by the context, containing the reason of rejection.

messagePushback

protected void messagePushback(MessagePushbackException rex)
Called when a message shall be pushed back during execution of startProcessing. This implementation merely output a notice to the log, makes the retriever push back the message, and returns. If a specific behavior is desired, this method should be overwritten.

Parameters:
rex - Exception which was thrown by the context, containing the reason of pushback.