From: Steven Pisarski Date: Thu, 16 Apr 2015 21:38:44 +0000 (-0600) Subject: Replaced use of logger abstraction COPSDebug.java to having this class log directly... X-Git-Tag: release/lithium~27^2~2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F18493%2F1;hp=eabacbc2e102bbd495a60e2df0bf66b93eceb6b5;p=packetcable.git Replaced use of logger abstraction COPSDebug.java to having this class log directly to it's own logger as well as fixing several compiler warnings. Change-Id: I307b4ddd5b1a1d12a9baf7465caf5a10214ecb98 Signed-off-by: Steven Pisarski --- diff --git a/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java b/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java index b6043c6..be17440 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java +++ b/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java @@ -6,29 +6,24 @@ package org.umu.cops.prpdp; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.umu.cops.stack.*; + import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; -import java.util.Enumeration; import java.util.Hashtable; - -import org.umu.cops.common.COPSDebug; -import org.umu.cops.stack.COPSAcctTimer; -import org.umu.cops.stack.COPSClientAcceptMsg; -import org.umu.cops.stack.COPSClientCloseMsg; -import org.umu.cops.stack.COPSClientOpenMsg; -import org.umu.cops.stack.COPSError; -import org.umu.cops.stack.COPSException; -import org.umu.cops.stack.COPSHeader; -import org.umu.cops.stack.COPSKATimer; -import org.umu.cops.stack.COPSMsg; -import org.umu.cops.stack.COPSPepId; -import org.umu.cops.stack.COPSTransceiver; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Core PDP agent for provisioning */ public class COPSPdpAgent extends Thread { + + public final static Logger logger = LoggerFactory.getLogger(COPSPdpAgent.class); + /** Well-known port for COPS */ public static final int WELL_KNOWN_PDP_PORT = 3288; /** Default keep-alive timer value (secs) */ @@ -36,11 +31,6 @@ public class COPSPdpAgent extends Thread { /** Default accounting timer value (secs) */ public static final short ACCT_TIMER_VALUE = 0; - /** - PDP host IP - */ - private ServerSocket _serverSocket; - /** PDP host port */ @@ -64,7 +54,7 @@ public class COPSPdpAgent extends Thread { /** Maps a PEP-ID to a connection */ - private Hashtable _connectionMap; + private final Map _connectionMap; // map < String(PEPID), COPSPdpConnection > ConnectionMap; /** @@ -84,7 +74,7 @@ public class COPSPdpAgent extends Thread { _acctTimer = ACCT_TIMER_VALUE; _clientType = clientType; - _connectionMap = new Hashtable(40); + _connectionMap = new ConcurrentHashMap<>(); _process = process; } @@ -102,7 +92,7 @@ public class COPSPdpAgent extends Thread { _acctTimer = ACCT_TIMER_VALUE; _clientType = clientType; - _connectionMap = new Hashtable(40); + _connectionMap = new ConcurrentHashMap<>(); _process = process; } @@ -138,20 +128,12 @@ public class COPSPdpAgent extends Thread { return _acctTimer; } - /** - * Gets the PEPs connected to this PDP - * @return An Enumeration of all connected PEPs - */ - public Enumeration getConnectedPEPIds() { - return _connectionMap.keys(); - } - /** * Gets the connection map * @return A Hashtable holding the connection map */ public Hashtable getConnectionMap() { - return _connectionMap; + return new Hashtable(_connectionMap); } /** @@ -172,7 +154,7 @@ public class COPSPdpAgent extends Thread { public void disconnect (String pepID, COPSError error) throws COPSException, IOException { - COPSPdpConnection pdpConn = (COPSPdpConnection) _connectionMap.get(pepID); + COPSPdpConnection pdpConn = _connectionMap.get(pepID); COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_CC, _clientType); COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(); @@ -182,7 +164,6 @@ public class COPSPdpAgent extends Thread { closeMsg.writeData(pdpConn.getSocket()); pdpConn.close(); - pdpConn = null; } /** @@ -194,7 +175,7 @@ public class COPSPdpAgent extends Thread { public void sync (String pepID) throws COPSException, COPSPdpException { - COPSPdpConnection pdpConn = (COPSPdpConnection) _connectionMap.get(pepID); + COPSPdpConnection pdpConn = _connectionMap.get(pepID); pdpConn.syncAllRequestState(); } @@ -212,7 +193,7 @@ public class COPSPdpAgent extends Thread { */ public void run() { try { - _serverSocket = new ServerSocket (_serverPort); + final ServerSocket serverSocket = new ServerSocket (_serverPort); //Loop through for Incoming messages @@ -220,7 +201,7 @@ public class COPSPdpAgent extends Thread { while (true) { // Wait for an incoming connection from a PEP - Socket socket = _serverSocket.accept(); + Socket socket = serverSocket.accept(); // COPSDebug.out(getClass().getName(),"New connection accepted " + // socket.getInetAddress() + @@ -235,19 +216,22 @@ public class COPSPdpAgent extends Thread { // COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOEXPECTEDMSG); try { socket.close(); - } catch (Exception ex) {}; + } catch (Exception ex) { + logger.error("Error closing socket", ex); + } } } catch (Exception e) { // COPSException, IOException // COPSDebug.err(getClass().getName(), COPSDebug.ERROR_EXCEPTION, // "(" + socket.getInetAddress() + ":" + socket.getPort() + ")", e); try { socket.close(); - } catch (Exception ex) {}; + } catch (Exception ex) { + logger.error("Error closing socket", ex); + } } } } catch (IOException e) { - COPSDebug.err(getClass().getName(), COPSDebug.ERROR_SOCKET, e); - return; + logger.error("Error caught while processing socket messages", e); } } @@ -273,7 +257,9 @@ public class COPSPdpAgent extends Thread { closeMsg.add(err); try { closeMsg.writeData(conn); - } catch (IOException unae) {} + } catch (IOException unae) { + logger.error("Error writing COPS data", unae); + } throw new COPSException("Unsupported client type"); } @@ -288,7 +274,9 @@ public class COPSPdpAgent extends Thread { closeMsg.add(err); try { closeMsg.writeData(conn); - } catch (IOException unae) {} + } catch (IOException unae) { + logger.error("Error writing close message", unae); + } throw new COPSException("Mandatory COPS object missing (PEPId)"); } @@ -306,7 +294,9 @@ public class COPSPdpAgent extends Thread { closeMsg.add(err); try { closeMsg.writeData(conn); - } catch (IOException unae) {} + } catch (IOException unae) { + logger.error("Error writing close message", unae); + } throw new COPSException("Unsupported objects (ClientSI, PdpAddress, Integrity)"); }