Skip to content
Snippets Groups Projects
Commit 0cafb807 authored by brutzman's avatar brutzman
Browse files

slightly slower sending for reliability; keep object instantiations outside of...

slightly slower sending for reliability; keep object instantiations outside of loops for best performance
parent ca5b4c4c
No related branches found
No related tags found
No related merge requests found
...@@ -424,23 +424,26 @@ public class AllPduSender ...@@ -424,23 +424,26 @@ public class AllPduSender
InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
MulticastSocket multicastSocket = new MulticastSocket(DEFAULT_MULTICAST_PORT); MulticastSocket multicastSocket = new MulticastSocket(DEFAULT_MULTICAST_PORT);
multicastSocket.joinGroup(localMulticastAddress); multicastSocket.joinGroup(localMulticastAddress);
// keep object instantiations outside of loops for best performance
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] buffer;
Pdu aPdu;
DatagramPacket packet;
for (int idx = 0; idx < generatedPdusList.size(); idx++) for (int idx = 0; idx < generatedPdusList.size(); idx++)
{ {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); aPdu = generatedPdusList.get(idx);
DataOutputStream dos = new DataOutputStream(baos);
byte[] buffer;
Pdu aPdu = generatedPdusList.get(idx);
try try
{ {
aPdu.marshal(dos); aPdu.marshal(dos);
buffer = baos.toByteArray(); buffer = baos.toByteArray();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT);
multicastSocket.send(packet); multicastSocket.send(packet);
try { try {
Thread.sleep(100L); // TODO this kind of delay timing should be in a DIS sender class? Thread.sleep(250L); // TODO shouldn't this kind of delay timing be in a DIS sender class?
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
} }
String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue()); String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment