com.ibm.websphere.samples.asynchbeans.wstrader.tickstream
Class StreamApplicationState

java.lang.Object
  extended by com.ibm.websphere.samples.asynchbeans.wstrader.tickstream.StreamApplicationState
All Implemented Interfaces:
com.ibm.websphere.asynchbeans.AsynchScopeEvents, com.ibm.websphere.asynchbeans.EventSourceEvents

public class StreamApplicationState
extends java.lang.Object
implements com.ibm.websphere.asynchbeans.AsynchScopeEvents

This class holds the application state. This state tracks all application wide state and resources. This state has an associated 'root' asynch bean on a WorkManager. This object is stored on that AsynchBean using a property allowing it to be retrieved easily at runtime. We currently use a single TopicConnection for the applications. Any Thread/Works make their own JMSSessions using this TopicConnection.


Field Summary
static java.lang.String AS_SSM_PRICEGEN
          The name of the Price Generator Subsystem Monitor
 
Method Summary
 void destroy()
          Destroy the AsynchScope where our StreamAppliationState is stored.
 void destroyed(com.ibm.websphere.asynchbeans.AsynchScope scope)
           
static StreamApplicationState getApplicationState(com.ibm.websphere.asynchbeans.WorkManager wm, boolean create)
          This is the method used to get the ApplicationState object.
 com.ibm.websphere.asynchbeans.AsynchScope getAsynchScope()
          Retrieve the Asynchronous Scope associated with this application state.
 StreamClientState getClientState(java.lang.String clientID, boolean createFlag)
          Retrieve a new or existing client state.
 com.ibm.websphere.asynchbeans.SubsystemMonitor getPriceGeneratorSSM()
          This is exposed to clients can register listeners on it to be notified when the price generator goes down or recovers.
 TickerSubscriber getTickerSubscriber(java.lang.String ticker)
          We could have given each attach client its own set of dynamically started JMS listeners.
 void handlePriceGenPing()
          This is called whenever a heart beat message is received from the price generator.
 void initialize()
          Initialize this object
 void listenerCountChanged(com.ibm.websphere.asynchbeans.EventSource es, int oldCount, int newCount)
           
 void listenerExceptionThrown(com.ibm.websphere.asynchbeans.EventSource es, java.lang.Object listener, java.lang.String methodName, java.lang.Throwable exception)
           
 void removeTickerSubscriber(java.lang.String ticker)
          This is called by TickerSubscriber when it notices that there are no more listeners attached to it.
 void unexpectedException(com.ibm.websphere.asynchbeans.EventSource es, java.lang.Object runnable, java.lang.Throwable exception)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AS_SSM_PRICEGEN

public static final java.lang.String AS_SSM_PRICEGEN
The name of the Price Generator Subsystem Monitor

See Also:
Constant Field Values
Method Detail

getPriceGeneratorSSM

public com.ibm.websphere.asynchbeans.SubsystemMonitor getPriceGeneratorSSM()
This is exposed to clients can register listeners on it to be notified when the price generator goes down or recovers.


initialize

public void initialize()
                throws javax.naming.NamingException,
                       javax.jms.JMSException
Initialize this object

Throws:
javax.naming.NamingException
javax.jms.JMSException

getApplicationState

public static StreamApplicationState getApplicationState(com.ibm.websphere.asynchbeans.WorkManager wm,
                                                         boolean create)
                                                  throws javax.naming.NamingException,
                                                         javax.jms.JMSException
This is the method used to get the ApplicationState object. It will create the state and initialize it if necessary.

Throws:
javax.naming.NamingException
javax.jms.JMSException

destroy

public void destroy()
Destroy the AsynchScope where our StreamAppliationState is stored. This will in turn call the destroyed() event which will call _destroy()


destroyed

public void destroyed(com.ibm.websphere.asynchbeans.AsynchScope scope)
Specified by:
destroyed in interface com.ibm.websphere.asynchbeans.AsynchScopeEvents
See Also:
AsynchScopeEvents.destroyed(AsynchScope)

listenerCountChanged

public void listenerCountChanged(com.ibm.websphere.asynchbeans.EventSource es,
                                 int oldCount,
                                 int newCount)
Specified by:
listenerCountChanged in interface com.ibm.websphere.asynchbeans.EventSourceEvents
See Also:
EventSourceEvents.listenerCountChanged(EventSource, int, int)

listenerExceptionThrown

public void listenerExceptionThrown(com.ibm.websphere.asynchbeans.EventSource es,
                                    java.lang.Object listener,
                                    java.lang.String methodName,
                                    java.lang.Throwable exception)
Specified by:
listenerExceptionThrown in interface com.ibm.websphere.asynchbeans.EventSourceEvents
See Also:
EventSourceEvents.listenerExceptionThrown(EventSource, Object, String, Throwable)

unexpectedException

public void unexpectedException(com.ibm.websphere.asynchbeans.EventSource es,
                                java.lang.Object runnable,
                                java.lang.Throwable exception)
Specified by:
unexpectedException in interface com.ibm.websphere.asynchbeans.EventSourceEvents
See Also:
EventSourceEvents.unexpectedException(EventSource, Object, Throwable)

getClientState

public StreamClientState getClientState(java.lang.String clientID,
                                        boolean createFlag)
Retrieve a new or existing client state.

Parameters:
clientID - a String representation of a client.
createFlag - If true and the client state doesn't exist, don't create one. Return null. If false, create and return a new StreamClientState object.
Returns:
StreamClientState

getTickerSubscriber

public TickerSubscriber getTickerSubscriber(java.lang.String ticker)
                                     throws com.ibm.websphere.asynchbeans.WorkException,
                                            javax.jms.JMSException,
                                            javax.naming.NamingException
We could have given each attach client its own set of dynamically started JMS listeners. This won't scale at all however. Instead, clients share jms listeners for the same tickers. This method is used by clients to find a listener for their ticker. We return an existing ticker if one was already in use by other clients. We create a new one if this client is the first client to ask for messages for that ticker. A Map keyed on ticker is used to track the listeners so that they can be shared in this manner.

Clients then add a listener to the EventSource associated with the listener and will then get an event when a message is received.

Parameters:
ticker - We need a listener for this ticker.
Returns:
The listener for the ticker.
Throws:
com.ibm.websphere.asynchbeans.WorkException
javax.jms.JMSException
javax.naming.NamingException

removeTickerSubscriber

public void removeTickerSubscriber(java.lang.String ticker)
This is called by TickerSubscriber when it notices that there are no more listeners attached to it. For example, there are no clients with an interest in that ticker anymore.


handlePriceGenPing

public void handlePriceGenPing()
This is called whenever a heart beat message is received from the price generator. We simply delegate to the ping on the SSM tracking the health of the price generator.


getAsynchScope

public com.ibm.websphere.asynchbeans.AsynchScope getAsynchScope()
Retrieve the Asynchronous Scope associated with this application state.