public static interface FredPluginFCPMessageHandler.ServerSideFCPMessageHandler extends FredPluginFCPMessageHandler
FredPluginFCPMessageHandler.ClientSideFCPMessageHandler, FredPluginFCPMessageHandler.PrioritizedMessageHandler, FredPluginFCPMessageHandler.ServerSideFCPMessageHandler
Modifier and Type | Method and Description |
---|---|
FCPPluginMessage |
handlePluginFCPMessage(FCPPluginConnection connection,
FCPPluginMessage message)
Is called to handle messages from your clients.
Must not block for very long and thus must only do small amounts of processing. |
FCPPluginMessage handlePluginFCPMessage(FCPPluginConnection connection, FCPPluginMessage message)
Is called to handle messages from your clients.
Must not block for very long and thus must only do small amounts of processing.
If you ...
- Need a long time to compute a reply.
- Need to keep a reference to the client connection because you want to send messages to
the client after having exited this function; maybe even triggered by events at your
plugin, not by client messages.
Then you should:
- Store the passed FCPPluginConnection
. If you cannot store objects in memory,
for example because you are using a database, you can get the UUID
of the
connection via FCPPluginConnection.getID()
, store only that, and then in the
future get back the connection using
PluginRespirator.getPluginConnectionByID(UUID)
.
- Compute your reply in another thread.
- Once you're ready to send the reply, send the message using the send functions of the
FCPPluginConnection
.
- Notice that there is no explicit disconnection mechanism. Clients can come and go as
they please. The only way to be sure that a connection is alive is by checking whether
the client replies to messages.
Thus, if you store client connections for longer than sending a single reply, make sure
to prevent excessive growth of your connection database upon client disconnection
by implementing a garbage collection mechanism as follows:
Periodically send a message at each connection and check if you get a reply within a
reasonable timeout to check whether the connection is still alive. Drop the connection
if not. You may make a "Ping" message with a "Pong" response a requirement for your
server's protocol.
handlePluginFCPMessage
in interface FredPluginFCPMessageHandler
connection
- The connection of the client which sent the message.FCPPluginConnection.sendSynchronous(
SendDirection, FCPPluginMessage, long)
: The function shall wait for the reply to the
original message, and return it to the caller. This only works if replies are
properly identified, otherwise it would have to throw an IOException
to
signal a timeout while waiting for the reply.message
- The actual message. See the JavaDoc of its member variables for an explanation of
their meaning.constructReplyMessage(FCPPluginMessage, SimpleFieldSet, Bucket, boolean, String,
String)
(or one of its shortcuts) to ensure that the
FCPPluginMessage.identifier
gets preserved.FCPPluginMessage.isReplyMessage()
.FCPPluginConnection
, as explained in the description of this function.FCPPluginConnection.sendSynchronous(SendDirection, FCPPluginMessage, long)
to
fail fast instead of having to wait for timeout.