Class ReactorClient

java.lang.Object
org.ovirt.vdsm.jsonrpc.client.reactors.ReactorClient
Direct Known Subclasses:
StompCommonClient

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

  • Constructor Details

    • ReactorClient

      public ReactorClient(Reactor reactor, String hostname, int port)
  • Method Details

    • getHostname

      public String getHostname()
    • getClientId

      public String getClientId()
    • setClientPolicy

      public void setClientPolicy(ClientPolicy policy)
    • getRetryPolicy

      public ClientPolicy getRetryPolicy()
    • connect

      public void connect() throws ClientConnectionException
      Throws:
      ClientConnectionException
    • getSelectionKey

      public SelectionKey getSelectionKey()
    • addEventListener

      public void addEventListener(ReactorClient.MessageListener el)
    • removeEventListener

      public void removeEventListener(ReactorClient.MessageListener el)
    • emitOnMessageReceived

      protected void emitOnMessageReceived(byte[] message)
    • disconnect

      public final void disconnect(String message)
    • close

      public Future<Void> close()
    • scheduleClose

      private Future<Void> scheduleClose(String message)
    • scheduleTask

      protected <T> FutureTask<T> scheduleTask(Callable<T> callable)
    • process

      public void process() throws IOException, ClientConnectionException
      Throws:
      IOException
      ClientConnectionException
    • processIncoming

      protected abstract void processIncoming() throws IOException, ClientConnectionException
      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

      protected void processOutgoing() throws IOException
      Throws:
      IOException
    • closeChannel

      protected void closeChannel()
    • isOpen

      public boolean isOpen()
    • getConnectionId

      public int getConnectionId()
    • performAction

      public void performAction() throws IOException
      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

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

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

      protected abstract void postConnect(OneTimeCallback callback) throws ClientConnectionException
      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

      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(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 List<Certificate> getPeerCertificates() throws ClientConnectionException
      Returns:
      the peer certificates of the current session
      Throws:
      ClientConnectionException