Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----mil.navy.nps.dis.NetworkMonitor
Since there are typcially two threads operating on this data, we need to be careful about synchronized access here, so the threads don't corrupt the internal data structures.
This object is typically configured with the port it's going to be reading from. When instantiated, a socket on that port is opened, and a thread spawned to read it. It then begins to continuously read data.
Basically, this object encapsulates both a socket and a thread that reads from the socket. The advantage is that this makes the external interface very simple; as far as the consumer is concerned, he asks for and gets PDUs that have arrived since the last time he asked, without having to worry about blocking. Possible disadvantages include buffer overflow. Right now there's no guard against this, so if the consumer doesn't ask for PDUs, and the packets keep coming in, the datagram buffer will keep on storing them up. We don't worry about thread or socket cleanup, since the expectation is that the whole shebang will get flushed only when the whole application quits.
The object implements the Runnable interface. To create a new instance of the network monitor, you need to do something like this:
"Monitor" is probably a bad term, since it overloads some other terminology in Java. "NetworkListener" would probably be better. Also, this should probably be broken out so that an abstract class NetworkMonitor has two concrete sublcasses, NetworkMonitorUnicast and NetworkMonitorMulticast.
Field Summary | |
java.util.Vector | datagramBuffer
|
int | datagramPort
|
java.net.DatagramSocket | datagramSocket
|
java.lang.String | multicastAddress
|
java.net.MulticastSocket | multicastSocket
|
netscape.security.PrivilegeManager | privilegeManager
|
java.lang.Thread | readerThread
|
byte | ttl
|
boolean | usingMulticast
|
Constructor Summary | |
NetworkMonitor(int pDatagramPort)
|
|
NetworkMonitor(java.lang.String pMulticastAddress,
int pDatagramPort)
|
Method Summary | |
void | finalize()
|
java.util.Vector | receivedPdus()
|
void | resumeReading()
|
void | run()
|
void | sendPDU(ProtocolDataUnit pdu,
java.lang.String pDestinationHost,
int pDestinationSocket)
|
void | sendPDUMcast(ProtocolDataUnit pPdu)
|
void | setThread(java.lang.Thread pThread)
|
void | setTTL(byte pTTL)
|
void | suspendReading()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
boolean usingMulticast
int datagramPort
java.net.DatagramSocket datagramSocket
java.net.MulticastSocket multicastSocket
java.lang.String multicastAddress
byte ttl
java.lang.Thread readerThread
java.util.Vector datagramBuffer
netscape.security.PrivilegeManager privilegeManager
Constructor Detail |
public NetworkMonitor(int pDatagramPort)
public NetworkMonitor(java.lang.String pMulticastAddress, int pDatagramPort)
Method Detail |
public void run()
public java.util.Vector receivedPdus()
public void setTTL(byte pTTL)
public void sendPDUMcast(ProtocolDataUnit pPdu)
public void sendPDU(ProtocolDataUnit pdu, java.lang.String pDestinationHost, int pDestinationSocket)
public void setThread(java.lang.Thread pThread)
public void suspendReading()
public void resumeReading()
protected void finalize()
Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |