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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
isStarted()
Gets the value indicating whether the protocol is started - i.e if the communication with server is enabled.void
reconnect()
Reconnects the underlying feedvoid
sendMessage(String data)
Sends the passed data to the server as is.boolean
sendMessage(O message, boolean blocking)
Sends the passedmessage
instance to the server.void
setListener(ProtocolListener<I> listener)
Sets theProtocolListener
used to observe the currentProtocol
.void
start()
Starts the protocol - i.e.void
stop()
Stops the protocol - i.e.
-
-
-
Method Detail
-
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 theProtocolListener
used to observe the currentProtocol
.- Parameters:
listener
- theProtocolListener
used to observe the currentProtocol
or a null reference.
-
sendMessage
boolean sendMessage(O message, boolean blocking) throws MessageException, ProtocolException
Sends the passedmessage
instance to the server.- Parameters:
message
- The message derived fromOutgoingMessage
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.
-
-