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

index b6043c60ab19c58f150751fca575ece68c36b142..be174403844701cc5d3c7803d58fd27ca90dfd18 100644 (file)
@@ -6,29 +6,24 @@
 \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.ServerSocket;\r
 import java.net.Socket;\r
-import java.util.Enumeration;\r
 import java.util.Hashtable;\r
-\r
-import org.umu.cops.common.COPSDebug;\r
-import org.umu.cops.stack.COPSAcctTimer;\r
-import org.umu.cops.stack.COPSClientAcceptMsg;\r
-import org.umu.cops.stack.COPSClientCloseMsg;\r
-import org.umu.cops.stack.COPSClientOpenMsg;\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.COPSKATimer;\r
-import org.umu.cops.stack.COPSMsg;\r
-import org.umu.cops.stack.COPSPepId;\r
-import org.umu.cops.stack.COPSTransceiver;\r
+import java.util.Map;\r
+import java.util.concurrent.ConcurrentHashMap;\r
 \r
 /**\r
  * Core PDP agent for provisioning\r
  */\r
 public class COPSPdpAgent extends Thread {\r
+\r
+    public final static Logger logger = LoggerFactory.getLogger(COPSPdpAgent.class);\r
+\r
     /** Well-known port for COPS */\r
     public static final int WELL_KNOWN_PDP_PORT = 3288;\r
     /** Default keep-alive timer value (secs) */\r
@@ -36,11 +31,6 @@ public class COPSPdpAgent extends Thread {
     /** Default accounting timer value (secs) */\r
     public static final short ACCT_TIMER_VALUE = 0;\r
 \r
-    /**\r
-        PDP host IP\r
-     */\r
-    private ServerSocket _serverSocket;\r
-\r
     /**\r
         PDP host port\r
      */\r
@@ -64,7 +54,7 @@ public class COPSPdpAgent extends Thread {
     /**\r
         Maps a PEP-ID to a connection\r
      */\r
-    private Hashtable _connectionMap;\r
+    private final Map<String, COPSPdpConnection> _connectionMap;\r
     // map < String(PEPID), COPSPdpConnection > ConnectionMap;\r
 \r
     /**\r
@@ -84,7 +74,7 @@ public class COPSPdpAgent extends Thread {
         _acctTimer = ACCT_TIMER_VALUE;\r
 \r
         _clientType = clientType;\r
-        _connectionMap = new Hashtable(40);\r
+        _connectionMap = new ConcurrentHashMap<>();\r
         _process = process;\r
     }\r
 \r
@@ -102,7 +92,7 @@ public class COPSPdpAgent extends Thread {
         _acctTimer = ACCT_TIMER_VALUE;\r
 \r
         _clientType = clientType;\r
-        _connectionMap = new Hashtable(40);\r
+        _connectionMap = new ConcurrentHashMap<>();\r
         _process = process;\r
     }\r
 \r
@@ -138,20 +128,12 @@ public class COPSPdpAgent extends Thread {
         return _acctTimer;\r
     }\r
 \r
-    /**\r
-     * Gets the PEPs connected to this PDP\r
-     * @return   An <tt>Enumeration</tt> of all connected PEPs\r
-     */\r
-    public Enumeration getConnectedPEPIds() {\r
-        return _connectionMap.keys();\r
-    }\r
-\r
     /**\r
      * Gets the connection map\r
      * @return   A <tt>Hashtable</tt> holding the connection map\r
      */\r
     public Hashtable getConnectionMap() {\r
-        return _connectionMap;\r
+        return new Hashtable(_connectionMap);\r
     }\r
 \r
     /**\r
@@ -172,7 +154,7 @@ public class COPSPdpAgent extends Thread {
     public void disconnect (String pepID, COPSError error)\r
     throws COPSException, IOException {\r
 \r
-        COPSPdpConnection pdpConn = (COPSPdpConnection) _connectionMap.get(pepID);\r
+        COPSPdpConnection pdpConn = _connectionMap.get(pepID);\r
 \r
         COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_CC, _clientType);\r
         COPSClientCloseMsg closeMsg = new COPSClientCloseMsg();\r
@@ -182,7 +164,6 @@ public class COPSPdpAgent extends Thread {
 \r
         closeMsg.writeData(pdpConn.getSocket());\r
         pdpConn.close();\r
-        pdpConn = null;\r
     }\r
 \r
     /**\r
@@ -194,7 +175,7 @@ public class COPSPdpAgent extends Thread {
     public void sync (String pepID)\r
     throws COPSException, COPSPdpException {\r
 \r
-        COPSPdpConnection pdpConn = (COPSPdpConnection) _connectionMap.get(pepID);\r
+        COPSPdpConnection pdpConn = _connectionMap.get(pepID);\r
         pdpConn.syncAllRequestState();\r
     }\r
 \r
@@ -212,7 +193,7 @@ public class COPSPdpAgent extends Thread {
      */\r
     public void run() {\r
         try {\r
-            _serverSocket = new ServerSocket (_serverPort);\r
+            final ServerSocket serverSocket = new ServerSocket (_serverPort);\r
 \r
             //Loop through for Incoming messages\r
 \r
@@ -220,7 +201,7 @@ public class COPSPdpAgent extends Thread {
             while (true) {\r
 \r
                 // Wait for an incoming connection from a PEP\r
-                Socket socket = _serverSocket.accept();\r
+                Socket socket = serverSocket.accept();\r
 \r
                 // COPSDebug.out(getClass().getName(),"New connection accepted " +\r
                 //           socket.getInetAddress() +\r
@@ -235,19 +216,22 @@ public class COPSPdpAgent extends Thread {
                         // COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOEXPECTEDMSG);\r
                         try {\r
                             socket.close();\r
-                        } catch (Exception ex) {};\r
+                        } catch (Exception ex) {\r
+                            logger.error("Error closing socket", ex);\r
+                        }\r
                     }\r
                 } catch (Exception e) { // COPSException, IOException\r
                     // COPSDebug.err(getClass().getName(), COPSDebug.ERROR_EXCEPTION,\r
                     //    "(" + socket.getInetAddress() + ":" + socket.getPort() + ")", e);\r
                     try {\r
                         socket.close();\r
-                    } catch (Exception ex) {};\r
+                    } catch (Exception ex) {\r
+                        logger.error("Error closing socket", ex);\r
+                    }\r
                 }\r
             }\r
         } catch (IOException e) {\r
-            COPSDebug.err(getClass().getName(), COPSDebug.ERROR_SOCKET, e);\r
-            return;\r
+            logger.error("Error caught while processing socket messages", e);\r
         }\r
     }\r
 \r
@@ -273,7 +257,9 @@ public class COPSPdpAgent extends Thread {
             closeMsg.add(err);\r
             try {\r
                 closeMsg.writeData(conn);\r
-            } catch (IOException unae) {}\r
+            } catch (IOException unae) {\r
+                logger.error("Error writing COPS data", unae);\r
+            }\r
 \r
             throw new COPSException("Unsupported client type");\r
         }\r
@@ -288,7 +274,9 @@ public class COPSPdpAgent extends Thread {
             closeMsg.add(err);\r
             try {\r
                 closeMsg.writeData(conn);\r
-            } catch (IOException unae) {}\r
+            } catch (IOException unae) {\r
+                logger.error("Error writing close message", unae);\r
+            }\r
 \r
             throw new COPSException("Mandatory COPS object missing (PEPId)");\r
         }\r
@@ -306,7 +294,9 @@ public class COPSPdpAgent extends Thread {
             closeMsg.add(err);\r
             try {\r
                 closeMsg.writeData(conn);\r
-            } catch (IOException unae) {}\r
+            } catch (IOException unae) {\r
+                logger.error("Error writing close message", unae);\r
+            }\r
 \r
             throw new COPSException("Unsupported objects (ClientSI, PdpAddress, Integrity)");\r
         }\r