java.lang.Object
io.deephaven.enterprise.niowrapper.sched.NullIOHandler
io.deephaven.enterprise.comm.impl.nio.Client
All Implemented Interfaces:
CommClient, IOHandler
Direct Known Subclasses:
WClient, WebsocketCommClient

public abstract class Client extends NullIOHandler implements CommClient
Connection and request-response management for remote servers. A Client is just a connection to a Server instance, supporting both one-way requests and request-response round trips. The Server can also send unsolicited one-way commands, for example to push updates to a price feed or similar. Unsolicited push updates are passed to the CommandHandler provided to the Client object when it is constructed. The Client object does not initiate the connection itself; instead, it is just an IOHandler for some external instance of Connector or Acceptor. When a new connection is established, an inner IOHandler is created to manage the transmission and reception of the actual data. Created by IntelliJ IDEA. User: jrauser Date: Feb 17, 2007 Time: 9:59:47 PM To change this template use File | Settings | File Templates.
  • Field Details

    • SYNC_TIMEOUT

      public static final int SYNC_TIMEOUT
    • sched

      protected final Scheduler sched
      the scheduler instance for this client
    • log

      protected final com.fishlib.io.logger.Logger log
      the logger
    • clock

      protected final com.fishlib.base.clock.Clock clock
      the clock used for send timestamps
    • logPrefix

      protected final String logPrefix
      the log prefix
    • 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
    • currentConnection

      protected volatile io.deephaven.enterprise.comm.impl.nio.Client.Connection currentConnection
      the current connection
    • roundTripTracker

      protected final RoundTripTracker roundTripTracker
      track command round trips.
  • Constructor Details

    • Client

      public Client(Scheduler sched, String serviceId, String statsItemPrefix, PooledMessage.Pool pool, com.fishlib.io.logger.Logger log, com.fishlib.base.clock.Clock clock, ConnectionMonitor monitor, ConnectionMonitor.Params monitorParams)
      Constructs a new client with the given serviceId, communicating over an IOJob, and a statsItemPrefix which is used for the client's statistics items (instead of the serviceId).
    • Client

      public Client(Scheduler sched, String serviceId, PooledMessage.Pool pool, com.fishlib.io.logger.Logger log, com.fishlib.base.clock.Clock clock, ConnectionMonitor monitor, ConnectionMonitor.Params monitorParams)
      Constructs a new client with the given serviceId, communicating over an IOJob
    • Client

      public Client(Scheduler sched, String serviceId, CommServer server, com.fishlib.io.logger.Logger log, com.fishlib.base.clock.Clock clock)
      Constructs a new client with the given serviceId, communicating with an in-process server.
  • Method Details

    • handleEnvelope

      protected abstract void handleEnvelope(ClientEntry client, WObjectUtil.Envelope<com.fishlib.base.Command> cmd, long now)
      Give the client a chance to examine every incoming envelope
    • handleClientPush

      protected abstract void handleClientPush(ClientEntry client, com.fishlib.base.Command cmd)
      Unsolicited commands from the server are sent here.
    • handleClientConnectionEstablished

      protected abstract void handleClientConnectionEstablished(ClientEntry client)
      Called when we establish a connection to the server.
    • handleClientConnectionLoss

      protected abstract void handleClientConnectionLoss(ClientEntry client)
      Called when we lose the connection to the server.
    • toString

      public String toString()
      Return a string representation of this client
      Overrides:
      toString in class Object
    • startJob

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

      public void sendCommandNoResponse(com.fishlib.base.Command cmd, boolean allowFlush) throws IOException
      Sends a one-way command to the server.
      Specified by:
      sendCommandNoResponse in interface CommClient
      Throws:
      IOException
    • sendCommandAsync

      public void sendCommandAsync(com.fishlib.base.Command cmd, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) throws IOException
      Sends a command to the server, passing the response to an async command handler when it arrives
      Specified by:
      sendCommandAsync in interface CommClient
      Throws:
      IOException
    • sendCommand

      public com.fishlib.base.Command sendCommand(com.fishlib.base.Command command, boolean allowFlush) throws IOException
      Sends a command to the server, waits for the response, and returns it.
      Specified by:
      sendCommand in interface CommClient
      Throws:
      IOException
    • sendCommand

      public com.fishlib.base.Command sendCommand(com.fishlib.base.Command command, long timeoutMillis, boolean allowFlush) throws IOException
      Sends a command to the server, waits for the response, and returns it.
      Specified by:
      sendCommand in interface CommClient
      Throws:
      IOException
    • sendCommand

      public void sendCommand(com.fishlib.base.Command command, AsyncCommandHandler handler, boolean allowFlush) throws IOException
      Specified by:
      sendCommand in interface CommClient
      Throws:
      IOException
    • sendCommand

      public void sendCommand(com.fishlib.base.Command command, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) throws IOException
      Specified by:
      sendCommand in interface CommClient
      Throws:
      IOException
    • disconnect

      public void disconnect() throws IOException
      Close the connection to the server.
      Specified by:
      disconnect in interface CommClient
      Throws:
      IOException
    • disconnect

      public void disconnect(boolean allowNotifications) throws IOException
      Close the connection to the server.
      Specified by:
      disconnect in interface CommClient
      Parameters:
      allowNotifications - If true, treat this disconnection as a survivable event. Make sure threads awaiting synchronous commands are unblocked, and allow handlers to be notified.
      Throws:
      IOException
    • isConnected

      public boolean isConnected()
      Is this client currently connected?
      Specified by:
      isConnected in interface CommClient
    • setPreSynchronousCallback

      public static void setPreSynchronousCallback(Runnable runnable)
      Sets an optional callback that is executed before sending each synchronous command.
      Parameters:
      runnable - a callback to execute before each synchronous command (or null)
    • doPreSynchronousCallback

      protected void doPreSynchronousCallback()
      If we are going to be running a synchronous command, allow a runnable to be called. The use case is for verifying that we are not actually doing any potentially blocking network operations on the swing thread.