Class Server
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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final ConnectionMonitorthe connection monitor -- may be nullprotected final ConnectionMonitor.Paramsthe connection monitor parameters -- may be null, if connectionMonitor is also nullprotected com.fishlib.io.logger.Loggerthe loggerprotected final Stringthe name of this serverprotected final Schedulerthe NIO schedulerFields inherited from interface io.deephaven.enterprise.comm.api.CommServer
IGNORE_CACHE_CLIENTS, ONLY_CACHE_CLIENTS, SEND_TO_ALL -
Constructor Summary
ConstructorsConstructorDescriptionServer(Scheduler sched, String name, PooledMessage.Pool pool, com.fishlib.io.logger.Logger log, com.fishlib.base.clock.Clock clock, ConnectionMonitor monitor, ConnectionMonitor.Params monitorParams) Construct a new server which accepts connections on a specific port. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd a client to the listvoidaddCommandHandler(String id, CommandHandler commandHandler) Add a new command handler to this server.com.fishlib.base.log.LogOutputappend(com.fishlib.base.log.LogOutput logOutput) voidClose the server socket, and disconnect all clients.Return the set of connected clientsintgetPort()Return the port on which this server is listenening.Return the service name.voidhandleCommand(ClientEntry client, com.fishlib.base.Command cmd) Handle an incoming command.voidhandleCommand(ClientEntry client, com.fishlib.base.Command cmd, long now) Handle an incoming command.protected voidhandleLostClient(ClientEntry client, CommandHandler handler) Notify the implementation of lost connection.protected voidhandleNewClient(ClientEntry client) Notify the implementation of a new connection.protected voidvoidRemove a command handler from this server.voidsendAsyncCommandWithResponse(ClientEntry client, String serviceId, com.fishlib.base.Command cmd, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) Send a command, for which we expect a response, to a specific client.booleansendCommand(ClientEntry client, String serviceId, com.fishlib.base.Command cmd, boolean allowFlush) Send a command to a specific client.voidsendCommand(String serviceId, com.fishlib.base.Command cmd) Send a command to all clients for a specified service.voidsendCommand(String serviceId, com.fishlib.base.Command cmd, int sendTo) Send a command to all clients for a specified service which also match the sendTo flagcom.fishlib.base.CommandsendCommandWithResponse(ClientEntry client, String serviceId, com.fishlib.base.Command command, AsyncCommandHandler handler, long timeoutMillis, boolean allowFlush) voidsetAcceptor(Acceptor acceptor) Record the acceptor which is creating connections for this server.voidvoiddisconnect all clients, but leave the server socket openMethods 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, toString, wait, wait, waitMethods inherited from interface io.deephaven.enterprise.comm.api.CommServer
sendCommand, sendCommandWithResponse, sendCommandWithResponse
-
Field Details
-
sched
the NIO scheduler -
name
the name of this server -
log
protected com.fishlib.io.logger.Logger logthe logger -
connectionMonitor
the connection monitor -- may be null -
connectionMonitorParams
the connection monitor parameters -- may be null, if connectionMonitor is also null
-
-
Constructor Details
-
Server
public Server(Scheduler sched, String name, PooledMessage.Pool pool, com.fishlib.io.logger.Logger log, com.fishlib.base.clock.Clock clock, ConnectionMonitor monitor, ConnectionMonitor.Params monitorParams) Construct a new server which accepts connections on a specific port.
-
-
Method Details
-
addClientEntry
add a client to the list- Specified by:
addClientEntryin interfaceCommServer
-
getServiceName
Return the service name. -
append
public com.fishlib.base.log.LogOutput append(com.fishlib.base.log.LogOutput logOutput) - Specified by:
appendin interfacecom.fishlib.base.log.LogOutputAppendable
-
setAcceptor
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:
getPortin interfaceCommServer
-
handleNewClient
Notify the implementation of a new connection. -
handleLostClient
Notify the implementation of lost connection. -
startJob
- Specified by:
startJobin interfaceIOHandler- Overrides:
startJobin classNullIOHandler
-
sendCommand
Send a command to all clients for a specified service.- Specified by:
sendCommandin interfaceCommServer
-
sendCommand
Send a command to all clients for a specified service which also match the sendTo flag- Specified by:
sendCommandin interfaceCommServer
-
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:
sendCommandin interfaceCommServer- 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:
sendAsyncCommandWithResponsein interfaceCommServer- 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:
sendCommandWithResponsein interfaceCommServer- Throws:
IOException
-
getClientSet
Return the set of connected clients- Specified by:
getClientSetin interfaceCommServer
-
addCommandHandler
Add a new command handler to this server.- Specified by:
addCommandHandlerin interfaceCommServer
-
removeCommandHandler
Remove a command handler from this server.- Specified by:
removeCommandHandlerin interfaceCommServer
-
disconnect
public void disconnect()Close the server socket, and disconnect all clients.- Specified by:
disconnectin interfaceCommServer
-
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_CLOSEin interfaceCommServer
-
handleCommand
Handle an incoming command.- Specified by:
handleCommandin interfaceCommServer
-
handleCommand
Handle an incoming command.
-