From 8116110e78193c2135d8b2905503ff97d142f904 Mon Sep 17 00:00:00 2001 From: terry-norbraten <tnorb@comcast.net> Date: Mon, 29 Jun 2020 12:16:02 -0700 Subject: [PATCH] must specify sentToNet in the constructor, else, the listener thread starts before a "false" can be interpreted --- src/edu/nps/moves/dis7/examples/PduReaderPlayer.java | 10 ++++++---- src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java | 8 +++----- test/edu/nps/moves/dis7/AllPduRoundTripTest.java | 3 +-- test/edu/nps/moves/dis7/SignalPdusTest.java | 3 +-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/edu/nps/moves/dis7/examples/PduReaderPlayer.java b/src/edu/nps/moves/dis7/examples/PduReaderPlayer.java index 2b5d2dafa4..fd292dcfc7 100644 --- a/src/edu/nps/moves/dis7/examples/PduReaderPlayer.java +++ b/src/edu/nps/moves/dis7/examples/PduReaderPlayer.java @@ -41,22 +41,24 @@ public class PduReaderPlayer break; case 1: outDir = args[0]; + sendToNet = Boolean.valueOf(args[1]); break; case 3: outDir = args[0]; mcast = args[1]; port = Integer.parseInt(args[2]); - sendToNet = true; + sendToNet = Boolean.valueOf(args[3]); break; default: - System.err.println("Usage: PduReaderPlayer() or PduReaderPlayer(\"outputdir\") or PduReaderPlayer(\"outputdir\",\"multicast address\", ipPort"); + System.err.println("Usage: PduReaderPlayer() or " + + "PduReaderPlayer(\"outputdir\", \"sendToNet true/false\") or " + + "PduReaderPlayer(\"outputdir\", \"multicast address\", \"ipPort\", \"sendToNet true/false\""); System.exit(1); } System.out.println("Beginning pdu playback from directory " + outDir); try { - PduPlayer pduPlayer = new PduPlayer(mcast, port, Path.of(outDir)); - pduPlayer.sendToNet(sendToNet); + PduPlayer pduPlayer = new PduPlayer(mcast, port, Path.of(outDir), sendToNet); mystate state = mystate.RUNNING; Scanner scan = new Scanner(System.in); diff --git a/src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java b/src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java index 5ec1250128..7ca8ff4aca 100644 --- a/src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java +++ b/src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java @@ -54,12 +54,14 @@ public class PduPlayer { * @param ip the multicast group address to utilize * @param port the multicast port to utilize * @param disLogDirectory a path to the directory containing PDU log files + * @param sendToNet to capture X3D interpolator values - if desired * @throws IOException if something goes wrong processing files */ - public PduPlayer(String ip, int port, Path disLogDirectory) throws IOException { + public PduPlayer(String ip, int port, Path disLogDirectory, boolean sendToNet) throws IOException { this.disLogDirectory = disLogDirectory; this.ip = ip; this.port = port; + this.netSend = sendToNet; thrd = new Thread(() -> begin()); thrd.setPriority(Thread.NORM_PRIORITY); @@ -84,10 +86,6 @@ public class PduPlayer { private byte[] globalByteBufferForX3dInterPolators = null; // -------------------- End Variables for X3D autogenerated code - public void sendToNet(boolean tf) { - netSend = tf; - } - public void addRawListener(RawListener lis) { rawListener = lis; } diff --git a/test/edu/nps/moves/dis7/AllPduRoundTripTest.java b/test/edu/nps/moves/dis7/AllPduRoundTripTest.java index 484f495eee..e8a798ddff 100644 --- a/test/edu/nps/moves/dis7/AllPduRoundTripTest.java +++ b/test/edu/nps/moves/dis7/AllPduRoundTripTest.java @@ -207,8 +207,7 @@ public class AllPduRoundTripTest { sem.acquire(); Path path = Path.of(recorder.getLogFile()).getParent(); - PduPlayer player = new PduPlayer(disnetworking.getMcastGroup(), disnetworking.getDisPort(), path); - player.sendToNet(false); + PduPlayer player = new PduPlayer(disnetworking.getMcastGroup(), disnetworking.getDisPort(), path, false); player.addRawListener(ba -> { if (ba != null) { Pdu pdu = pduFactory.createPdu(ba); diff --git a/test/edu/nps/moves/dis7/SignalPdusTest.java b/test/edu/nps/moves/dis7/SignalPdusTest.java index c416f7bd35..5f9b670838 100644 --- a/test/edu/nps/moves/dis7/SignalPdusTest.java +++ b/test/edu/nps/moves/dis7/SignalPdusTest.java @@ -133,8 +133,7 @@ public class SignalPdusTest { Path path = Path.of(recorder.getLogFile()).getParent(); // Note: the player will playback all log files in the given path - PduPlayer player = new PduPlayer(netif.getMcastGroup(), netif.getDisPort(), path); - player.sendToNet(false); + PduPlayer player = new PduPlayer(netif.getMcastGroup(), netif.getDisPort(), path, false); player.addRawListener(ba -> { if (ba != null) assertNotNull(pduFac.createPdu(ba), "PDU creation failure"); -- GitLab