Interface ProtocolMessageHandler<MessageType>

All Superinterfaces:
ProtocolHandler
All Known Implementing Classes:
ProtocolMessageHandler.Null

public interface ProtocolMessageHandler<MessageType> extends ProtocolHandler
User: dsmith Date: Oct 7, 2010 This interface serves the same role as ProtocolHandler, but breaks processing up into two stages - message decoding, and application-level processing. This is to enable implementations that must do long-running or (gasp) synchronous NIO calls (e.g. CommClient.sendCommand) while handling a message. Message decoding happens while synchronized on the associated IOJob, and hence must be fast operation in order to avoid stalling delivery of data for this and other IOJobs with the current Scheduler/Job implementations. Message handling has no such limitation - the only shared resource it consumes is a single NIODriver thread for its duration.
  • Method Details

    • decodeSingleMessage

      MessageType decodeSingleMessage(ByteBuffer buffer)
      Converts data from a ByteBuffer into a message for processing by handleMessage. Implementations *must* ensure that buffer.position() reflects the data consumed before returning. Do *not* make synchronous NIO calls from this method (or do anything else long-running).
      Parameters:
      buffer - The buffer
      Returns:
      A message for handleMessage to process, or null if the buffer does not contain a complete message
    • handleMessage

      void handleMessage(MessageType message)
      Does application-level processing of a message.
      Parameters:
      message - The message, previously returned by a call to decodeSingleMessage