Class BaseServer

java.lang.Object
org.apache.vinci.transport.BaseServer
Direct Known Subclasses:
VinciServer

public class BaseServer extends Object
Class for running VinciServables in the Vinci framework. This implementation supports multiple concurrent clients (in a Thread per client manner). Creating a service typically requires defining implementing a VinciServable which is passed to this class to service requests. This class can be used independently of VNS. For VNS-enhanced serving, use the VinciServer. This class is designed to be extensible. For example you can extend to provide new Runnable objects that are used to handle requests in the appropriate fashion. You can also override configure socket to install SSL-supporting server sockets, and so on...
  • Constructor Details

    • BaseServer

      public BaseServer(VinciServable my_servable)
      Create a new BaseServer that will delegate requests to the provided servable.
      Parameters:
      my_servable - The servable object implementing the service.
  • Method Details

    • getServable

      public VinciServable getServable()
      Get the servable object being used by this server.
      Returns:
      -
    • setSocketTimeout

      public void setSocketTimeout(int millis) throws IOException
      This method is used to override the default timeout value of one minute. You can provide "0" for "never timeout" but this is not recommended, as in some cases threads will end up forever blocking for input, eventually causing the threadpool to max out and block all pending requests.
      Parameters:
      millis - The socket timeout value in milliseconds.
      Throws:
      IOException - -
    • setThreadPoolSize

      public void setThreadPoolSize(int initial, int max)
      Set the intitial and maximum size of the threadpool used by this server. This should be called before serving starts otherwise it has no effect.
      Parameters:
      initial - -
      max - -
    • startServing

      public void startServing(int port) throws IOException
      Asynchronously start serving requests. If this method returns without throwing an exception, then another thread has been successfully launched to begin serving requests.
      Parameters:
      port - The port on which to listen for requests.
      Throws:
      IOException - Thrown if there was some problem with the server socket.
      Since:
      2.0.15
    • serve

      public void serve(int port) throws IOException
      Serve requests, blocking until a clean shutdown is triggered.
      Parameters:
      port - The port on which to listen for requests.
      Throws:
      IOException - Thrown if there was some problem with the server socket.
    • getServerSocket

      protected ServerSocket getServerSocket()
      Get the server socket that this server uses to listen for requests.
      Returns:
      The server's server socket
    • createServerSocket

      protected ServerSocket createServerSocket(int port) throws IOException
      Create the server socket used to listen for requests. This method can be overridden to provide non-standard server sockets, such as those supporting SSL, those requiring special configuration/initialization, etc.
      Parameters:
      port - The port which is to be listened to by the created socket.
      Returns:
      The server socket to be used by this server for accepting requests.
      Throws:
      IOException - -
    • handleRequests

      protected void handleRequests()
      Enter the server socket accept() loop. Loop terminates when shutdown shutdownServing() method is called.
    • shutdownServing

      public void shutdownServing()
      Cause the serve() method to terminate.
    • getRunnable

      protected Runnable getRunnable(Socket client)
      Get a runnable object to run within a pooled thread that will handle the request.
      Parameters:
      client - -
      Returns:
      -
    • handleRequest

      protected void handleRequest(Socket client)
      Initialize a new socket connection.
      Parameters:
      client - -
    • cleanExit

      protected void cleanExit()
      Cleanly shut down this server. Called when handleRequests completes the accept loop.
    • eval

      public Transportable eval(Transportable in, KeyValuePair header)
      This function is a callback for the (Base/Vinci)ServerRunnable. It invokes the eval method of the appropriate VinciServable.
      Parameters:
      in - -
      header - -
      Returns:
      -
    • makeTransportable

      public Transportable makeTransportable()
      This is another callback for the (Base/Vinci)ServerRunnable that creates the document to be populated by the service with the request response.
      Returns:
      The document the service will populate to create the request response.