public abstract class ReactorClient extends Object
JsonRpcClient
which handles low level networking.Modifier and Type | Class and Description |
---|---|
static interface |
ReactorClient.MessageListener |
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE |
protected SocketChannel |
channel |
static String |
CLIENT_CLOSED |
protected List<ReactorClient.MessageListener> |
eventListeners |
protected ByteBuffer |
ibuff |
protected SelectionKey |
key |
protected Deque<ByteBuffer> |
outbox |
protected ClientPolicy |
policy |
protected Reactor |
reactor |
Constructor and Description |
---|
ReactorClient(Reactor reactor,
String hostname,
int port) |
Modifier and Type | Method and Description |
---|---|
void |
addEventListener(ReactorClient.MessageListener el) |
protected abstract byte[] |
buildNetworkResponse(String reason)
Builds network issue message for specific protocol.
|
Future<Void> |
close() |
protected void |
closeChannel() |
void |
connect() |
void |
disconnect(String message) |
protected void |
emitOnMessageReceived(byte[] message) |
String |
getClientId() |
int |
getConnectionId() |
String |
getHostname() |
List<Certificate> |
getPeerCertificates() |
protected abstract OneTimeCallback |
getPostConnectCallback() |
ClientPolicy |
getRetryPolicy() |
SelectionKey |
getSelectionKey() |
abstract boolean |
isInInit() |
boolean |
isOpen() |
void |
performAction() |
protected abstract void |
postConnect(OneTimeCallback callback)
Transport specific post connection functionality.
|
abstract void |
postDisconnect()
Cleans resources after disconnect.
|
void |
process() |
protected abstract void |
processIncoming()
Process incoming channel.
|
protected void |
processOutgoing() |
protected abstract int |
read(ByteBuffer buff)
Reads provided buffer.
|
void |
removeEventListener(ReactorClient.MessageListener el) |
protected <T> FutureTask<T> |
scheduleTask(Callable<T> callable) |
protected abstract void |
sendHeartbeat()
Client sends protocol specific heartbeat message
|
abstract void |
sendMessage(byte[] message)
Sends message using provided byte array.
|
void |
setClientPolicy(ClientPolicy policy) |
abstract void |
updateInterestedOps()
Updates selection key's operation set.
|
protected void |
updateLastIncomingHeartbeat() |
protected void |
updateLastOutgoingHeartbeat() |
abstract void |
validate()
Validates policy when it is set.
|
public static final String CLIENT_CLOSED
public static final int BUFFER_SIZE
protected ClientPolicy policy
protected final List<ReactorClient.MessageListener> eventListeners
protected final Reactor reactor
protected final Deque<ByteBuffer> outbox
protected SelectionKey key
protected ByteBuffer ibuff
protected SocketChannel channel
public String getHostname()
public String getClientId()
public void setClientPolicy(ClientPolicy policy)
public ClientPolicy getRetryPolicy()
public void connect() throws ClientConnectionException
ClientConnectionException
public SelectionKey getSelectionKey()
public void addEventListener(ReactorClient.MessageListener el)
public void removeEventListener(ReactorClient.MessageListener el)
protected void emitOnMessageReceived(byte[] message)
public final void disconnect(String message)
protected <T> FutureTask<T> scheduleTask(Callable<T> callable)
public void process() throws IOException, ClientConnectionException
IOException
ClientConnectionException
protected abstract void processIncoming() throws IOException, ClientConnectionException
IOException
- Thrown when reading issue occurred.ClientConnectionException
- Thrown when issues with connection.protected void updateLastIncomingHeartbeat()
protected void updateLastOutgoingHeartbeat()
protected void processOutgoing() throws IOException, ClientConnectionException
IOException
ClientConnectionException
protected void closeChannel()
public boolean isOpen()
public int getConnectionId()
public void performAction()
public abstract void sendMessage(byte[] message) throws ClientConnectionException
message
- - content of the message to sent.ClientConnectionException
- when issues with connection.protected abstract int read(ByteBuffer buff) throws IOException
buff
- provided buffer to be read.IOException
- when networking issue occurs.protected abstract void postConnect(OneTimeCallback callback) throws ClientConnectionException
callback
- - callback which is executed after connection is estabilished.ClientConnectionException
- when issues with connection.public abstract void updateInterestedOps()
protected abstract OneTimeCallback getPostConnectCallback()
OneTimeCallback
or null. The callback is executed
after the connection is established.public abstract void postDisconnect()
public abstract boolean isInInit()
true
when connection initialization is in progress like
SSL hand shake. false
when connection is initialized.protected abstract byte[] buildNetworkResponse(String reason)
reason
- why we want to build network response.protected abstract void sendHeartbeat()
public abstract void validate()
public List<Certificate> getPeerCertificates()
Copyright © 2016. All rights reserved.