|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.nps.moves.net.BehaviorProducerUDP
public class BehaviorProducerUDP
This implements an object that can read and write DIS PDUs from a unicast or multicast UDP socket. It implements the BehaviorProducer interface, which allows objects to register as listeners for PDU arrival events, and the BehaviorWriter interface, which allows PDUs to be written. It's a bit complex internally, but not all that bad from an interface standpoint.
This runs in a thread of its own. The listeners for PDU events can either run in threads of their own, which is a bit complex, or simply process PDU objects as they come in, which is simple but may have performance problems if processing a PDU takes a long time.
Field Summary |
---|
Fields inherited from interface edu.nps.moves.net.BehaviorWriterIF |
---|
MTU_SIZE |
Constructor Summary | |
---|---|
BehaviorProducerUDP(java.net.DatagramSocket pSocket)
|
Method Summary | |
---|---|
void |
addListener(BehaviorConsumerIF consumer)
Add a listener that will be notified when a PDU is ready. |
void |
removeListener(BehaviorConsumerIF consumer)
Remove a listener/consumer of PDUs from the notification list. |
void |
run()
Entry point for thread |
void |
setDefaultDestination(java.net.InetAddress addr,
int port)
Set the default destination that the plain write(pdu) method will send data to. |
void |
setUseCopies(boolean shouldCreateCopy)
This is a performance option. |
void |
write(java.nio.ByteBuffer buffer)
Write PDU information to the default destination. |
void |
write(java.nio.ByteBuffer buffer,
int numberOfBytes)
If we have a byte buffer we are marshalling to, it may be bigger than the actuall size of the marshalled PDU. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BehaviorProducerUDP(java.net.DatagramSocket pSocket)
Method Detail |
---|
public void addListener(BehaviorConsumerIF consumer)
BehaviorProducerIF
addListener
in interface BehaviorProducerIF
consumer
- the object that will be notified of the PDUpublic void removeListener(BehaviorConsumerIF consumer)
BehaviorProducerIF
removeListener
in interface BehaviorProducerIF
consumer
- to be removed from the notification listpublic void setDefaultDestination(java.net.InetAddress addr, int port)
BehaviorWriterIF
setDefaultDestination
in interface BehaviorWriterIF
addr
- first object that describes destination (eg, IP)port
- second object that describes destination (eg, port number)public void write(java.nio.ByteBuffer buffer)
BehaviorWriterIF
write
in interface BehaviorWriterIF
buffer
- the DIS PDU infomation to be writtenpublic void write(java.nio.ByteBuffer buffer, int numberOfBytes)
buffer
- numberOfBytes
- public void setUseCopies(boolean shouldCreateCopy)
BehaviorProducerIF
The default behavior should be to distribute a new, unqiue copy to each listener. this allows the user to override this behavior for better performance.
setUseCopies
in interface BehaviorProducerIF
shouldCreateCopy
- true to create a new copy for each listener, false for a shared copy for each listenerpublic void run()
run
in interface java.lang.Runnable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |