public class BehaviorProducerUDP extends java.lang.Object implements BehaviorProducerIF, BehaviorWriterIF, java.lang.Runnable
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.
MTU_SIZE
Constructor and Description |
---|
BehaviorProducerUDP(java.net.DatagramSocket pSocket) |
Modifier and Type | Method and Description |
---|---|
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.
|
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