public abstract class AbstractComProtocol extends java.lang.Object implements ComProtocol
ComProtocol.Configuration, ComProtocol.IOnEvent<T>, ComProtocol.OnConnectionStatusChangeListener, ComProtocol.OnErrorListener| Modifier and Type | Field and Description |
|---|---|
boolean |
unwantedDisconnecting
Manual disconnection
|
| Constructor and Description |
|---|
AbstractComProtocol() |
| Modifier and Type | Method and Description |
|---|---|
void |
addOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener)
Set the message listener
|
void |
addOnErrorListener(ComProtocol.OnErrorListener listener)
Set the message listener
|
void |
addOnMessageListener(ComProtocol.IOnEvent<byte[]> listener)
Set the message listener
|
void |
connect()
Connect to the protocol
|
void |
disconnect()
Disconnect from the protocol
|
void |
disconnectIgnoreError() |
ComProtocol.Configuration |
getConfiguration() |
ConnectionState |
getConnectionStatus()
Get the current connection status
|
java.lang.Throwable |
getLastError() |
boolean |
isConnected() |
boolean |
isUnwantedDisconnection() |
void |
notifyNewMessage(byte[] message) |
boolean |
removeOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener) |
boolean |
removeOnErrorListener(ComProtocol.OnErrorListener listener) |
byte[] |
send(byte[] message)
Write request and wait for response
|
void |
sendAsync(byte[] responseMessage,
ComProtocol.IOnEvent<byte[]> event)
Send data asynchronously
|
void |
setConnectionStatus(ConnectionState connectionStatus) |
void |
setLastError(java.lang.Throwable lastError) |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetType, read, writepublic boolean isUnwantedDisconnection()
public ConnectionState getConnectionStatus()
ComProtocolgetConnectionStatus in interface ComProtocolpublic void notifyNewMessage(@Nullable
byte[] message)
notifyNewMessage in interface ComProtocolmessage - the input message receivedpublic void sendAsync(byte[] responseMessage,
ComProtocol.IOnEvent<byte[]> event)
ComProtocolsendAsync in interface ComProtocolresponseMessage - the data to sendevent - callback eventpublic void addOnMessageListener(ComProtocol.IOnEvent<byte[]> listener)
ComProtocoladdOnMessageListener in interface ComProtocollistener - the listnerpublic void setConnectionStatus(ConnectionState connectionStatus)
public void addOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener)
ComProtocoladdOnConnectionStatusChangeListener in interface ComProtocollistener - the listenerpublic boolean removeOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener)
removeOnConnectionStatusChangeListener in interface ComProtocollistener - the listenerpublic void setLastError(java.lang.Throwable lastError)
public java.lang.Throwable getLastError()
getLastError in interface ComProtocolpublic void addOnErrorListener(ComProtocol.OnErrorListener listener)
ComProtocoladdOnErrorListener in interface ComProtocollistener - the listenerpublic boolean removeOnErrorListener(ComProtocol.OnErrorListener listener)
removeOnErrorListener in interface ComProtocollistener - the listenerpublic byte[] send(byte[] message)
throws java.lang.Exception
ComProtocolsend in interface ComProtocolmessage - the data to sendjava.lang.Exception - when send failspublic void connect()
throws java.lang.Exception
ComProtocolconnect in interface ComProtocoljava.lang.Exception - when connection failspublic void disconnect()
throws java.lang.Exception
ComProtocoldisconnect in interface ComProtocoljava.lang.Exception - when disconnection failspublic boolean isConnected()
isConnected in interface ComProtocolpublic void disconnectIgnoreError()
public ComProtocol.Configuration getConfiguration()
getConfiguration in interface ComProtocol