Class AcceptorNioServer

All Implemented Interfaces:
Runnable

public class AcceptorNioServer extends StatelessNioServer<AcceptorContext>
Instances of this class serve task execution requests to the JPPF nodes.
Author:
Laurent Cohen
  • Field Details

    • ports

      protected int[] ports
      The ports this server is listening to.
    • sslPorts

      protected int[] sslPorts
      The SSL ports this server is listening to.
    • servers

      protected final Map<Integer,ServerSocketChannel> servers
      List of opened server socket channels.
  • Constructor Details

    • AcceptorNioServer

      public AcceptorNioServer(int[] ports, int[] sslPorts, JPPFStatistics stats, TypedProperties configuration) throws Exception
      Initialize this server with the specified port numbers.
      Parameters:
      ports - the ports this socket server is listening to.
      sslPorts - the SSL ports this socket server is listening to.
      stats - the statsistics to update, if any.
      configuration - the JPPF configuration to use.
      Throws:
      Exception - if the underlying server socket can't be opened.
  • Method Details

    • init

      protected void init() throws Exception
      Initialize the underlying server sockets.
      Overrides:
      init in class StatelessNioServer<AcceptorContext>
      Throws:
      Exception - if any error occurs while initializing the server sockets.
    • handleRead

      protected void handleRead(SelectionKey key) throws Exception
      Description copied from class: StatelessNioServer
      Called when a selection key is selected and readable.
      Overrides:
      handleRead in class StatelessNioServer<AcceptorContext>
      Parameters:
      key - the key to handle.
      Throws:
      Exception - if any error occurs.
    • handleWrite

      protected void handleWrite(SelectionKey key) throws Exception
      Description copied from class: StatelessNioServer
      Called when a selection key is selected and writable.
      Overrides:
      handleWrite in class StatelessNioServer<AcceptorContext>
      Parameters:
      key - the key to handle.
      Throws:
      Exception - if any error occurs.
    • handleSelectionException

      protected void handleSelectionException(SelectionKey key, Exception e)
      Description copied from class: StatelessNioServer
      Called when a selection key is writable.
      Specified by:
      handleSelectionException in class StatelessNioServer<AcceptorContext>
      Parameters:
      key - the key to handle.
      e - the exception to handle.
    • doAccept

      protected void doAccept(SelectionKey key)
      Description copied from class: NioServer
      accept the incoming connection. It accept and put it in a state to define what type of peer is.
      Overrides:
      doAccept in class NioServer
      Parameters:
      key - the selection key that represents the channel's registration with the selector.
    • accept

      public void accept(ServerSocketChannel serverSocketChannel, SocketChannel channel, SSLHandler sslHandler, boolean ssl, boolean peer, Object... params) throws Exception
      Register an incoming connection with this server's selector. The channel is registered with an empty set of initial interest operations, which means a call to the corresponding SelectionKey's interestOps() method will return 0.
      Specified by:
      accept in class NioServer
      Parameters:
      serverSocketChannel - the server socket channel accepting the connection.
      channel - the socket channel representing the connection.
      sslHandler - an sslEngine eventually passed on from a different server.
      ssl - specifies whether an SSLHandler should be initialized for the channel.
      peer - specifiies whether the channel is for a peer driver.
      params - optional parameters.
      Throws:
      Exception - if any error occurs.
    • createNioContext

      public NioContext createNioContext(Object... params)
      Description copied from class: NioServer
      Define a context for a newly created channel.
      Specified by:
      createNioContext in class NioServer
      Parameters:
      params - optional parameters.
      Returns:
      an NioContext instance.
    • addServer

      public boolean addServer(int portToInit, boolean ssl, Map<String,?> env, boolean retryOnException) throws Exception
      Description copied from class: NioServer
      Initialize the underlying server sockets for the spcified array of ports. This implementation throws a JPPFUnsupportedOperationException, it should be overriden by subclasses for a different outcome.
      Overrides:
      addServer in class NioServer
      Parameters:
      portToInit - the array of ports to initiialize.
      ssl - true if the server sockets should be initialized with SSL enabled, false otherwise.
      env - optional map of parameters to associate with the server socket channel.
      retryOnException - whether to retry if an exception occurs when binding the server.
      Returns:
      true ifd a new server was created, false otherwxise.
      Throws:
      Exception - if any error occurs while initializing the server sockets.
    • removeServer

      public void removeServer(int port) throws IOException
      Remove the server identified by the local port it is listening to.
      Overrides:
      removeServer in class NioServer
      Parameters:
      port - the port the sever is listening to.
      Throws:
      IOException - if any error occurs closing the specified server socket channel.
    • removeAllConnections

      public void removeAllConnections()
      Description copied from class: NioServer
      Close and remove all connections accepted by this server.
      Overrides:
      removeAllConnections in class NioServer
    • getPorts

      public int[] getPorts()
      Get the ports this server is listening to.
      Returns:
      an array of int values.
    • getSSLPorts

      public int[] getSSLPorts()
      Get the SSL ports this server is listening to.
      Returns:
      an array of int values.
    • getStats

      public JPPFStatistics getStats()
      Returns:
      the statistics to update, if any.
    • initReaderAndWriter

      protected void initReaderAndWriter()
      Description copied from class: StatelessNioServer
      Initialize the message reader and writer.
      Specified by:
      initReaderAndWriter in class StatelessNioServer<AcceptorContext>
    • initNioHandlers

      protected void initNioHandlers()
      Overrides:
      initNioHandlers in class StatelessNioServer<AcceptorContext>
    • end

      public void end()
      Description copied from class: NioServer
      Close the underlying server socket and stop this socket server.
      Overrides:
      end in class NioServer