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, wait
getType, read, write
public boolean isUnwantedDisconnection()
public ConnectionState getConnectionStatus()
ComProtocol
getConnectionStatus
in interface ComProtocol
public void notifyNewMessage(@Nullable byte[] message)
notifyNewMessage
in interface ComProtocol
message
- the input message receivedpublic void sendAsync(byte[] responseMessage, ComProtocol.IOnEvent<byte[]> event)
ComProtocol
sendAsync
in interface ComProtocol
responseMessage
- the data to sendevent
- callback eventpublic void addOnMessageListener(ComProtocol.IOnEvent<byte[]> listener)
ComProtocol
addOnMessageListener
in interface ComProtocol
listener
- the listnerpublic void setConnectionStatus(ConnectionState connectionStatus)
public void addOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener)
ComProtocol
addOnConnectionStatusChangeListener
in interface ComProtocol
listener
- the listenerpublic boolean removeOnConnectionStatusChangeListener(ComProtocol.OnConnectionStatusChangeListener listener)
removeOnConnectionStatusChangeListener
in interface ComProtocol
listener
- the listenerpublic void setLastError(java.lang.Throwable lastError)
public java.lang.Throwable getLastError()
getLastError
in interface ComProtocol
public void addOnErrorListener(ComProtocol.OnErrorListener listener)
ComProtocol
addOnErrorListener
in interface ComProtocol
listener
- the listenerpublic boolean removeOnErrorListener(ComProtocol.OnErrorListener listener)
removeOnErrorListener
in interface ComProtocol
listener
- the listenerpublic byte[] send(byte[] message) throws java.lang.Exception
ComProtocol
send
in interface ComProtocol
message
- the data to sendjava.lang.Exception
- when send failspublic void connect() throws java.lang.Exception
ComProtocol
connect
in interface ComProtocol
java.lang.Exception
- when connection failspublic void disconnect() throws java.lang.Exception
ComProtocol
disconnect
in interface ComProtocol
java.lang.Exception
- when disconnection failspublic boolean isConnected()
isConnected
in interface ComProtocol
public void disconnectIgnoreError()
public ComProtocol.Configuration getConfiguration()
getConfiguration
in interface ComProtocol