org.apache.qpid.client.state
Class AMQStateManager

java.lang.Object
  extended by org.apache.qpid.client.state.AMQStateManager
All Implemented Interfaces:
org.apache.qpid.protocol.AMQMethodListener

public class AMQStateManager
extends Object
implements org.apache.qpid.protocol.AMQMethodListener

The state manager is responsible for managing the state of the protocol session.

For each AMQProtocolHandler there is a separate state manager. The AMQStateManager is now attached to the AMQProtocolHandler and that is the sole point of reference so that As the AMQProtocolSession changes due to failover the AMQStateManager need not be copied around. The StateManager works by any component can wait for a state change to occur by using the following sequence.

  • StateWaiter waiter = stateManager.createWaiter(Set states);
  • // Perform action that will cause state change
  • waiter.await(); The two step process is required as there is an inherit race condition between starting a process that will cause the state to change and then attempting to wait for that change. The interest in the change must be first set up so that any asynchrous errors that occur can be delivered to the correct waiters.


    Field Summary
    protected  List<StateWaiter> _waiters
               
     
    Constructor Summary
      AMQStateManager()
               
      AMQStateManager(AMQProtocolSession protocolSession)
               
    protected AMQStateManager(AMQState state, AMQProtocolSession protocolSession)
               
     
    Method Summary
     void changeState(AMQState newState)
               
     void clearLastException()
               
     StateWaiter createWaiter(Set<AMQState> states)
              Create and add a new waiter to the notifcation list.
     void error(Exception error)
              Propogate error to waiters
     AMQState getCurrentState()
               
     Exception getLastException()
               
     long getWaitTimeout()
              This provides a single place that the maximum time for state change to occur can be accessed.
    <B extends org.apache.qpid.framing.AMQMethodBody>
    boolean
    methodReceived(org.apache.qpid.protocol.AMQMethodEvent<B> evt)
               
     void removeWaiter(StateWaiter waiter)
              Remove the waiter from the notification list.
     void setProtocolSession(AMQProtocolSession session)
              Setting of the ProtocolSession will be required when Failover has been successfuly compeleted.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    _waiters

    protected final List<StateWaiter> _waiters
    Constructor Detail

    AMQStateManager

    public AMQStateManager()

    AMQStateManager

    public AMQStateManager(AMQProtocolSession protocolSession)

    AMQStateManager

    protected AMQStateManager(AMQState state,
                              AMQProtocolSession protocolSession)
    Method Detail

    getCurrentState

    public AMQState getCurrentState()

    changeState

    public void changeState(AMQState newState)

    methodReceived

    public <B extends org.apache.qpid.framing.AMQMethodBody> boolean methodReceived(org.apache.qpid.protocol.AMQMethodEvent<B> evt)
                           throws org.apache.qpid.AMQException
    Specified by:
    methodReceived in interface org.apache.qpid.protocol.AMQMethodListener
    Throws:
    org.apache.qpid.AMQException

    setProtocolSession

    public void setProtocolSession(AMQProtocolSession session)
    Setting of the ProtocolSession will be required when Failover has been successfuly compeleted. The new AMQProtocolSession that has been re-established needs to be provided as that is now the connection to the network.

    Parameters:
    session - The new protocol session

    error

    public void error(Exception error)
    Propogate error to waiters

    Specified by:
    error in interface org.apache.qpid.protocol.AMQMethodListener
    Parameters:
    error - The error to propogate.

    getWaitTimeout

    public long getWaitTimeout()
    This provides a single place that the maximum time for state change to occur can be accessed. It is currently set via System property amqj.MaximumStateWait

    Returns:
    long Milliseconds value for a timeout

    createWaiter

    public StateWaiter createWaiter(Set<AMQState> states)
    Create and add a new waiter to the notifcation list.

    Parameters:
    states - The waiter will attempt to wait for one of these desired set states to be achived.
    Returns:
    the created StateWaiter.

    removeWaiter

    public void removeWaiter(StateWaiter waiter)
    Remove the waiter from the notification list.

    Parameters:
    waiter - The waiter to remove.

    getLastException

    public Exception getLastException()

    clearLastException

    public void clearLastException()


    Licensed to the Apache Software Foundation