mil.navy.nps.dis
Class BehaviorStreamBuffer

java.lang.Object
  extended bymil.navy.nps.dis.BehaviorStreamBuffer
All Implemented Interfaces:
AllPermissionsBadge, java.lang.Runnable
Direct Known Subclasses:
BehaviorStreamBufferFile, BehaviorStreamBufferTCP, BehaviorStreamBufferUDP

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

BehaviorStreamBuffer is an abstract class that defines functionality for other subclasses, including BehaviorStreamBufferNetwork and BehaviorStreamBufferFile. The idea is that we have a single interface for getting things from the external world, be it from a network or a file.

This includes a BehaviorStreamBufferInfo object, which includes info about the stream such as URLs where more info can be found, rtp status, version number, etc.

Author:
DMcG

Field Summary
protected  boolean DEBUG
          When DEBUG is true, System.out.println text messages trace the internals of script operation.
protected  BehaviorStreamBufferInfo info
           
protected  boolean inputThreadStarted
           
protected  boolean readThreadRunning
           
protected  boolean rtpEnabled
           
protected  boolean runContinue
           
protected  SecurityStrategy strategy
          SecurityStrategy is used as a way to get around the java sandbox.
 
Constructor Summary
BehaviorStreamBuffer()
           
 
Method Summary
protected  void checkForThreadStart()
          This is some thread synchronization code.
abstract  void cleanup()
          Closes down input buffers, sockets, or open files nicely
protected  void debug(java.lang.String pDiagnostic)
          Debugging output.
protected abstract  void finalize()
          Finalize method--used to clean up any sockets that are still open
 boolean getDEBUG()
          Retrieve value of DEBUG.
 BehaviorStreamBufferInfo getInfo()
           
abstract  ProtocolDataUnit getNextPdu()
          Get the next PDU from the input stream.
 boolean getRtpEnabled()
          Returns true if this BSB is using RTP.
abstract  java.util.Vector receivedPdus()
          Returns a vector of all the PDUs received since the last time we asked.
abstract  void resumeReading()
          Start reading packets from the datagramStreamBuffer again.
abstract  void run()
          Threading method to read/write until shutdown.
abstract  void sendPdu(ProtocolDataUnit pPdu)
          Sends a PDU.
 void sendPdu(ProtocolDataUnit pPdu, java.lang.Object pAddress1, int pAddress2)
          Utility method accepts int ports
abstract  void sendPdu(ProtocolDataUnit pPdu, java.lang.Object pAddress1, java.lang.Object pAddress2)
          Send a PDU to an address.
 void setDEBUG(boolean pDEBUG)
          Set value of DEBUG.
 void setInfo(BehaviorStreamBufferInfo pInfo)
           
 void setRtpEnabled(boolean pEnabled)
          setRtpEnabled turns on or off the RTP headers.
abstract  void shutdown()
          Terminate the run loop and shutdown the thread.
protected abstract  void startInputThread()
          Simple method to launch thread.
 void startInputThreadWithSecurity()
          Starts the input thread, but with security hoop-jumping enabled.
abstract  void suspendReading()
          suspend reading in the DatagramStreamBuffer
protected  void trace(java.lang.String pDiagnostic)
          Guaranteed debugging output.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputThreadStarted

protected boolean inputThreadStarted

runContinue

protected boolean runContinue

rtpEnabled

protected boolean rtpEnabled

info

protected BehaviorStreamBufferInfo info

readThreadRunning

protected boolean readThreadRunning

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.


DEBUG

protected boolean DEBUG
When DEBUG is true, System.out.println text messages trace the internals of script operation. Text output appears in the Java Console (CosmoPlayer browser) or in the VRML console (WorldView browser)

Constructor Detail

BehaviorStreamBuffer

public BehaviorStreamBuffer()
Method Detail

startInputThread

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


startInputThreadWithSecurity

public void startInputThreadWithSecurity()
Starts the input thread, but with security hoop-jumping enabled.


shutdown

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


suspendReading

public abstract void suspendReading()
suspend reading in the DatagramStreamBuffer


resumeReading

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


run

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

Specified by:
run in interface java.lang.Runnable

setRtpEnabled

public void setRtpEnabled(boolean pEnabled)
setRtpEnabled turns on or off the RTP headers.


getRtpEnabled

public boolean getRtpEnabled()
Returns true if this BSB is using RTP.


getInfo

public BehaviorStreamBufferInfo getInfo()

setInfo

public void setInfo(BehaviorStreamBufferInfo pInfo)

receivedPdus

public abstract 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.


getNextPdu

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


sendPdu

public abstract 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.


sendPdu

public abstract 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!)

Parameters:
pPdu - protocol data unit being sent
pAddress1 - the first part of the address, typically the inet address
pAddress2 - the second part of the address, typically null or the destination port

sendPdu

public void sendPdu(ProtocolDataUnit pPdu,
                    java.lang.Object pAddress1,
                    int pAddress2)
Utility method accepts int ports


cleanup

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


finalize

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

Throws:
java.lang.Throwable

getDEBUG

public boolean getDEBUG()
Retrieve value of DEBUG. When DEBUG is true, System.out.println text messages trace the internals of script operation. Text output appears in the Java Console (CosmoPlayer browser) or in the VRML console (WorldView browser)


setDEBUG

public void setDEBUG(boolean pDEBUG)
Set value of DEBUG. When DEBUG is true, System.out.println text messages trace the internals of script operation. Text output appears in the Java Console (CosmoPlayer browser) or in the VRML console (WorldView browser)


debug

protected void debug(java.lang.String pDiagnostic)
Debugging output. Pass in a string, and it gets printed out on the console. You can pass in strings such as "foo " + bar.getName().


trace

protected void trace(java.lang.String pDiagnostic)
Guaranteed debugging output. Pass in a string, and it gets printed out on the console. You can pass in strings such as "foo " + bar.getName().


checkForThreadStart

protected void checkForThreadStart()
This is some thread synchronization code. When we start a bsb, the thread may take some amount of time to actually begin reading. This uses a boolean that gets flipped to true when the run() method actually begins. If the boolean isn't flipped, we wait for 5 sec, which should be plenty of time for the thread to finish starting and start reading.