Class ConfigurableProtocolConverter

java.lang.Object
com.thecoderscorner.menu.remote.protocol.ConfigurableProtocolConverter
All Implemented Interfaces:
MenuCommandProtocol

public class ConfigurableProtocolConverter extends Object implements MenuCommandProtocol
An implementation of the menu command protocol interface that is configurable, by default it can create all the regular tag value message processors so that regular embedCONTROL messages can be parsed and written. It is also possible to add extra command handlers for both TagVal protocol and also for binary format.
  • Constructor Details

    • ConfigurableProtocolConverter

      public ConfigurableProtocolConverter(boolean includeDefaultProcessors)
  • Method Details

    • addTagValInProcessor

      public void addTagValInProcessor(MessageField field, TagValProtocolIncomingMsgConverter processor)
      This method adds an additional tag value message processor that can convert an incoming wire message into a command. In this case the processor will take a TagValTextParser and convert that into a MenuCommand.
      Parameters:
      field - the message type to convert
      processor - the processor that can do the conversion
    • addTagValOutProcessor

      public <T extends MenuCommand> void addTagValOutProcessor(MessageField field, ProtocolOutgoingMsgConverter<T,StringBuilder> processor, Class<T> clazz)
      This methods adds an additional tag value message processor that can convert a MenuCommand into the appropriate wire format for sending.
      Type Parameters:
      T - specialization of the message class extending from MenuCommand.
      Parameters:
      field - the type to convert
      processor - the processor that can do the conversion
      clazz - the specific message class
    • addRawInProcessor

      public void addRawInProcessor(MessageField field, RawProtocolIncomingMsgConverter processor)
      This method adds an additional binary message processor that can convert an incoming wire message into a command. In this case the processor will take a byte buffer and length of the message in the buffer, it should convert this into a MenuCommand.
      Parameters:
      field - the message type to convert
      processor - the processor that can do the conversion
    • addRawOutProcessor

      public <T extends MenuCommand> void addRawOutProcessor(MessageField field, ProtocolOutgoingMsgConverter<T,ByteBuffer> processor, Class<T> clazz)
      This method adds an addition binary message processor that can convert a MenuCommand into binary wire format, you must write 4 bytes containing the length first.
      Type Parameters:
      T - specialization of the message class extending from MenuCommand.
      Parameters:
      field - the message type to convert
      processor - the processor for this conversion
      clazz - the specific message class
    • fromChannel

      public MenuCommand fromChannel(ByteBuffer buffer) throws IOException
      Description copied from interface: MenuCommandProtocol
      Retrieves a message from the channel, or throws an exception if the message is not fully formed. It is assumed that the buffer has been suitably flipped ready for reading
      Specified by:
      fromChannel in interface MenuCommandProtocol
      Throws:
      IOException
    • toChannel

      public void toChannel(ByteBuffer buffer, MenuCommand cmd) throws TcProtocolException
      Description copied from interface: MenuCommandProtocol
      Puts the command specified into the byte buffer, it is assumed that the callee will flip the channel once complete.
      Specified by:
      toChannel in interface MenuCommandProtocol
      Parameters:
      buffer - to write the data to
      cmd - the command to write
      Throws:
      TcProtocolException
    • getProtocolForCmd

      public CommandProtocol getProtocolForCmd(MenuCommand command)
      Description copied from interface: MenuCommandProtocol
      Checks the message and sees which protocol it will be processed with. For example the JOIN message would be processed using TagVal.
      Specified by:
      getProtocolForCmd in interface MenuCommandProtocol
      Parameters:
      command - the command to check the protocol of
      Returns:
      the protocol that will be used.