Interface Protocol<I extends IncomingMessage,O extends OutgoingMessage>

Type Parameters:
I - Specifies the type of the messages received by the protocol
O - Specifies the type of the message send by the protocol
All Known Implementing Classes:
LiveFeedProtocol, ProtocolBase

public interface Protocol<I extends IncomingMessage,O extends OutgoingMessage>
Represents a protocol which knows how to properly communicate with the server
Author:
uros.bregar
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Gets the value indicating whether the protocol is started - i.e if the communication with server is enabled.
    void
    Reconnects the underlying feed
    void
    Sends the passed data to the server as is.
    boolean
    sendMessage(O message, boolean blocking)
    Sends the passed message instance to the server.
    void
    Sets the ProtocolListener used to observe the current Protocol.
    void
    Starts the protocol - i.e.
    void
    Stops the protocol - i.e.
  • Method Details

    • start

      void start()
      Starts the protocol - i.e. enables(starts) the communication with the server.
      Throws:
      IllegalStateException - The protocol is already started.
    • reconnect

      void reconnect()
      Reconnects the underlying feed
    • isStarted

      boolean isStarted()
      Gets the value indicating whether the protocol is started - i.e if the communication with server is enabled.
      Returns:
      True if protocol is started. False otherwise.
    • setListener

      void setListener(ProtocolListener<I> listener)
      Sets the ProtocolListener used to observe the current Protocol.
      Parameters:
      listener - the ProtocolListener used to observe the current Protocol or a null reference.
    • sendMessage

      boolean sendMessage(O message, boolean blocking) throws MessageException, ProtocolException
      Sends the passed message instance to the server.
      Parameters:
      message - The message derived from OutgoingMessage to be send to the server.
      blocking - true if request must be blocking.
      Returns:
      true if success.
      Throws:
      MessageException - An error occurred while writing the message to byte array.
      ProtocolException - thrown when an un-expected situation is encountered.
    • sendMessage

      void sendMessage(String data) throws MessageException, ProtocolException
      Sends the passed data to the server as is.
      Parameters:
      data - data to be sent.
      Throws:
      MessageException - An error occurred while writing the message to byte array.
      ProtocolException - thrown when an un-expected situation is encountered.
    • stop

      void stop()
      Stops the protocol - i.e. disables the communication with the server.
      Throws:
      IllegalStateException - The protocol is already stopped.