copyright The Portico Project 2008.

org.portico.binding.jsop.rti
Class JSOPDaemon

java.lang.Object
  extended by org.portico.binding.jsop.rti.JSOPDaemon
All Implemented Interfaces:
Runnable

public class JSOPDaemon
extends Object
implements Runnable

The JSOPDaemon is responsible for handling incoming requets from remote clients wishing to connect to the RTI. The lifecycle of the daemon is controlled by the JSOPBootstrap class. Instances of this class are started in separate threads. When an instance is started (via the run() method), a new server socket is opened and the thread will continually sit and wait, listening for incoming connection requests.

Connection Management

The daemon also acts as a central repository of all currently active JSOP connections. When a new connection is made, the daemon creates and stores a new JSOPActiveConnection that manages the LRC-RTI conversation from thereon in. When the daemon is asked to shutdown, it in turn informs all of the remaining active connections and asks them to also shutdown.


Field Summary
private  List<JSOPActiveConnection> active
           
private  JSOPBootstrap bootstrap
           
private  org.apache.log4j.Logger logger
           
private  int port
           
private  ServerSocket serverSocket
           
 
Constructor Summary
JSOPDaemon(JSOPBootstrap bootstrap, int port)
          Create a new daemon that is to be associted with the given bootstrap and that should listen on the given port.
 
Method Summary
private  void addConnection(JSOPActiveConnection connection)
          Add the given connection to our local store.
protected  void removeConnection(JSOPActiveConnection connection)
          So that references to long dead connection objects are not kept lying around (and thus can be garbage collected), this method is provided with the sole intent that JSOPActiveConnection instances will use it to remove themselves from the store of active connections when they end processing through natural causes (this does not include when they are being asked ot manually shut down).
 void run()
          This method will start listening on the server socket, creating a new JSOPActiveConnection for each client that contacts it.
 void shutdown()
          This method will close the daemon's server socket (provided that it is active).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bootstrap

private JSOPBootstrap bootstrap

port

private int port

logger

private org.apache.log4j.Logger logger

serverSocket

private ServerSocket serverSocket

active

private List<JSOPActiveConnection> active
Constructor Detail

JSOPDaemon

public JSOPDaemon(JSOPBootstrap bootstrap,
                  int port)
           throws IOException
Create a new daemon that is to be associted with the given bootstrap and that should listen on the given port.

Parameters:
bootstrap - The bootstrap is kept so that it can be passed to all newly created JSOPActiveConnection's
port - The port on which the daemon should listen for incoming connections
Throws:
IOException - If there is a problem creating the server socket
Method Detail

run

public void run()
This method will start listening on the server socket, creating a new JSOPActiveConnection for each client that contacts it. Once the new connection has been created, it will store it in the local list of active connections and tell it to start working (via the Thread.start() call).

The thread will continue executing until the server socket is closed. Note that when this happens, all the currently active connections will not be asked to shutdown. All that will happen is that the thread will exit and there will no longer be a way for new clients to connect to the RTI via JSOP. The same process occurs if an unexpected IOException occurs while working with the server socket.

Specified by:
run in interface Runnable

shutdown

public void shutdown()
This method will close the daemon's server socket (provided that it is active). It will then iterate over all the currently registered JSOPActiveConnections and invoke their JSOPActiveConnection.shutdown() method. At each step, it will wait until the thread associated with the connection has stopped before it moves on.


addConnection

private void addConnection(JSOPActiveConnection connection)
Add the given connection to our local store. We use this method explicitly so that we can synchronize it and control concurrent access to the store. The associated removal method (removeConnection(JSOPActiveConnection)) is also synchronized.


removeConnection

protected void removeConnection(JSOPActiveConnection connection)
So that references to long dead connection objects are not kept lying around (and thus can be garbage collected), this method is provided with the sole intent that JSOPActiveConnection instances will use it to remove themselves from the store of active connections when they end processing through natural causes (this does not include when they are being asked ot manually shut down).


copyright The Portico Project 2008.