Class Service
java.lang.Object
org.processmining.framework.util.socket.Service
This is a wrapper for a server socket. It has an arbitrary number of
registered ServiceHandler-s. Whenever a client connects to the service, all
registered handlers are notified. Each handler can further communucate with
the client.
- Author:
- christian
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
A simple class that enables notification of ServiceHandler-s in a new thread. -
Field Summary
-
Constructor Summary
ConstructorDescriptionService
(int port) The only constructor, which simply sets a port to be used by the server socket. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addServiceHandler
(ServiceHandler handler) Registers a new handler.int
getPort()
Get the server port.protected void
handleConnection
(Socket socket, ServiceEnvironment environment, Executor executor) Notifies all registered handlers about every new client connection.void
removeServiceHandler
(ServiceHandler handler) Unregister the handler.void
start
(ServiceEnvironment environment, Executor executor) Opens the server socked on the given port.
-
Field Details
-
serverSocket
-
handlers
-
-
Constructor Details
-
Service
public Service(int port) The only constructor, which simply sets a port to be used by the server socket. Note that the constructor does not open the server socket.- Parameters:
port
- for the server socket.
-
-
Method Details
-
addServiceHandler
Registers a new handler. From this moment, the handler will be notified about new client connections.- Parameters:
handler
- to be registered.
-
removeServiceHandler
Unregister the handler. From this moment, the handler will not longer be notified about new client connections.- Parameters:
handler
- to be unregistered.
-
start
Opens the server socked on the given port. Periodically notifies the environment that the service is alive. Notifies all registered handlers about every new client connection. It keeps on listening on the socket until the environment is canceled, upon which the socket is closed.- Parameters:
environment
- is the environment of this service.executor
- enables notification of handlers in a new thread.- Throws:
IOException
-
handleConnection
Notifies all registered handlers about every new client connection.- Parameters:
socket
- is the client socket.environment
- is the environment of this service.executor
- enables notification of handlers in a new thread.
-
getPort
public int getPort()Get the server port.- Returns:
- the port.
-