Class ReactorClient
java.lang.Object
org.ovirt.vdsm.jsonrpc.client.reactors.ReactorClient
- Direct Known Subclasses:
StompCommonClient
Abstract implementation of
JsonRpcClient which handles low level networking.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected SocketChannelstatic final Stringprivate final AtomicBooleanprotected final List<ReactorClient.MessageListener> protected final AtomicBooleanprivate final Stringprotected ByteBufferprotected SelectionKeyprivate final AtomicLongprivate final AtomicLongprivate static final intprivate final Lockprivate static final org.slf4j.Loggerprotected final Deque<ByteBuffer> static final List<Certificate> protected ClientPolicyprivate final intprotected final Reactor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected abstract byte[]buildNetworkResponse(String reason) Builds network issue message for specific protocol.protected abstract voidclean()Cleans internal state.close()protected voidvoidconnect()final voiddisconnect(String message) protected voidemitOnMessageReceived(byte[] message) intprivate longprotected abstract OneTimeCallbackprivate booleanabstract booleanisInInit()booleanisOpen()private booleanlongnow()voidprotected abstract voidpostConnect(OneTimeCallback callback) Transport specific post connection functionality.abstract voidCleans resources after disconnect.voidprocess()private voidprotected abstract voidProcess incoming channel.protected voidprotected abstract intread(ByteBuffer buff) Reads provided buffer.voidscheduleClose(String message) protected <T> FutureTask<T> scheduleTask(Callable<T> callable) protected abstract voidClient sends protocol specific heartbeat messageabstract voidsendMessage(byte[] message) Sends message using provided byte array.voidsetClientPolicy(ClientPolicy policy) abstract voidUpdates selection key's operation set.protected voidprotected voidabstract voidvalidate(ClientPolicy policy) Validates policy when it is set.protected abstract voidwrite(ByteBuffer buff) Writes provided buffer.
-
Field Details
-
PEER_CERTIFICATE_EMPTY_LIST
-
CLIENT_CLOSED
- See Also:
-
BUFFER_SIZE
public static final int BUFFER_SIZE- See Also:
-
LIMIT
private static final int LIMIT- See Also:
-
log
private static final org.slf4j.Logger log -
hostname
-
port
private final int port -
lock
-
lastIncomingHeartbeat
-
lastOutgoingHeartbeat
-
closing
-
half
-
policy
-
eventListeners
-
reactor
-
outbox
-
key
-
ibuff
-
channel
-
-
Constructor Details
-
ReactorClient
-
-
Method Details
-
getHostname
-
getClientId
-
setClientPolicy
-
getRetryPolicy
-
connect
- Throws:
ClientConnectionException
-
getSelectionKey
-
addEventListener
-
removeEventListener
-
emitOnMessageReceived
protected void emitOnMessageReceived(byte[] message) -
disconnect
-
close
-
scheduleClose
-
scheduleTask
-
process
- Throws:
IOExceptionClientConnectionException
-
processIncoming
Process incoming channel.- Throws:
IOException- Thrown when reading issue occurred.ClientConnectionException- Thrown when issues with connection.
-
processHeartbeat
private void processHeartbeat() -
getHeartbeatTime
private long getHeartbeatTime() -
isIncomingHeartbeatExceeded
private boolean isIncomingHeartbeatExceeded() -
updateLastIncomingHeartbeat
protected void updateLastIncomingHeartbeat() -
updateLastOutgoingHeartbeat
protected void updateLastOutgoingHeartbeat() -
processOutgoing
- Throws:
IOException
-
closeChannel
protected void closeChannel() -
isOpen
public boolean isOpen() -
getConnectionId
public int getConnectionId() -
performAction
- Throws:
IOException
-
isOutgoingHeartbeatExceeded
private boolean isOutgoingHeartbeatExceeded() -
now
public long now() -
sendMessage
public abstract void sendMessage(byte[] message) Sends message using provided byte array.- Parameters:
message- - content of the message to sent.
-
read
Reads provided buffer.- Parameters:
buff- provided buffer to be read.- Returns:
- Number of bytes read.
- Throws:
IOException- when networking issue occurs.
-
write
Writes provided buffer.- Parameters:
buff- provided buffer to be written.- Throws:
IOException- when networking issue occurs.
-
postConnect
Transport specific post connection functionality.- Parameters:
callback- - callback which is executed after connection is estabilished.- Throws:
ClientConnectionException- when issues with connection.
-
updateInterestedOps
public abstract void updateInterestedOps()Updates selection key's operation set. -
getPostConnectCallback
- Returns:
- Client specific
OneTimeCallbackor null. The callback is executed after the connection is established.
-
postDisconnect
public abstract void postDisconnect()Cleans resources after disconnect. -
isInInit
public abstract boolean isInInit()- Returns:
truewhen connection initialization is in progress like SSL hand shake.falsewhen connection is initialized.
-
buildNetworkResponse
Builds network issue message for specific protocol.- Parameters:
reason- why we want to build network response.- Returns:
- byte array containing response.
-
sendHeartbeat
protected abstract void sendHeartbeat()Client sends protocol specific heartbeat message -
validate
Validates policy when it is set.- Parameters:
policy- - validated policy
-
clean
protected abstract void clean()Cleans internal state. -
getPeerCertificates
- Returns:
- the peer certificates of the current session
- Throws:
ClientConnectionException
-