Complete PDP connection refactor. 31/19731/2
authorSteven Pisarski <s.pisarski@cablelabs.com>
Wed, 6 May 2015 17:54:38 +0000 (11:54 -0600)
committerThomas Kee <xsited@yahoo.com>
Fri, 8 May 2015 19:52:02 +0000 (12:52 -0700)
Fixed error handling in run() and moved the addition of new state managers up to the super.

Change-Id: Ia751f131d690cfccbf590d728e0eb2863300ed42
Signed-off-by: Steven Pisarski <s.pisarski@cablelabs.com>
packetcable-driver/src/main/java/org/pcmm/PCMMPdpConnection.java
packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpConnection.java

index c14a4d911e036c5218e1fbc132d9e528e5cf85b9..5c50667c5c37cbe1b92d0e5ecb8e960ebde8451b 100644 (file)
@@ -6,7 +6,6 @@ package org.pcmm;
 
 import org.umu.cops.prpdp.COPSPdpConnection;
 import org.umu.cops.prpdp.COPSPdpReqStateMan;
-import org.umu.cops.stack.COPSHandle;
 import org.umu.cops.stack.COPSPepId;
 import org.umu.cops.stack.COPSReqMsg;
 
@@ -37,10 +36,6 @@ public class PCMMPdpConnection extends COPSPdpConnection {
         _thisProcess = process;
     }
 
-    public void addStateMan(final COPSHandle handle, final PCMMPdpReqStateMan man) {
-        _managerMap.put(handle, man);
-    }
-
     /**
      * Returns an instance of a COPSPdpReqStateMan
      * @param reqMsg - the request on which to create the state manager
index bb550f710774e2c3dea9561043b62110c64ba367..2248a9e416ba939111b0fc9fa1c359aadceb73f6 100644 (file)
@@ -76,14 +76,18 @@ public class COPSPdpConnection extends COPSConnection {
         _managerMap = new ConcurrentHashMap<>();
     }
 
+    public void addStateMan(final COPSHandle handle, final COPSPdpReqStateMan man) {
+        _managerMap.put(handle, man);
+    }
+
     /**
      * Main loop
      */
     public void run () {
         Date lastSendKa = new Date();
         Date lastRecKa = new Date();
-        try {
-            while (!_sock.isClosed()) {
+        while (!_sock.isClosed()) {
+            try {
                 if (_sock.getInputStream().available() != 0) {
                     processMessage(_sock);
                     lastRecKa = new Date();
@@ -115,17 +119,18 @@ public class COPSPdpConnection extends COPSConnection {
 
                 try {
                     Thread.sleep(500);
-                } catch (Exception e) {
-                    logger.error("Exception thrown while sleeping", e);
+                } catch (InterruptedException e) {
+                    logger.warn("Thread interrupted, shutting down", e);
+                    break;
                 }
-
+            } catch (Exception e) {
+                logger.error("Error while processing socket messages, continue processing", e);
             }
-        } catch (Exception e) {
-            logger.error("Error while processing socket messages", e);
         }
 
         // connection closed by server
         try {
+            logger.info("Closing socket");
             _sock.close();
         } catch (IOException e) {
             logger.error("Error closing socket", e);
@@ -133,6 +138,7 @@ public class COPSPdpConnection extends COPSConnection {
 
         // Notify all Request State Managers
         try {
+            logger.info("Notifying state managers that PDP connection is closing");
             notifyCloseAllReqStateMan();
         } catch (COPSException e) {
             logger.error("Error closing state managers");