Class ReactorClient

  • Direct Known Subclasses:
    StompCommonClient

    public abstract class ReactorClient
    extends java.lang.Object
    Abstract implementation of JsonRpcClient which handles low level networking.
    • Field Detail

      • log

        private static org.slf4j.Logger log
      • hostname

        private final java.lang.String hostname
      • port

        private final int port
      • lock

        private final java.util.concurrent.locks.Lock lock
      • lastIncomingHeartbeat

        private java.util.concurrent.atomic.AtomicLong lastIncomingHeartbeat
      • lastOutgoingHeartbeat

        private java.util.concurrent.atomic.AtomicLong lastOutgoingHeartbeat
      • closing

        private java.util.concurrent.atomic.AtomicBoolean closing
      • half

        protected boolean half
      • reactor

        protected final Reactor reactor
      • outbox

        protected final java.util.Deque<java.nio.ByteBuffer> outbox
      • key

        protected java.nio.channels.SelectionKey key
      • ibuff

        protected java.nio.ByteBuffer ibuff
      • channel

        protected java.nio.channels.SocketChannel channel
    • Constructor Detail

      • ReactorClient

        public ReactorClient​(Reactor reactor,
                             java.lang.String hostname,
                             int port)
    • Method Detail

      • getHostname

        public java.lang.String getHostname()
      • getClientId

        public java.lang.String getClientId()
      • setClientPolicy

        public void setClientPolicy​(ClientPolicy policy)
      • getSelectionKey

        public java.nio.channels.SelectionKey getSelectionKey()
      • emitOnMessageReceived

        protected void emitOnMessageReceived​(byte[] message)
      • disconnect

        public final void disconnect​(java.lang.String message)
      • close

        public java.util.concurrent.Future<java.lang.Void> close()
      • scheduleClose

        private java.util.concurrent.Future<java.lang.Void> scheduleClose​(java.lang.String message)
      • scheduleTask

        protected <T> java.util.concurrent.FutureTask<T> scheduleTask​(java.util.concurrent.Callable<T> callable)
      • processIncoming

        protected abstract void processIncoming()
                                         throws java.io.IOException,
                                                ClientConnectionException
        Process incoming channel.
        Throws:
        java.io.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()
      • closeChannel

        protected void closeChannel()
      • isOpen

        public boolean isOpen()
      • getConnectionId

        public int getConnectionId()
      • isOutgoingHeartbeatExceeded

        private boolean isOutgoingHeartbeatExceeded()
      • now

        public long now()
      • sendMessage

        public abstract void sendMessage​(byte[] message)
                                  throws ClientConnectionException
        Sends message using provided byte array.
        Parameters:
        message - - content of the message to sent.
        Throws:
        ClientConnectionException - when issues with connection.
      • read

        protected abstract int read​(java.nio.ByteBuffer buff)
                             throws java.io.IOException
        Reads provided buffer.
        Parameters:
        buff - provided buffer to be read.
        Returns:
        Number of bytes read.
        Throws:
        java.io.IOException - when networking issue occurs.
      • write

        protected abstract void write​(java.nio.ByteBuffer buff)
                               throws java.io.IOException
        Writes provided buffer.
        Parameters:
        buff - provided buffer to be written.
        Throws:
        java.io.IOException - when networking issue occurs.
      • updateInterestedOps

        public abstract void updateInterestedOps()
        Updates selection key's operation set.
      • getPostConnectCallback

        protected abstract OneTimeCallback getPostConnectCallback()
        Returns:
        Client specific OneTimeCallback or 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:
        true when connection initialization is in progress like SSL hand shake. false when connection is initialized.
      • buildNetworkResponse

        protected abstract byte[] buildNetworkResponse​(java.lang.String reason)
        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

        public abstract void validate​(ClientPolicy policy)
        Validates policy when it is set.
        Parameters:
        policy - - validated policy
      • clean

        protected abstract void clean()
        Cleans internal state.
      • getPeerCertificates

        public java.util.List<java.security.cert.Certificate> getPeerCertificates()
        Returns:
        the peer certificates of the current session