com.ibm.websphere.samples.asynchbeans.wstrader.applet
Class URLSenderHandler

java.lang.Object
  extended by java.lang.Thread
      extended by com.ibm.websphere.samples.asynchbeans.wstrader.applet.URLSenderHandler
All Implemented Interfaces:
java.lang.Runnable

public class URLSenderHandler
extends java.lang.Thread

Sends information to our various Ticker Streamer servlets by queuing all requests to run on a single thread. We use a singleton, so all applets running in the same JVM are using a single HTTP connection.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
 void addNotificationListener(NotificationListener listener)
          Add a listener for Notifications that will be recieved asynchronously.
 void cancel()
          Cancel this monitor.
static URLSenderHandler create(java.net.URL codeBase)
          Initialize the singleton URLSenderHandler.
 boolean doLogout(java.lang.String cookie)
          Logout from the WebSphere Trader application by way of the logout servlet.
 boolean doUpdate(java.lang.String streamerName, java.lang.String cookie, java.lang.String symbols)
          Update the current client's ticker symbols on the WebSphere Trader application by way of the update servlet.
 boolean getCancelled()
          Find out if the thread has been requested to end.
static URLSenderHandler getSelf()
          Return a singleton instance of the URLSenderHandler.
 void removeNotificationListener(NotificationListener listener)
          Remove a listener from the Notification list.
 void run()
          Execute the URLSender loop.
static void sendLoginMessage(java.lang.String clientid, java.lang.String symbols)
          Send a Client Login message to the TickerStreamer server app.
static void sendLogoutMessage(java.lang.String cookie)
          Send a Client Logout message to the TickerStreamer server app.
static void sendPingMessage(java.lang.String cookie)
          Send a Ping message to the TickerStreamer server app.
static void sendUpdateMessage(java.lang.String streamerName, java.lang.String cookie, java.lang.String symbols)
          Send a Change Tickers message to the TickerStreamer server app.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getSelf

public static URLSenderHandler getSelf()
Return a singleton instance of the URLSenderHandler.

Returns:
URLSenderHandler object.

create

public static URLSenderHandler create(java.net.URL codeBase)
Initialize the singleton URLSenderHandler.

Parameters:
codeBase - the calling applet's codeBase.

sendPingMessage

public static void sendPingMessage(java.lang.String cookie)
Send a Ping message to the TickerStreamer server app.

Parameters:
cookie - the Cookie receieved from the login.

sendLoginMessage

public static void sendLoginMessage(java.lang.String clientid,
                                    java.lang.String symbols)
Send a Client Login message to the TickerStreamer server app.

Parameters:
clientid - the client id to login as
symbols - the Ticker Symbols to use if this client is not already logged-in.

sendLogoutMessage

public static void sendLogoutMessage(java.lang.String cookie)
Send a Client Logout message to the TickerStreamer server app.

Parameters:
cookie - the Cookie receieved from the login.

sendUpdateMessage

public static void sendUpdateMessage(java.lang.String streamerName,
                                     java.lang.String cookie,
                                     java.lang.String symbols)
Send a Change Tickers message to the TickerStreamer server app.

Parameters:
streamerName - the streamer to update (example: "DEFAULT")
cookie - the Cookie receieved from the login.
symbols - the Ticker Symbols to update to.

doLogout

public boolean doLogout(java.lang.String cookie)
                 throws java.net.MalformedURLException,
                        java.io.IOException
Logout from the WebSphere Trader application by way of the logout servlet.

Parameters:
cookie - the Cookie receieved from the login.
Throws:
java.net.MalformedURLException
java.io.IOException

doUpdate

public boolean doUpdate(java.lang.String streamerName,
                        java.lang.String cookie,
                        java.lang.String symbols)
                 throws java.net.MalformedURLException,
                        java.io.IOException
Update the current client's ticker symbols on the WebSphere Trader application by way of the update servlet.

Parameters:
streamerName - the streamer to update (example: "DEFAULT")
cookie - the Cookie receieved from the login.
symbols - the Ticker Symbols to update to.
Throws:
java.net.MalformedURLException
java.io.IOException

run

public void run()
Execute the URLSender loop. Continually process messages from our message queue such that only one message is processed at a time. We do this to avoid starting more than one connection. We will only have a single HTTP connection open at a given time.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

cancel

public void cancel()
Cancel this monitor.


getCancelled

public boolean getCancelled()
Find out if the thread has been requested to end.


addNotificationListener

public void addNotificationListener(NotificationListener listener)
Add a listener for Notifications that will be recieved asynchronously.

Parameters:
listener - the listener to notify.

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)
Remove a listener from the Notification list.

Parameters:
listener -