\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
/** 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
/**\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
_acctTimer = ACCT_TIMER_VALUE;\r
\r
_clientType = clientType;\r
- _connectionMap = new Hashtable(40);\r
+ _connectionMap = new ConcurrentHashMap<>();\r
_process = process;\r
}\r
\r
_acctTimer = ACCT_TIMER_VALUE;\r
\r
_clientType = clientType;\r
- _connectionMap = new Hashtable(40);\r
+ _connectionMap = new ConcurrentHashMap<>();\r
_process = process;\r
}\r
\r
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
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
\r
closeMsg.writeData(pdpConn.getSocket());\r
pdpConn.close();\r
- pdpConn = null;\r
}\r
\r
/**\r
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
*/\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
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
// 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
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
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
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