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 RetryPolicy |
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() |
void |
connect() |
void |
disconnect(String message) |
protected void |
emitOnMessageReceived(byte[] message) |
String |
getClientId() |
String |
getHostname() |
protected abstract OneTimeCallback |
getPostConnectCallback() |
RetryPolicy |
getRetryPolicy() |
SelectionKey |
getSelectionKey() |
abstract boolean |
isInInit() |
boolean |
isOpen() |
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) |
abstract void |
sendMessage(byte[] message)
Sends message using provided byte array.
|
void |
setRetryPolicy(RetryPolicy policy) |
abstract void |
updateInterestedOps()
Updates selection key's operation set.
|
protected void |
updateLastHeartbeat() |
public static final String CLIENT_CLOSED
public static final int BUFFER_SIZE
protected RetryPolicy 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 setRetryPolicy(RetryPolicy policy)
public RetryPolicy 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 updateLastHeartbeat()
protected void processOutgoing() throws IOException, ClientConnectionException
IOException
ClientConnectionException
public boolean isOpen()
public abstract void sendMessage(byte[] message) throws ClientConnectionException
message
- - content of the message to sent.ClientConnectionException
protected abstract int read(ByteBuffer buff) throws IOException
buff
- provided buffer to be read.IOException
- when networking issue occurs.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)
Copyright © 2015. All Rights Reserved.