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

index 354bf76e742a8d386557fd6aab8217214cfd7ed0..d701d8fd9a720cc59ab84ab8ccfe7add976a17e4 100644 (file)
@@ -1,28 +1,22 @@
 package org.umu.cops.ospdp;\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 outsourcing.\r
  */\r
 public class COPSPdpOSAgent extends Thread {\r
+\r
+    public final static Logger logger = LoggerFactory.getLogger(COPSPdpOSAgent.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
@@ -30,11 +24,6 @@ public class COPSPdpOSAgent 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
@@ -58,7 +47,7 @@ public class COPSPdpOSAgent extends Thread {
     /**\r
         Maps a PEP-ID to a connection\r
      */\r
-    private Hashtable _connectionMap;\r
+    private final Map<String, COPSPdpOSConnection> _connectionMap;\r
     // map < String(PEPID), COPSPdpOSConnection > ConnectionMap;\r
 \r
     /**\r
@@ -78,7 +67,7 @@ public class COPSPdpOSAgent 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
@@ -96,7 +85,7 @@ public class COPSPdpOSAgent 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
@@ -132,22 +121,6 @@ public class COPSPdpOSAgent 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
-    }\r
-\r
     /**\r
      * Gets the client-type\r
      * @return   The client-type\r
@@ -164,7 +137,7 @@ public class COPSPdpOSAgent extends Thread {
      * @throws IOException\r
      */\r
     public void disconnect (String pepID, COPSError error) throws COPSException, IOException {\r
-        COPSPdpOSConnection pdpConn = (COPSPdpOSConnection) _connectionMap.get(pepID);\r
+        COPSPdpOSConnection pdpConn = _connectionMap.get(pepID);\r
 \r
         COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_CC, _clientType);\r
         COPSClientCloseMsg closeMsg = new COPSClientCloseMsg();\r
@@ -174,7 +147,6 @@ public class COPSPdpOSAgent extends Thread {
 \r
         closeMsg.writeData(pdpConn.getSocket());\r
         pdpConn.close();\r
-        pdpConn = null;\r
     }\r
 \r
     /**\r
@@ -184,7 +156,7 @@ public class COPSPdpOSAgent extends Thread {
      * @throws COPSPdpException\r
      */\r
     public void sync(String pepID) throws COPSException, COPSPdpException {\r
-        COPSPdpOSConnection pdpConn = (COPSPdpOSConnection) _connectionMap.get(pepID);\r
+        COPSPdpOSConnection pdpConn = _connectionMap.get(pepID);\r
         pdpConn.syncAllRequestState();\r
     }\r
 \r
@@ -201,14 +173,14 @@ public class COPSPdpOSAgent 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
             // server infinite loop\r
             while (true) {\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
@@ -223,19 +195,22 @@ public class COPSPdpOSAgent 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 processing socket messages", e);\r
         }\r
     }\r
 \r
@@ -260,7 +235,9 @@ public class COPSPdpOSAgent extends Thread {
             closeMsg.add(err);\r
             try {\r
                 closeMsg.writeData(conn);\r
-            } catch (IOException unae) {}\r
+            } catch (IOException unae) {\r
+                logger.error("Error writing data", unae);\r
+            }\r
 \r
             throw new COPSException("Unsupported client type");\r
         }\r
@@ -275,7 +252,9 @@ public class COPSPdpOSAgent extends Thread {
             closeMsg.add(err);\r
             try {\r
                 closeMsg.writeData(conn);\r
-            } catch (IOException unae) {}\r
+            } catch (IOException unae) {\r
+                logger.error("Error writing data", unae);\r
+            }\r
 \r
             throw new COPSException("Mandatory COPS object missing (PEPId)");\r
         }\r
@@ -293,7 +272,9 @@ public class COPSPdpOSAgent extends Thread {
             closeMsg.add(err);\r
             try {\r
                 closeMsg.writeData(conn);\r
-            } catch (IOException unae) {}\r
+            } catch (IOException unae) {\r
+                logger.error("Error writing data", unae);\r
+            }\r
 \r
             throw new COPSException("Unsupported objects (ClientSI, PdpAddress, Integrity)");\r
         }\r