Replaced use of logger abstraction COPSDebug.java to having this class log directly... 87/18487/1
authorSteven Pisarski <s.pisarski@cablelabs.com>
Thu, 16 Apr 2015 21:09:15 +0000 (15:09 -0600)
committerSteven Pisarski <s.pisarski@cablelabs.com>
Thu, 16 Apr 2015 21:09:15 +0000 (15:09 -0600)
Change-Id: If1709dc853ddf210775319cde1e78d6f397ebb34
Signed-off-by: Steven Pisarski <s.pisarski@cablelabs.com>
packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpConnection.java

index d1c011cb4746ffe5c3e8a415c0ad9dfafb871b69..c79abc6a9a4e85103c25324c0549370812fea77a 100644 (file)
@@ -6,32 +6,23 @@
 \r
 package org.umu.cops.prpdp;\r
 \r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.umu.cops.stack.*;\r
+\r
 import java.io.IOException;\r
 import java.net.Socket;\r
 import java.util.Date;\r
-import java.util.Enumeration;\r
-import java.util.Hashtable;\r
-\r
-import org.umu.cops.common.COPSDebug;\r
-import org.umu.cops.stack.COPSClientCloseMsg;\r
-import org.umu.cops.stack.COPSContext;\r
-import org.umu.cops.stack.COPSDeleteMsg;\r
-import org.umu.cops.stack.COPSError;\r
-import org.umu.cops.stack.COPSException;\r
-import org.umu.cops.stack.COPSHeader;\r
-import org.umu.cops.stack.COPSKAMsg;\r
-import org.umu.cops.stack.COPSMsg;\r
-import org.umu.cops.stack.COPSPepId;\r
-import org.umu.cops.stack.COPSReportMsg;\r
-import org.umu.cops.stack.COPSReqMsg;\r
-import org.umu.cops.stack.COPSSyncStateMsg;\r
-import org.umu.cops.stack.COPSTransceiver;\r
+import java.util.Map;\r
+import java.util.concurrent.ConcurrentHashMap;\r
 \r
 /**\r
  * Class for managing an provisioning connection at the PDP side.\r
  */\r
 public class COPSPdpConnection implements Runnable {\r
 \r
+    public final static Logger logger = LoggerFactory.getLogger(COPSPdpConnection.class);\r
+\r
     /**\r
         Socket connected to PEP\r
      */\r
@@ -60,7 +51,7 @@ public class COPSPdpConnection implements Runnable {
     /**\r
         Maps a Client Handle to a Handler\r
      */\r
-    protected Hashtable _managerMap;\r
+    protected final Map<String, COPSPdpReqStateMan> _managerMap;\r
     // map < String(COPSHandle), COPSPdpHandler> HandlerMap;\r
 \r
     /**\r
@@ -96,7 +87,7 @@ public class COPSPdpConnection implements Runnable {
 \r
         _lastKa = new Date();\r
         _lastmessage = COPSHeader.COPS_OP_OPN;\r
-        _managerMap = new Hashtable(20);\r
+        _managerMap = new ConcurrentHashMap<>();\r
 \r
         _kaTimer = 0;\r
         _process = process;\r
@@ -150,22 +141,6 @@ public class COPSPdpConnection implements Runnable {
         return _lastmessage;\r
     }\r
 \r
-    /**\r
-     * Gets active handles\r
-     * @return   An <tt>Enumeration</tt> holding all active handles\r
-     */\r
-    public Enumeration getHandles() {\r
-        return _managerMap.keys();\r
-    }\r
-\r
-    /**\r
-     * Gets the handle map\r
-     * @return   A <tt>Hashtable</tt> holding the handle map\r
-     */\r
-    public Hashtable getReqStateMans() {\r
-        return _managerMap;\r
-    }\r
-\r
     /**\r
      * Gets the PEP-ID\r
      * @return   The ID of the PEP, as a <tt>String</tt>\r
@@ -218,7 +193,7 @@ public class COPSPdpConnection implements Runnable {
                     int _startTime = (int) (_lastRecKa.getTime());\r
                     int cTime = (int) (new Date().getTime());\r
 \r
-                    if ((int)(cTime - _startTime) > _kaTimer*1000) {\r
+                    if ((cTime - _startTime) > _kaTimer * 1000) {\r
                         _sock.close();\r
                         // Notify all Request State Managers\r
                         notifyNoKAAllReqStateMan();\r
@@ -228,7 +203,7 @@ public class COPSPdpConnection implements Runnable {
                     _startTime = (int) (_lastSendKa.getTime());\r
                     cTime = (int) (new Date().getTime());\r
 \r
-                    if ((int)(cTime - _startTime) > ((_kaTimer*3/4)*1000)) {\r
+                    if ((cTime - _startTime) > ((_kaTimer * 3/4) * 1000)) {\r
                         COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_KA);\r
                         COPSKAMsg msg = new COPSKAMsg();\r
 \r
@@ -241,23 +216,29 @@ public class COPSPdpConnection implements Runnable {
 \r
                 try {\r
                     Thread.sleep(500);\r
-                } catch (Exception e) {};\r
+                } catch (Exception e) {\r
+                    logger.error("Exception thrown while sleeping", e);\r
+                }\r
 \r
             }\r
         } catch (Exception e) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_SOCKET, e);\r
+            logger.error("Error while processing socket messages", e);\r
         }\r
 \r
         // connection closed by server\r
         // COPSDebug.out(getClass().getName(),"Connection closed by client");\r
         try {\r
             _sock.close();\r
-        } catch (IOException e) {};\r
+        } catch (IOException e) {\r
+            logger.error("Error closing socket", e);\r
+        }\r
 \r
         // Notify all Request State Managers\r
         try {\r
             notifyCloseAllReqStateMan();\r
-        } catch (COPSPdpException e) {};\r
+        } catch (COPSPdpException e) {\r
+            logger.error("Error closing state managers");\r
+        }\r
     }\r
 \r
     /**\r
@@ -316,12 +297,13 @@ public class COPSPdpConnection implements Runnable {
         try {\r
             // Support\r
             if (cMsg.getIntegrity() != null) {\r
-                COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOSUPPORTED,\r
-                              "Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
+                logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
             }\r
 \r
             conn.close();\r
-        } catch (Exception unae) { };\r
+        } catch (Exception unae) {\r
+            logger.error("Unexpected exception closing connection", unae);\r
+        }\r
     }\r
 \r
     /**\r
@@ -351,12 +333,12 @@ public class COPSPdpConnection implements Runnable {
         try {\r
             // Support\r
             if (cMsg.getIntegrity() != null) {\r
-                COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOSUPPORTED,\r
-                              "Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
+                logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
             }\r
-\r
             kaMsg.writeData(conn);\r
-        } catch (Exception unae) { };\r
+        } catch (Exception unae) {\r
+            logger.error("Unexpected exception while writing COPS data", unae);\r
+        }\r
     }\r
 \r
     /**\r
@@ -381,8 +363,7 @@ public class COPSPdpConnection implements Runnable {
 \r
         // Support\r
         if (cMsg.getIntegrity() != null) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOSUPPORTED,\r
-                          "Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
+            logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
         }\r
 \r
         // Delete clientHandler\r
@@ -391,9 +372,9 @@ public class COPSPdpConnection implements Runnable {
             //  cMsg.getClientHandle().getId().getData());\r
         }\r
 \r
-        COPSPdpReqStateMan man = (COPSPdpReqStateMan) _managerMap.get(cMsg.getClientHandle().getId().str());\r
+        COPSPdpReqStateMan man = _managerMap.get(cMsg.getClientHandle().getId().str());\r
         if (man == null) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOEXPECTEDMSG);\r
+            logger.warn("No state manager found with ID - " + cMsg.getClientHandle().getId().str());\r
         } else {\r
             man.processDeleteRequestState(cMsg);\r
         }\r
@@ -427,8 +408,7 @@ public class COPSPdpConnection implements Runnable {
 \r
         // Support\r
         if (reqMsg.getIntegrity() != null) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOSUPPORTED,\r
-                          "Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
+            logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
         }\r
 \r
         COPSPdpReqStateMan man;\r
@@ -471,13 +451,12 @@ public class COPSPdpConnection implements Runnable {
 \r
         // Support\r
         if (repMsg.getIntegrity() != null) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOSUPPORTED,\r
-                          "Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
+            logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
         }\r
 \r
         COPSPdpReqStateMan man = (COPSPdpReqStateMan) _managerMap.get(repMsg.getClientHandle().getId().str());\r
         if (man == null) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOEXPECTEDMSG);\r
+            logger.warn("No state manager found with ID - " + repMsg.getClientHandle().getId().str());\r
         } else {\r
             man.processReport(repMsg);\r
         }\r
@@ -498,13 +477,12 @@ public class COPSPdpConnection implements Runnable {
 \r
         // Support\r
         if (cMsg.getIntegrity() != null) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOSUPPORTED,\r
-                          "Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
+            logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
         }\r
 \r
         COPSPdpReqStateMan man = (COPSPdpReqStateMan) _managerMap.get(cMsg.getClientHandle().getId().str());\r
         if (man == null) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOEXPECTEDMSG);\r
+            logger.warn("No state manager found with ID - " + cMsg.getClientHandle().getId().str());\r
         } else {\r
             man.processSyncComplete(cMsg);\r
         }\r
@@ -515,39 +493,21 @@ public class COPSPdpConnection implements Runnable {
      * @throws COPSException\r
      * @throws COPSPdpException\r
      */\r
-    protected void syncAllRequestState()\r
-    throws COPSException, COPSPdpException {\r
-        if (_managerMap.size() > 0) {\r
-            for (Enumeration e = _managerMap.keys() ; e.hasMoreElements() ;) {\r
-                String handle = (String) e.nextElement();\r
-                COPSPdpReqStateMan man = (COPSPdpReqStateMan) _managerMap.get(handle);\r
-\r
-                man.syncRequestState();\r
-            }\r
+    protected void syncAllRequestState() throws COPSException, COPSPdpException {\r
+        for (final COPSPdpReqStateMan man : _managerMap.values()) {\r
+            man.syncRequestState();\r
         }\r
     }\r
 \r
-    private void notifyCloseAllReqStateMan()\r
-    throws COPSPdpException {\r
-        if (_managerMap.size() > 0) {\r
-            for (Enumeration e = _managerMap.keys() ; e.hasMoreElements() ;) {\r
-                String handle = (String) e.nextElement();\r
-                COPSPdpReqStateMan man = (COPSPdpReqStateMan) _managerMap.get(handle);\r
-\r
-                man.processClosedConnection(_error);\r
-            }\r
+    private void notifyCloseAllReqStateMan() throws COPSPdpException {\r
+        for (final COPSPdpReqStateMan man : _managerMap.values()) {\r
+            man.processClosedConnection(_error);\r
         }\r
     }\r
 \r
-    private void notifyNoKAAllReqStateMan()\r
-    throws COPSPdpException {\r
-        if (_managerMap.size() > 0) {\r
-            for (Enumeration e = _managerMap.keys() ; e.hasMoreElements() ;) {\r
-                String handle = (String) e.nextElement();\r
-                COPSPdpReqStateMan man = (COPSPdpReqStateMan) _managerMap.get(handle);\r
-\r
-                man.processNoKAConnection();\r
-            }\r
+    private void notifyNoKAAllReqStateMan() throws COPSPdpException {\r
+        for (final COPSPdpReqStateMan man : _managerMap.values()) {\r
+            man.processNoKAConnection();\r
         }\r
     }\r
 \r