com.sentilla.platform.cmote
Class Dispatcher

java.lang.Object
  extended by com.sentilla.system.DriverAdapter
      extended by com.sentilla.platform.cmote.Dispatcher
All Implemented Interfaces:
Driver

public class Dispatcher
extends DriverAdapter

Dispatches messages through Protocols to user application receivers.

The Dispatcher is resposible for managing the sending and receiving of messages. It contains two threads: one for sending messages and one for receiving them. Messages are sent in the order they are received. The Dispatcher calls receive on the communications interfaces and dispatches the received objects to their respective protocols.

See Also:
Protocol, DriverAdapter, Drivers, Sender, Receiver

Field Summary
 
Fields inherited from class com.sentilla.system.DriverAdapter
m_nextDriver
 
Constructor Summary
Dispatcher()
          Instantiates the Dispatcher and starts the send and receive threads.
 
Method Summary
 void dispatch(Receiver rcvr)
          Dispatches messages to protocols and waiting receivers.
static Dispatcher getDefaultDispatcher()
          Returns the default Dispatcher object for this platform.
 String getDriverName(int n)
          Returns the driver name of this class, "disp".
 boolean queueForReceive(Receiver rcvr)
          Queues a Receiver object that is ready to receive.
 boolean queueForSend(Sender sender)
          Queues a Sender object for transmission.
 boolean removeFromReceiveQueue(Receiver rcvr)
          Remove a Receiver object from the receive queue.
 void serviceSendQueue()
          Examine the sendQueue and send a message if not empty.
static void setDefaultDispatcher(Dispatcher d)
          Sets the default Dispatcher for this platform.
 void stop()
          Stops the running Dispatcher threads.
 
Methods inherited from class com.sentilla.system.DriverAdapter
getNextDriver, setNextDriver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dispatcher

public Dispatcher()
Instantiates the Dispatcher and starts the send and receive threads. The Dispatcher should only be instantiated once on a platform. It starts two threads, one for sending messages and one for receiving. Instantiating more than once will create more threads than needed and lead to performance issues.

Method Detail

setDefaultDispatcher

public static void setDefaultDispatcher(Dispatcher d)
Sets the default Dispatcher for this platform.

Parameters:
d - a valid Dispatcher object

getDefaultDispatcher

public static Dispatcher getDefaultDispatcher()
Returns the default Dispatcher object for this platform. Allows applications to get a reference to the Dispatcher without querying the Drivers interface.

Returns:
the default Dispatcher object

stop

public void stop()
Stops the running Dispatcher threads. This method will stop the receive and send threads.


dispatch

public void dispatch(Receiver rcvr)
Dispatches messages to protocols and waiting receivers. The input is a Receiver object containing the received message.

Parameters:
rcvr - Receiver object containing the received message.
See Also:
Receiver

serviceSendQueue

public void serviceSendQueue()
Examine the sendQueue and send a message if not empty. This method blocks until a message is inserted into the sendQueue linked list. The unblocking is accomplished with an interrupt.


queueForSend

public boolean queueForSend(Sender sender)
Queues a Sender object for transmission. The data is contained in the Sender object and should only be called by the Sender class.

Parameters:
sender - Sender object containing the message.
Returns:
true if data is successfully queued
See Also:
Sender

queueForReceive

public boolean queueForReceive(Receiver rcvr)
Queues a Receiver object that is ready to receive. The input is a Receiver containing the received message class. This method should only be called by the Receiver class.

Parameters:
rcvr - Receiver object containing the received message.
Returns:
true if data is successfully queued
See Also:
Receiver

removeFromReceiveQueue

public boolean removeFromReceiveQueue(Receiver rcvr)
Remove a Receiver object from the receive queue. Used internally to remove Receiver objects upon thread death.


getDriverName

public String getDriverName(int n)
Returns the driver name of this class, "disp". Drivers can optionally have more than one name, associated with a different index number. This driver has a single name.

Specified by:
getDriverName in interface Driver
Specified by:
getDriverName in class DriverAdapter
Parameters:
n - index of class name
Returns:
the string "disp"
See Also:
Drivers, Driver


Copyright © 2007 Sentilla Corporation. All Rights Reserved.