Boeing Simulation 3.1 API Specification

worldsimulator
Class SocketSimulatorComponentTemplate

java.lang.Object
  |
  +--objects.WhatWhere
        |
        +--objects.MovableWhatWhere
              |
              +--worldsimulator.SocketSimulatorComponentTemplate
All Implemented Interfaces:
Component, Extensible, Locatable, Movable, Runnable, Serializable
Direct Known Subclasses:
SimulatorBus, SimulatorSchool, SimulatorTank

public abstract class SocketSimulatorComponentTemplate
extends MovableWhatWhere
implements Component, Runnable, Serializable

Base class for all Socket-based components that will interact with the ComponentizedSimulator. This class is based on the template method pattern. This class will use sockets to accept incoming connections.

Subclasses will in addition to behavior define the types of objects that can connect to it. Allowing for incoming connections allows for other components to gain control over this component's actions.

Version:
$Revision:
Author:
Dave Jurgens
See Also:
SocketComponentTemplate, Serialized Form

Field Summary
private  connect.CreatesConnection connection
          The object that allows other components to connect to it in an opaque manner.
private  Set connections
          A set containing all the ChannelBundle objects that are currently connected to this component.
private static int currentPort
          The current port that the most recently constructed SocketSimulatorComponentTemplate object was constructed by using the default constructor.
private static boolean debug
          Flag for outputting debug messages.
private static int DEFAULT_PORT
          The port that SocketSimulatorComponentTemplate>/tt> objects will first attempt to initialize if the construct without a port assignment is called.
private  connect.ComponentEmissary representative
          The emissary used to represent this component when forming remote connections
private static long serialVersionUID
           
protected  connect.ChannelBundle simulatorConnection
          The channels over which this UCAV will communicate with the Simulator.
protected  util.ConsumerQueue simulatorQueue
          The multithreaded queue for reading in objects from the server.
private  ServerSocket ss
          The ServerSocket used to receive incoming connections.
private  boolean started
          Flag for testing whether this object has started its periodic run calls.
private  util.Ceaseable worker
          The periodic thread responsible for calling the run method.
 
Fields inherited from class objects.WhatWhere
dim, loc
 
Constructor Summary
SocketSimulatorComponentTemplate(objects.Location loc, objects.Dimension d, connect.CreatesConnection toSimulator)
          Constructs this Component on the first available port.
SocketSimulatorComponentTemplate(objects.Location loc, objects.Dimension d, connect.CreatesConnection toSimulator, int listeningPort)
          Constructs the Component and connects it to the server.
 
Method Summary
protected abstract  boolean accept(Class requestingType)
          Returns whether this component will accept a connection from the the requesting object of the speicifed type.
protected abstract  boolean allowMethod(util.MethodRequest request)
          Returns true if this object accepts the method being invoked upon itself.
 void connect(connect.CreatesConnection cc)
          Attempts to form a connection between this Component to the component reached by this ComponentEmissary.
protected static void debug(String s)
          Emits a message if the debug flag is enabled.
abstract  boolean equals(Object other)
          Extending classes should define behavior that would ensure equality across a network.
protected  connect.ComponentEmissary getComponentEmissary()
          Returns the ComponentEmissary that represents this object.
 connect.CreatesConnection getConnection()
          Returns the CreatesConnection that connects to this component.
private static int getNextAvailablePort()
          Returns the first available port to construct a ServerSocket.
 objects.WhatWhere getObject()
          Returns an instance of this object.
protected  Runnable getOverrunLogic()
          Returns the overrun logic should the time of execution of the SimulatorObject exceed the specified period.
protected abstract  long getStepCost()
          Returns the time interval in milliseconds in which the step function may be called and return.
protected abstract  long getUpdatePeriod()
          Returns the time in milliseconds between subsequent calls of the periodic step function.
abstract  int hashCode()
          Extending classes should define behavior that would ensure equality across a network.
 boolean isStarted()
          Returns whether the object has begun periodic movements.
protected abstract  void processIncomingConnection(Class hostType, connect.ChannelBundle acceptedConnection)
          Handles the bevahior of this component when another component initiates the connection to this component.
protected abstract  void processOutgoingConnection(Class hostType, connect.ChannelBundle acceptedConnection)
          Handles the bevahior of this component when it initiates a connection to a remote component
private  void readObject(ObjectInputStream in)
          Reads in the object using the default serailization methods and then sets the started flag to false.
 void run()
          Calls the periodic step function.
private  void startListeningThread()
          Receives incoming connection requests, tests for admission acceptance and then passes the ChannelBundle and Class to the subclass for additional processing.
 void startPeriodicMovements()
          Starts the WorkerThread that moves this UCAV, and begins processing MethodRequest objects sent to this component from the ComponentizedSimulator.
private  void startSimulatorRequestThread()
          This method handles MethodRequest objects that are sent to this object from the ComponentizedSimulator.
abstract  void step()
          Extending classes should define a unit step behavior that will be periodically called.
protected  void stopPeriodicRun()
          Finishes processing the current call of run, and then exits the periodic thread.
 
Methods inherited from class objects.MovableWhatWhere
setLoc, setLoc
 
Methods inherited from class objects.WhatWhere
bound, getCenter, getDimensions, getDistance, getHeight, getLoc, getWidth, isEastOf, isNorthOf, isSouthOf, isWestOf, overlaps
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface objects.Locatable
getDistance, getLoc, isEastOf, isNorthOf, isSouthOf, isWestOf
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

simulatorConnection

protected transient connect.ChannelBundle simulatorConnection
The channels over which this UCAV will communicate with the Simulator.


simulatorQueue

protected transient util.ConsumerQueue simulatorQueue
The multithreaded queue for reading in objects from the server.


started

private boolean started
Flag for testing whether this object has started its periodic run calls.


worker

private transient util.Ceaseable worker
The periodic thread responsible for calling the run method.

See Also:
RealtimeThread, WorkerThread

ss

private transient ServerSocket ss
The ServerSocket used to receive incoming connections. If in the process of establishing the server socket, an acception is thrown, this will be set to null.


connections

private final transient Set connections
A set containing all the ChannelBundle objects that are currently connected to this component.


connection

private connect.CreatesConnection connection
The object that allows other components to connect to it in an opaque manner.


representative

private connect.ComponentEmissary representative
The emissary used to represent this component when forming remote connections


DEFAULT_PORT

private static final int DEFAULT_PORT
The port that SocketSimulatorComponentTemplate>/tt> objects will first attempt to initialize if the construct without a port assignment is called.

See Also:
Constant Field Values

currentPort

private static int currentPort
The current port that the most recently constructed SocketSimulatorComponentTemplate object was constructed by using the default constructor.


debug

private static boolean debug
Flag for outputting debug messages.

Constructor Detail

SocketSimulatorComponentTemplate

public SocketSimulatorComponentTemplate(objects.Location loc,
                                        objects.Dimension d,
                                        connect.CreatesConnection toSimulator,
                                        int listeningPort)
Constructs the Component and connects it to the server. If the port provided is not a valid port upon which to construct a ServerSocket, then this component will continue its operation but will not listen for incoming connections.

Parameters:
listeningPort - the port that this socket-based Component use to receiving incoming connections

SocketSimulatorComponentTemplate

public SocketSimulatorComponentTemplate(objects.Location loc,
                                        objects.Dimension d,
                                        connect.CreatesConnection toSimulator)
Constructs this Component on the first available port.

Method Detail

accept

protected abstract boolean accept(Class requestingType)
Returns whether this component will accept a connection from the the requesting object of the speicifed type.


allowMethod

protected abstract boolean allowMethod(util.MethodRequest request)
Returns true if this object accepts the method being invoked upon itself.


connect

public void connect(connect.CreatesConnection cc)
Attempts to form a connection between this Component to the component reached by this ComponentEmissary. If the remote component rejects the connection, the link formation fails, but does not kill this component.

Specified by:
connect in interface Component
See Also:
SocketComponentTemplate.allowMethod(util.MethodRequest)

debug

protected static void debug(String s)
Emits a message if the debug flag is enabled.


equals

public abstract boolean equals(Object other)
Extending classes should define behavior that would ensure equality across a network.

Overrides:
equals in class Object

getComponentEmissary

protected connect.ComponentEmissary getComponentEmissary()
Returns the ComponentEmissary that represents this object.


getConnection

public connect.CreatesConnection getConnection()
Returns the CreatesConnection that connects to this component.

Specified by:
getConnection in interface Component

getNextAvailablePort

private static int getNextAvailablePort()
Returns the first available port to construct a ServerSocket.


getObject

public final objects.WhatWhere getObject()
Returns an instance of this object. At times, the simuluator may ask this object for a reference of itself for comparison. The method is marked protected so that it may only be invoked via remote method invocation.


getOverrunLogic

protected Runnable getOverrunLogic()
Returns the overrun logic should the time of execution of the SimulatorObject exceed the specified period.

See Also:
RealtimeThread

getStepCost

protected abstract long getStepCost()
Returns the time interval in milliseconds in which the step function may be called and return.

See Also:
step()

getUpdatePeriod

protected abstract long getUpdatePeriod()
Returns the time in milliseconds between subsequent calls of the periodic step function.

See Also:
step()

hashCode

public abstract int hashCode()
Extending classes should define behavior that would ensure equality across a network.

Overrides:
hashCode in class Object

isStarted

public boolean isStarted()
Returns whether the object has begun periodic movements.


processOutgoingConnection

protected abstract void processOutgoingConnection(Class hostType,
                                                  connect.ChannelBundle acceptedConnection)
Handles the bevahior of this component when it initiates a connection to a remote component

See Also:
connect(connect.CreatesConnection)

processIncomingConnection

protected abstract void processIncomingConnection(Class hostType,
                                                  connect.ChannelBundle acceptedConnection)
Handles the bevahior of this component when another component initiates the connection to this component.

See Also:
connect(connect.CreatesConnection)

run

public final void run()
Calls the periodic step function.

Specified by:
run in interface Runnable
See Also:
step()

startListeningThread

private void startListeningThread()
Receives incoming connection requests, tests for admission acceptance and then passes the ChannelBundle and Class to the subclass for additional processing.


startPeriodicMovements

public final void startPeriodicMovements()
Starts the WorkerThread that moves this UCAV, and begins processing MethodRequest objects sent to this component from the ComponentizedSimulator.


startSimulatorRequestThread

private void startSimulatorRequestThread()
This method handles MethodRequest objects that are sent to this object from the ComponentizedSimulator.


step

public abstract void step()
Extending classes should define a unit step behavior that will be periodically called.

See Also:
run()

stopPeriodicRun

protected final void stopPeriodicRun()
Finishes processing the current call of run, and then exits the periodic thread.


readObject

private final void readObject(ObjectInputStream in)
                       throws IOException,
                              ClassNotFoundException
Reads in the object using the default serailization methods and then sets the started flag to false. This method ensures that upon deserialization, any component will by default have started set to be false.

IOException
ClassNotFoundException
See Also:
started, isStarted()

Boeing Simulation 3.1 API Specification

To submit a bug or feature email the author of that class. Funding for this research was provided by Boeing and DARPA.