*/
package org.pcmm.rcd.impl;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.concurrent.Executors;
-
import org.pcmm.PCMMConstants;
import org.pcmm.PCMMProperties;
import org.pcmm.concurrent.IWorkerPool;
import org.pcmm.concurrent.impl.WorkerPool;
-// import org.junit.Assert;
import org.pcmm.messages.impl.MessageFactory;
import org.pcmm.rcd.IPCMMServer;
import org.pcmm.state.IState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.umu.cops.stack.COPSHeader;
+import org.umu.cops.stack.COPSHeader.OPCode;
import org.umu.cops.stack.COPSMsg;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.Executors;
+
+// import org.junit.Assert;
+
/*
* (non-Javadoc)
*
IWorkerPool pool;
+ /**
+ * Constructor to use the port number contained within the PCMMProperties static object
+ */
protected AbstractPCMMServer() {
this(PCMMProperties.get(PCMMConstants.PCMM_PORT, Integer.class));
}
+ /**
+ * Constructor for starting the server to a pre-defined port number. When 0 is used, the server socket will
+ * assign one for you. To determine which port is being used, call getPort() after startServer() is called.
+ * @param port - the port number on which to start the server
+ */
protected AbstractPCMMServer(int port) {
// XXX - Assert.assertTrue(port >= 0 && port <= 65535);
this.port = port;
return;
try {
serverSocket = new ServerSocket(port);
+ port = serverSocket.getLocalPort();
logger.info("Server started and listening on port :" + port);
} catch (IOException e) {
logger.error(e.getMessage());
* This client is used to handle requests from within the Application
* Manager
*
- * @param socket
+ * @param socket - the connection to the PCMM server
* @return client handler
*/
protected abstract IPCMMClientHandler getPCMMClientHandler(Socket socket);
return null;
}
- /**
- * @return the serverSocket
- */
- public ServerSocket getServerSocket() {
- return serverSocket;
- }
-
- /**
- * @param serverSocket
- * the serverSocket to set
- */
- public void setServerSocket(ServerSocket serverSocket) {
- this.serverSocket = serverSocket;
- }
-
/**
* @return the port
*/
*/
// if (getSocket() != null)
// handlersPool.remove(getSocket());
- COPSMsg message = MessageFactory.getInstance().create(COPSHeader.COPS_OP_CC);
+ COPSMsg message = MessageFactory.getInstance().create(OPCode.CC);
sendRequest(message);
return super.disconnect();
}