mil.navy.nps.dis
Class BehaviorStreamBufferTCP

java.lang.Object
  extended bymil.navy.nps.dis.BehaviorStreamBuffer
      extended bymil.navy.nps.dis.BehaviorStreamBufferTCP
All Implemented Interfaces:
AllPermissionsBadge, java.lang.Runnable

public abstract class BehaviorStreamBufferTCP
extends BehaviorStreamBuffer
implements java.lang.Runnable, AllPermissionsBadge

BehaviorStreamBufferTCP is a class responsible for interpreting data received via a TCP socket and interpreting it as DIS PDUs.

DIS is by nature packet-oriented, while TCP is stream-oriented. this means that we must parse the data as it comes in, to determine how many bytes to read. This can be done via the PDU length field in the PDU header. This is always at the same point in the packet, and describes how many bytes to read. By nature, if this count is off, the stream will get scrambled.

Author:
DMcG

Field Summary
static boolean DEBUG
           
static int MAX_DATAGRAM_SIZE
           
protected  SecurityStrategy strategy
          SecurityStrategy is used as a way to get around the java sandbox.
 
Fields inherited from class mil.navy.nps.dis.BehaviorStreamBuffer
info, inputThreadStarted, readThreadRunning, rtpEnabled, runContinue
 
Constructor Summary
BehaviorStreamBufferTCP(java.net.Socket pSocket)
          Constructor, takes a connected socket.
BehaviorStreamBufferTCP(java.lang.String pAddress, int port)
          Constructor; takes a string inet address and a port number.
 
Method Summary
 void cleanup()
          Closes down input buffers, sockets, or open files nicely
 void debug(java.lang.String pMessage)
          Debugging output
protected  void finalize()
          Finalize method--used to clean up any sockets that are still open
 ProtocolDataUnit getNextPdu()
          Get the next PDU from the input stream.
 java.util.Vector receivedPdus()
          Returns a vector of all the PDUs received since the last time we asked.
 void resumeReading()
          Start reading packets from the datagramStreamBuffer again.
 void run()
          Threading method to read/write until shutdown.
 void sendPdu(ProtocolDataUnit pPdu)
          Sends a PDU.
 void sendPdu(ProtocolDataUnit pPdu, java.lang.Object pAddress1, java.lang.Object pAddress2)
          Send a PDU to an address.
 void shutdown()
          Terminate the run loop and shutdown the thread.
 void startInputThread()
          Simple method to launch thread.
 void suspendReading()
          suspend reading in the DatagramStreamBuffer
 void trace(java.lang.String pMessage)
          tracing output
 
Methods inherited from class mil.navy.nps.dis.BehaviorStreamBuffer
checkForThreadStart, getDEBUG, getInfo, getRtpEnabled, sendPdu, setDEBUG, setInfo, setRtpEnabled, startInputThreadWithSecurity
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_DATAGRAM_SIZE

public static final int MAX_DATAGRAM_SIZE
See Also:
Constant Field Values

DEBUG

public static boolean DEBUG

strategy

protected SecurityStrategy strategy
SecurityStrategy is used as a way to get around the java sandbox. A security scheme is picked at runtime for whatever type of box we are running on.

Constructor Detail

BehaviorStreamBufferTCP

public BehaviorStreamBufferTCP(java.net.Socket pSocket)
Constructor, takes a connected socket. Also starts up a listening thread on this socket.


BehaviorStreamBufferTCP

public BehaviorStreamBufferTCP(java.lang.String pAddress,
                               int port)
Constructor; takes a string inet address and a port number. Establishes a connection to this server and uses that connection for communications. This also starts up a thread for communications with that server.

Method Detail

startInputThread

public void startInputThread()
Simple method to launch thread. This kicks of the BSBTCP and starts it reading in its own thread. This is required for some subclasses of BSB, such as sockets; for files, this is optional-- we can read one PDU at a time from them without blocking.

Specified by:
startInputThread in class BehaviorStreamBuffer

shutdown

public void shutdown()
Terminate the run loop and shutdown the thread. This should be used only for threaded readers.

Specified by:
shutdown in class BehaviorStreamBuffer

suspendReading

public void suspendReading()
suspend reading in the DatagramStreamBuffer

Specified by:
suspendReading in class BehaviorStreamBuffer

resumeReading

public void resumeReading()
Start reading packets from the datagramStreamBuffer again.

Specified by:
resumeReading in class BehaviorStreamBuffer

run

public void run()
Threading method to read/write until shutdown.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class BehaviorStreamBuffer

receivedPdus

public java.util.Vector receivedPdus()
Returns a vector of all the PDUs received since the last time we asked. Queries the underlying input buffer for this information.\ this is generally used with threaded readers.

Specified by:
receivedPdus in class BehaviorStreamBuffer

getNextPdu

public ProtocolDataUnit getNextPdu()
Get the next PDU from the input stream. This is generally used with unthreaded readers.

Specified by:
getNextPdu in class BehaviorStreamBuffer

sendPdu

public void sendPdu(ProtocolDataUnit pPdu)
Sends a PDU. If the underlying destination address has already been set, for example in a multicast or file, we don't need to supply an address.

Specified by:
sendPdu in class BehaviorStreamBuffer

sendPdu

public void sendPdu(ProtocolDataUnit pPdu,
                    java.lang.Object pAddress1,
                    java.lang.Object pAddress2)
Send a PDU to an address. Since the address can be in many forms, for example an InetAddress and a port number, we cheat here. The destination address is passed in as generic objects; a concrete subclass, such as a Unicast UDP object, will cast the generic objects here to what it expects, such as an InetAddress. (After checking for the right type with instanceof, of course!)

Note that if you're sending to the "standard" tcp destination address, you should use sendPdu().

Specified by:
sendPdu in class BehaviorStreamBuffer
Parameters:
pPdu - protocol data unit being sent
pAddress1 - TCP address of destination
pAddress2 - port of destination

cleanup

public void cleanup()
Closes down input buffers, sockets, or open files nicely

Specified by:
cleanup in class BehaviorStreamBuffer

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalize method--used to clean up any sockets that are still open

Specified by:
finalize in class BehaviorStreamBuffer
Throws:
java.lang.Throwable

trace

public void trace(java.lang.String pMessage)
tracing output

Overrides:
trace in class BehaviorStreamBuffer

debug

public void debug(java.lang.String pMessage)
Debugging output

Overrides:
debug in class BehaviorStreamBuffer