Interface Protocol<I extends IncomingMessage,O extends OutgoingMessage>
- Type Parameters:
I- Specifies the type of the messages received by the protocolO- 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 TypeMethodDescriptionbooleanGets the value indicating whether the protocol is started - i.e if the communication with server is enabled.voidReconnects the underlying feedvoidsendMessage(String data) Sends the passed data to the server as is.booleansendMessage(O message, boolean blocking) Sends the passedmessageinstance to the server.voidsetListener(ProtocolListener<I> listener) Sets theProtocolListenerused to observe the currentProtocol.voidstart()Starts the protocol - i.e.voidstop()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
Sets theProtocolListenerused to observe the currentProtocol.- Parameters:
listener- theProtocolListenerused to observe the currentProtocolor a null reference.
-
sendMessage
Sends the passedmessageinstance to the server.- Parameters:
message- The message derived fromOutgoingMessageto 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
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.
-