java.lang.Object
org.processmining.framework.util.socket.Service

public class Service extends Object
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
  • Field Details

  • 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

      public void addServiceHandler(ServiceHandler handler)
      Registers a new handler. From this moment, the handler will be notified about new client connections.
      Parameters:
      handler - to be registered.
    • removeServiceHandler

      public void removeServiceHandler(ServiceHandler handler)
      Unregister the handler. From this moment, the handler will not longer be notified about new client connections.
      Parameters:
      handler - to be unregistered.
    • start

      public void start(ServiceEnvironment environment, Executor executor) throws IOException
      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

      protected void handleConnection(Socket socket, ServiceEnvironment environment, Executor executor)
      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.