|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.websphere.samples.asynchbeans.wstrader.tickstream.TickerSubscriber
public class TickerSubscriber
This is a Work that is used to dynamically subscribe to a Topic and notify listeners that are colocated in this JVM whenever a message is received on that topic.
It is created whenever a client that is attached needs to subscribe to a particular stock ticker. A Map of these TickerSubscribers is kept in StreamApplicationState. If a Tickersubscriber for the required ticker doesn't exist then we create a new one for that ticker and add it to the Map. The client then adds a listener to the EventSource associated with the TickerSubscriber object. The tickerUpdated method on the client listener will be called whenever a message arrives on that topic.
The TickerSubscriber should only exist as long as their are interested clients attached to its EventSource. Once the number of listeners falls to 1 then the TickerSubscriber will terminate and release the JMS and thread resources.
Constructor Summary | |
---|---|
TickerSubscriber(StreamApplicationState appState,
com.ibm.websphere.asynchbeans.WorkManager wm,
javax.jms.TopicConnectionFactory tcf,
javax.jms.Topic topic,
java.lang.String selector)
This creates a new TickerSubscriber. |
Method Summary | |
---|---|
com.ibm.websphere.asynchbeans.EventSource |
getEventSource()
This returns the EventSource associated with this listener. |
java.lang.String |
getTicker()
|
void |
listenerCountChanged(com.ibm.websphere.asynchbeans.EventSource es,
int oldCount,
int newCount)
If the listener counter falls to one listener, then that means we're the only listener and therefore we will stop the Work by calling release and this will stop us listening needlessly when no one is listening to the received messages. |
void |
listenerExceptionThrown(com.ibm.websphere.asynchbeans.EventSource es,
java.lang.Object listener,
java.lang.String methodName,
java.lang.Throwable exception)
|
void |
release()
This when called will cause the run method to exit. |
void |
run()
This is the actual 'thread' which listens for prices. |
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 |
Constructor Detail |
---|
public TickerSubscriber(StreamApplicationState appState, com.ibm.websphere.asynchbeans.WorkManager wm, javax.jms.TopicConnectionFactory tcf, javax.jms.Topic topic, java.lang.String selector) throws javax.jms.JMSException, com.ibm.websphere.asynchbeans.WorkException, javax.naming.NamingException
wm
- the main WorkManager for the application.selector
- the ticker that this TickerSubscriber is subscribed to.
javax.jms.JMSException
com.ibm.websphere.asynchbeans.WorkException
javax.naming.NamingException
Method Detail |
---|
public java.lang.String getTicker()
public void release()
release
in interface com.ibm.websphere.asynchbeans.Work
public void run()
run
in interface java.lang.Runnable
public com.ibm.websphere.asynchbeans.EventSource getEventSource()
public void listenerCountChanged(com.ibm.websphere.asynchbeans.EventSource es, int oldCount, int newCount)
listenerCountChanged
in interface com.ibm.websphere.asynchbeans.EventSourceEvents
EventSourceEvents.listenerCountChanged(EventSource, int, int)
public void listenerExceptionThrown(com.ibm.websphere.asynchbeans.EventSource es, java.lang.Object listener, java.lang.String methodName, java.lang.Throwable exception)
listenerExceptionThrown
in interface com.ibm.websphere.asynchbeans.EventSourceEvents
EventSourceEvents.listenerExceptionThrown(EventSource, Object, String, Throwable)
public void unexpectedException(com.ibm.websphere.asynchbeans.EventSource es, java.lang.Object runnable, java.lang.Throwable exception)
unexpectedException
in interface com.ibm.websphere.asynchbeans.EventSourceEvents
EventSourceEvents.unexpectedException(EventSource, Object, Throwable)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |