QJCC homepage

biz.chitec.quarterback.gjsa
Class DefaultFreeFloatingHandler

java.lang.Object
  extended byjava.lang.Thread
      extended bybiz.chitec.quarterback.gjsa.DefaultFreeFloatingHandler
All Implemented Interfaces:
java.lang.Runnable

public class DefaultFreeFloatingHandler
extends java.lang.Thread

Handler for free floating server messages. Handles "out of order" (free-floating or "pushed") messages from the server. Manages several channels on which receivers can connect.

This handler can be attached to a SessionConnector from the outside. This attachment can be repeated as often as required without any loss of the internal state.

This handler operates as a stand-alone Thread of itself (as the asynchronous nature of the free floating events suggests). The thread must be started from outside also alone.

Version:
$Id: 2258937837d14ea7f5af062a61efa0d1efbc735d $
Author:
chitec/Dirk Hillbrecht 2001. Distributed under the terms of the GNU LGPL.

Field Summary
protected  java.util.Map receivers
          Storage for all registered receivers
protected  ThreadInterface ti
          Communication interface with the SessionConnector
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DefaultFreeFloatingHandler()
          Default constructor.
 
Method Summary
 void addFreeFloatingReceiver(int[] messages, FreeFloatingReceiver ffr)
          Add one receiver simultaneously to several message types.
 void addFreeFloatingReceiver(int message, FreeFloatingReceiver ffr)
          Add one receiver to a specific message type.
 void attachToServerConnector(ServerConnector sc)
          Attaches this handler to a SessionConnector.
 ThreadInterface getProducerInterface()
          Returns the producer interface of this handler.
protected  void handleFreeFloatingMessage(int message, java.lang.Object data)
          Handle a free floating message.
 void removeFreeFloatingReceiver(FreeFloatingReceiver ffr)
          Remove a receiver from all messages it has been registered to.
 void removeFreeFloatingReceiver(int[] messages, FreeFloatingReceiver ffr)
          Remove a receiver from several message types at once.
 void removeFreeFloatingReceiver(int message, FreeFloatingReceiver ffr)
          Remove a receiver from one specific message type.
 void run()
          The main loop.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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
 

Field Detail

ti

protected ThreadInterface ti
Communication interface with the SessionConnector


receivers

protected java.util.Map receivers
Storage for all registered receivers

Constructor Detail

DefaultFreeFloatingHandler

public DefaultFreeFloatingHandler()
Default constructor. Simply initializes internal fields. Does not do any actual work.

Method Detail

getProducerInterface

public ThreadInterface getProducerInterface()
Returns the producer interface of this handler. Normally, the returned interface will be connected to a SessionConnector.


attachToServerConnector

public void attachToServerConnector(ServerConnector sc)
Attaches this handler to a SessionConnector. Simply connects the internal ThreadInterface to the SessionConnector.


addFreeFloatingReceiver

public void addFreeFloatingReceiver(int message,
                                    FreeFloatingReceiver ffr)
Add one receiver to a specific message type. The receiver is only added if it is not yet registered for this type of message.

Note that this method locks access to the internal receivers storage. Take care on deadlock situations!


addFreeFloatingReceiver

public void addFreeFloatingReceiver(int[] messages,
                                    FreeFloatingReceiver ffr)
Add one receiver simultaneously to several message types. This method locks itself to the receiver storage for the whole operation time. As sending data to the receivers is locked also, one can guarantee with this method, that the receiver will not receive any information unless it is registered with all messages.


removeFreeFloatingReceiver

public void removeFreeFloatingReceiver(int message,
                                       FreeFloatingReceiver ffr)
Remove a receiver from one specific message type. Note that this method locks access to the internal receivers storage. Take care on deadlock situations!


removeFreeFloatingReceiver

public void removeFreeFloatingReceiver(int[] messages,
                                       FreeFloatingReceiver ffr)
Remove a receiver from several message types at once. As the similar adding method, this one locks access to the receiver storage for the whole operating time.


removeFreeFloatingReceiver

public void removeFreeFloatingReceiver(FreeFloatingReceiver ffr)
Remove a receiver from all messages it has been registered to. The receiver is removed from everywhere. This method is designed especially for receivers which will not live any longer and can therefore remove themselves from the internal storage.


handleFreeFloatingMessage

protected void handleFreeFloatingMessage(int message,
                                         java.lang.Object data)
Handle a free floating message. All receivers which have registered for this specific message type get the data they requested.

Note that this method locks access to the internal receivers storage. Take care on deadlock situations!


run

public void run()
The main loop. Waits for anything consumable on the thread interface and calls the free floating message handler with it.


QJCC homepage