java.lang.Object
io.deephaven.enterprise.niowrapper.sched.NullIOHandler
io.deephaven.enterprise.comm.impl.nio.Server
All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, CommServer, IOHandler

public class Server extends NullIOHandler implements CommServer
Command multiplexer and distributor. A Server provides an abstraction for multiplexing incoming Commands from a collection of peers, and for distributing outgoing Commands to those peers. Incoming commands are passed to an instance of CommandHandler. Outgoing commands are sent from the application by calling the various sendCommand() methods. A Server can also partition the processing it does into separate "services". Each service has its own CommandHandler instance, identified by a unique string provided by the application when it registers the handler. Each client is required to identify the service with which it communicates by sending an initial String as the first object on its stream when it establishes the connection. Then, an incoming message from a client is passed to the CommandHandler for the service it specified on connection. Outgoing messages are targeted to a specific service by the serviceID argument to the sendCommand() methods. A command can be broadcast to all services by specifying null for the serviceId. Created by IntelliJ IDEA. User: jrauser Date: Feb 16, 2007 Time: 11:14:31 PM To change this template use File | Settings | File Templates.
  • Field Details

    • sched

      protected final Scheduler sched
      the NIO scheduler
    • name

      protected final String name
      the name of this server
    • log

      protected com.fishlib.io.logger.Logger log
      the logger
    • connectionMonitor

      protected final ConnectionMonitor connectionMonitor
      the connection monitor -- may be null
    • connectionMonitorParams

      protected final ConnectionMonitor.Params connectionMonitorParams
      the connection monitor parameters -- may be null, if connectionMonitor is also null
  • Constructor Details

  • Method Details

    • addClientEntry

      public void addClientEntry(ClientEntry c)
      add a client to the list
      Specified by:
      addClientEntry in interface CommServer
    • getServiceName

      public String getServiceName()
      Return the service name.
    • append

      public com.fishlib.base.log.LogOutput append(com.fishlib.base.log.LogOutput logOutput)
      Specified by:
      append in interface com.fishlib.base.log.LogOutputAppendable
    • setAcceptor

      public void setAcceptor(Acceptor acceptor)
      Record the acceptor which is creating connections for this server.
    • getPort

      public int getPort()
      Return the port on which this server is listenening.
      Specified by:
      getPort in interface CommServer
    • handleNewClient

      protected void handleNewClient(ClientEntry client)
      Notify the implementation of a new connection.
    • handleLostClient

      protected void handleLostClient(ClientEntry client, CommandHandler handler)
      Notify the implementation of lost connection.
    • startJob

      public void startJob(IOJob job)
      Specified by:
      startJob in interface IOHandler
      Overrides:
      startJob in class NullIOHandler
    • sendCommand

      public void sendCommand(String serviceId, com.fishlib.base.Command cmd)
      Send a command to all clients for a specified service.
      Specified by:
      sendCommand in interface CommServer
    • sendCommand

      public void sendCommand(String serviceId, com.fishlib.base.Command cmd, int sendTo)
      Send a command to all clients for a specified service which also match the sendTo flag
      Specified by:
      sendCommand in interface CommServer
    • sendCommand

      public boolean sendCommand(ClientEntry client, String serviceId, com.fishlib.base.Command cmd, boolean allowFlush)
      Send a command to a specific client. The serviceId is not checked before sending the message, but it is passed along to the client's processCommand() method.
      Specified by:
      sendCommand in interface CommServer
      Returns:
      false if an IOException was caught while sending the command, true otherwise
    • sendAsyncCommandWithResponse

      public void sendAsyncCommandWithResponse(ClientEntry client, String serviceId, com.fishlib.base.Command cmd, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) throws IOException
      Send a command, for which we expect a response, to a specific client. The serviceId is not checked before sending the message, but it is passed along to the client's processCommand() method.
      Specified by:
      sendAsyncCommandWithResponse in interface CommServer
      Throws:
      IOException
    • sendCommandWithResponse

      public com.fishlib.base.Command sendCommandWithResponse(ClientEntry client, String serviceId, com.fishlib.base.Command command, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) throws IOException
      Specified by:
      sendCommandWithResponse in interface CommServer
      Throws:
      IOException
    • getClientSet

      public List<ClientEntry> getClientSet()
      Return the set of connected clients
      Specified by:
      getClientSet in interface CommServer
    • addCommandHandler

      public void addCommandHandler(String id, CommandHandler commandHandler)
      Add a new command handler to this server.
      Specified by:
      addCommandHandler in interface CommServer
    • removeCommandHandler

      public void removeCommandHandler(String id)
      Remove a command handler from this server.
      Specified by:
      removeCommandHandler in interface CommServer
    • disconnect

      public void disconnect()
      Close the server socket, and disconnect all clients.
      Specified by:
      disconnect in interface CommServer
    • onDisconnect

      protected void onDisconnect()
    • TEST_SOCKET_CLOSE

      public void TEST_SOCKET_CLOSE()
      disconnect all clients, but leave the server socket open
      Specified by:
      TEST_SOCKET_CLOSE in interface CommServer
    • handleCommand

      public void handleCommand(ClientEntry client, com.fishlib.base.Command cmd)
      Handle an incoming command.
      Specified by:
      handleCommand in interface CommServer
    • handleCommand

      public void handleCommand(ClientEntry client, com.fishlib.base.Command cmd, long now)
      Handle an incoming command.