From a644ab685e92633e9b653b7832206fc6dee06421 Mon Sep 17 00:00:00 2001
From: terry-norbraten <tnorb@comcast.net>
Date: Fri, 26 Jun 2020 19:50:45 -0600
Subject: [PATCH] remove the added listener

---
 .../dis7/utilities/stream/PduRecorder.java    | 47 +++++++++++--------
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java b/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java
index c4df2f3639..821a23f0ff 100644
--- a/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java
+++ b/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java
@@ -48,25 +48,10 @@ public class PduRecorder implements PduReceiver
   
   private static String pduLogEncoding = ENCODING_PLAINTEXT; // TODO use Java enumerations, generalize/share across library
 
-    /**
-     * TODO change this to enumeration type for strictness
-     * @return the pduLogEncoding
-     */
-    public static String getEncoding() {
-        return pduLogEncoding;
-    }
-
-    /**
-     * @param aEncoding the pduLogEncoding to set
-     */
-    public static void setEncoding(String aEncoding) {
-        pduLogEncoding = aEncoding;
-    }
-
   private Writer writer;
   private File   logFile;
-  
   private DisThreadedNetIF disThreadedNetIF;
+  private DisThreadedNetIF.RawPduListener lis; 
   
   /**
    * Default constructor that uses default values for output directory, multicast
@@ -106,12 +91,34 @@ public class PduRecorder implements PduReceiver
     writer = new PrintWriter(new BufferedWriter(new FileWriter(logFile)));
     
     disThreadedNetIF = new DisThreadedNetIF(port, mcastaddr);
-    disThreadedNetIF.addRawListener(bAndL -> {
-        receivePdu(bAndL.buff, bAndL.length);
-    });
+    
+    lis = new DisThreadedNetIF.RawPduListener() {
+        @Override
+        public void incomingPdu(DisThreadedNetIF.BuffAndLength bAndL) {
+            receivePdu(bAndL.buff, bAndL.length);
+        }
+    };
+    
+    disThreadedNetIF.addRawListener(lis);
     System.out.println(getClass() + " listening to IP address " + mcastaddr + " on port: " + port);
   }
   
+    /**
+     * TODO change this to enumeration type for strictness
+     *
+     * @return the pduLogEncoding
+     */
+    public static String getEncoding() {
+        return pduLogEncoding;
+    }
+
+    /**
+     * @param aEncoding the pduLogEncoding to set
+     */
+    public static void setEncoding(String aEncoding) {
+        pduLogEncoding = aEncoding;
+    }
+  
   public void startResume()
   {
     doSave = true;
@@ -124,6 +131,8 @@ public class PduRecorder implements PduReceiver
   
   public File end()
   {
+    doSave = false;
+    disThreadedNetIF.removeRawListener(lis);
     disThreadedNetIF.kill();
 
     writeFooter();
-- 
GitLab