Class ClientStub

java.lang.Object
org.jgroups.raft.client.ClientStub
All Implemented Interfaces:
Closeable, AutoCloseable, Settable

public class ClientStub extends Object implements Settable, Closeable
Client stub which accesses a remote server via the CLIENT protocol through a socket. Forwards all requests to the remote server and receives the responses.
Since:
1.0.0
Author:
Bela Ban
  • Field Details

    • host

      protected InetAddress host
    • port

      protected int port
    • sock

      protected Socket sock
    • in

      protected DataInputStream in
    • out

      protected DataOutputStream out
    • current_request_id

      protected int current_request_id
    • requests

      protected final Map<Integer,CompletableFuture<byte[]>> requests
    • runner

      protected org.jgroups.util.Runner runner
    • log

      protected final org.jgroups.logging.Log log
  • Constructor Details

    • ClientStub

      public ClientStub(InetAddress host, int port)
  • Method Details

    • getHost

      public InetAddress getHost()
    • setHost

      public ClientStub setHost(InetAddress h)
    • getPort

      public int getPort()
    • setPort

      public ClientStub setPort(int p)
    • start

      public ClientStub start() throws Exception
      Throws:
      Exception
    • stop

      public ClientStub stop()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • setAsync

      public CompletableFuture<byte[]> setAsync(byte[] buf, int offset, int length, Options ignored) throws Exception
      Description copied from interface: Settable
      Asynchronous set, returns immediately with a CompletableFuture. To wait for the result, CompletableFuture.get() or CompletableFuture.get(long, TimeUnit) can be called.
      Specified by:
      setAsync in interface Settable
      Parameters:
      buf - The buffer (usually a serialized command) which represent the change to be applied to all state machines
      offset - The offset into the buffer
      length - he number of bytes to be used in the buffer, starting at offset
      ignored - Options to pass to the call, may be null
      Returns:
      A CompletableFuture which can be used to fetch the result.
      Throws:
      Exception
    • getAsync

      public CompletableFuture<byte[]> getAsync(byte[] buf, int offset, int length, Options ignored) throws Exception
      Description copied from interface: Settable
      Asynchronous get operation that returns immediately without blocking.

      This method submits a read-only operation to the state machine. Read-only operations are treated differently by the replication algorithm. Since read-only operations do not change the state-machine state, these operations are not appended to the replicated log.

      Warning: Do not change the state-machine state by operations submitted through this method. Otherwise, the state-machine will diverge and lead to an undefined state.

      Specified by:
      getAsync in interface Settable
      Parameters:
      buf - The buffer representing the read-only operation to submit to the state machine.
      offset - The offset to skip the bytes in the buffer.
      length - The number of bytes to use from the buffer starting at offset.
      Returns:
      A buffer representing the result after submitting the read-only operation.
      Throws:
      Exception - Thrown if the operation could not be submitted.
    • setAsync

      public CompletableFuture<byte[]> setAsync(CLIENT.RequestType type, byte[] buf, int offset, int length) throws Exception
      Throws:
      Exception
    • readResponse

      protected void readResponse()
    • toString

      public String toString()
      Overrides:
      toString in class Object