com.javageeks.gjas.services
Class SocketServer
java.lang.Object
|
+--com.javageeks.gjas.services.ThreadedServer
|
+--com.javageeks.gjas.services.SocketServer
- All Implemented Interfaces:
- java.io.Serializable, Service
- Direct Known Subclasses:
- ConnectionManager, HeartbeatService, RemoteObjectFactoryService, RemoteStorageService, SocketControlService
- public abstract class SocketServer
- extends ThreadedServer
SocketServer: abstract base class refactoring common behavior when
writing a service to handle clients via sockets. Derived Services
are expected to override serve
and provide a port number
to use as our server socket either via the setPort
method or via a "-port:##" argument in the arguments to
start
.
- See Also:
- Serialized Form
Constructor Summary |
SocketServer()
Constructor, taking no arguments. |
SocketServer(int port)
Constructor, taking the port number on which to listen as the
sole argument. |
Method Summary |
ConfigProperties |
getConfigInfo()
Return the Properties configuration information |
int |
getPort()
Return the port we accept clients on. |
abstract void |
serve(java.net.Socket socket)
Derived services must override this method. |
void |
setConfigInfo(ConfigProperties props)
Set the Properties configuration information |
void |
setPort(int newPort)
Set the port number we plan to accept clients on; has no effect
after the service is started. |
void |
start()
Start the SocketServer |
void |
stop()
Stop the Service. |
Methods inherited from class com.javageeks.gjas.services.ThreadedServer |
getInstanceID, getState, getThread, isPaused, kill, pause, resume, setRunnable, setState, setThread, shouldStop |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PORT_PROP
protected static final java.lang.String PORT_PROP
TIMEOUT_PROP
protected static final java.lang.String TIMEOUT_PROP
m_serverSocket
protected java.net.ServerSocket m_serverSocket
SocketServer
public SocketServer()
- Constructor, taking no arguments. The port number on which to
listen must be specified (either through the args argument to
start or via setPort).
SocketServer
public SocketServer(int port)
- Constructor, taking the port number on which to listen as the
sole argument.
start
public void start()
throws java.lang.Exception
- Start the SocketServer
- Overrides:
start
in class ThreadedServer
stop
public void stop()
throws java.lang.Exception
- Description copied from interface:
Service
- Stop the Service.
- Overrides:
stop
in class ThreadedServer
getConfigInfo
public ConfigProperties getConfigInfo()
- Description copied from interface:
Service
- Return the Properties configuration information
setConfigInfo
public void setConfigInfo(ConfigProperties props)
- Description copied from interface:
Service
- Set the Properties configuration information
getPort
public int getPort()
- Return the port we accept clients on.
setPort
public void setPort(int newPort)
- Set the port number we plan to accept clients on; has no effect
after the service is started.
serve
public abstract void serve(java.net.Socket socket)
throws java.lang.Exception
- Derived services must override this method. Once a client has
connected to us, this method is called to "do the work" of
handling the connection.