Class Client
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
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.deephaven.enterprise.comm.api.CommClient
CommClient.Null -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.fishlib.base.clock.Clockthe clock used for send timestampsprotected final ConnectionMonitorthe connection monitor -- may be nullprotected final ConnectionMonitor.Paramsthe connection monitor parameters -- may be null, if connectionMonitor is also nullprotected io.deephaven.enterprise.comm.impl.nio.Client.Connectionthe current connectionprotected final com.fishlib.io.logger.Loggerthe loggerprotected final Stringthe log prefixprotected final RoundTripTrackertrack command round trips.protected final Schedulerthe scheduler instance for this clientstatic final intFields inherited from interface io.deephaven.enterprise.comm.api.CommClient
NULL -
Constructor Summary
ConstructorsConstructorDescriptionClient(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.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 IOJobClient(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). -
Method Summary
Modifier and TypeMethodDescriptionvoidClose the connection to the server.voiddisconnect(boolean allowNotifications) Close the connection to the server.protected voidIf we are going to be running a synchronous command, allow a runnable to be called.protected abstract voidCalled when we establish a connection to the server.protected abstract voidCalled when we lose the connection to the server.protected abstract voidhandleClientPush(ClientEntry client, com.fishlib.base.Command cmd) Unsolicited commands from the server are sent here.protected abstract voidhandleEnvelope(ClientEntry client, WObjectUtil.Envelope<com.fishlib.base.Command> cmd, long now) Give the client a chance to examine every incoming envelopebooleanIs this client currently connected?com.fishlib.base.CommandsendCommand(com.fishlib.base.Command command, boolean allowFlush) Sends a command to the server, waits for the response, and returns it.com.fishlib.base.CommandsendCommand(com.fishlib.base.Command command, long timeoutMillis, boolean allowFlush) Sends a command to the server, waits for the response, and returns it.voidsendCommand(com.fishlib.base.Command command, AsyncCommandHandler handler, boolean allowFlush) voidsendCommand(com.fishlib.base.Command command, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) voidsendCommandAsync(com.fishlib.base.Command cmd, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) Sends a command to the server, passing the response to an async command handler when it arrivesvoidsendCommandNoResponse(com.fishlib.base.Command cmd, boolean allowFlush) Sends a one-way command to the server.static voidsetPreSynchronousCallback(Runnable runnable) Sets an optional callback that is executed before sending each synchronous command.voidtoString()Return a string representation of this clientMethods inherited from class io.deephaven.enterprise.niowrapper.sched.NullIOHandler
endJob, handleEOF, handleError, handleIncoming, handleOutgoing, handleTimeoutMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.deephaven.enterprise.comm.api.CommClient
sendCommand, sendCommand, sendCommand, sendCommand, sendCommandAsync, sendCommandNoResponse
-
Field Details
-
SYNC_TIMEOUT
public static final int SYNC_TIMEOUT -
sched
the scheduler instance for this client -
log
protected final com.fishlib.io.logger.Logger logthe logger -
clock
protected final com.fishlib.base.clock.Clock clockthe clock used for send timestamps -
logPrefix
the log prefix -
connectionMonitor
the connection monitor -- may be null -
connectionMonitorParams
the connection monitor parameters -- may be null, if connectionMonitor is also null -
currentConnection
protected volatile io.deephaven.enterprise.comm.impl.nio.Client.Connection currentConnectionthe current connection -
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
Unsolicited commands from the server are sent here. -
handleClientConnectionEstablished
Called when we establish a connection to the server. -
handleClientConnectionLoss
Called when we lose the connection to the server. -
toString
Return a string representation of this client -
startJob
- Specified by:
startJobin interfaceIOHandler- Overrides:
startJobin classNullIOHandler
-
sendCommandNoResponse
public void sendCommandNoResponse(com.fishlib.base.Command cmd, boolean allowFlush) throws IOException Sends a one-way command to the server.- Specified by:
sendCommandNoResponsein interfaceCommClient- 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:
sendCommandAsyncin interfaceCommClient- 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:
sendCommandin interfaceCommClient- 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:
sendCommandin interfaceCommClient- Throws:
IOException
-
sendCommand
public void sendCommand(com.fishlib.base.Command command, AsyncCommandHandler handler, boolean allowFlush) throws IOException - Specified by:
sendCommandin interfaceCommClient- Throws:
IOException
-
sendCommand
public void sendCommand(com.fishlib.base.Command command, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) throws IOException - Specified by:
sendCommandin interfaceCommClient- Throws:
IOException
-
disconnect
Close the connection to the server.- Specified by:
disconnectin interfaceCommClient- Throws:
IOException
-
disconnect
Close the connection to the server.- Specified by:
disconnectin interfaceCommClient- 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:
isConnectedin interfaceCommClient
-
setPreSynchronousCallback
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.
-