java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCProvider
eu.cloudnetservice.driver.network.rpc.defaults.rpc.DefaultRPCChain
All Implemented Interfaces:
ChainableRPC, RPCChain, RPCExecutable, RPCProvider

public class DefaultRPCChain extends DefaultRPCProvider implements RPCChain
Represents the default implementation of a rpc chain.
Since:
4.0
  • Field Details

    • rootRPC

      protected final RPC rootRPC
    • headRPC

      protected final RPC headRPC
    • rpcChain

      protected final List<RPC> rpcChain
  • Constructor Details

    • DefaultRPCChain

      protected DefaultRPCChain(@NonNull @NonNull RPC rootRPC, @NonNull @NonNull RPC headRPC)
      Constructs a new default rpc chain instance.
      Parameters:
      rootRPC - the root rpc of the chain, also known as the entry point.
      headRPC - the next rpc to invoke after the root rpc.
      Throws:
      NullPointerException - if either the given root or head rpc is null.
    • DefaultRPCChain

      protected DefaultRPCChain(@NonNull @NonNull RPC rootRPC, @NonNull @NonNull RPC headRPC, @NonNull @NonNull List<RPC> rpcChain)
      Constructs a new default rpc chain instance.
      Parameters:
      rootRPC - the root rpc of the chain, also known as the entry point.
      headRPC - the next rpc to invoke after the root rpc.
      rpcChain - the full chain of rpc invocations to call on top of the root rpc.
      Throws:
      NullPointerException - if either the given root or head rpc is null.
  • Method Details

    • join

      Adds a join statement to the current rpc chain. This method always returns a new rpc chain with the given rpc as the last rpc. Therefore, the result type expectation when firring the rpc chain is based on the last rpc given to the chain using this method.

      A chain can be re-used infinite times and even joined on without making a change to the original rpc chain.

      Specified by:
      join in interface ChainableRPC
      Parameters:
      rpc - the rpc to join on the result of the current chain.
      Returns:
      a new rpc chain instance with the given rpc as its head rpc.
    • head

      @NonNull public @NonNull RPC head()
      Get the current last call of the chain (the head). All result expectations are based on this rpc.
      Specified by:
      head in interface RPCChain
      Returns:
      the last call in the rpc chain.
    • joins

      @NonNull public @NonNull Collection<RPC> joins()
      Get all joins of the rpc in the order in which they get called. The first call in the chain will be the first element of this collection (method call order).
      Specified by:
      joins in interface RPCChain
      Returns:
      all joins of the rpc in the order in which they get called.
    • fireAndForget

      public void fireAndForget()
      Fires the current rpc into the first channel of the associated network component and doesn't wait for the result of the rpc to become available. This method will not suspend the current thread.
      Specified by:
      fireAndForget in interface RPCExecutable
    • fireSync

      @NonNull public <T> T fireSync()
      Fires the current rpc into the first channel of the associated network component and waits for the result to become available, or times out after 30 seconds. This method will suspend the calling thread.
      Specified by:
      fireSync in interface RPCExecutable
      Type Parameters:
      T - the expected return type.
      Returns:
      the result of the method invocation, might be null if the remote method returned null.
    • fire

      @NonNull public <T> @NonNull eu.cloudnetservice.common.concurrent.Task<T> fire()
      Fires the current rpc into the first channel of the associated network component and returns a future which will be completed with the return value of the method execution when it's available or completed with a timeout exception when the query packet future times out.
      Specified by:
      fire in interface RPCExecutable
      Type Parameters:
      T - the expected return type.
      Returns:
      a task completed with the result of the method invocation, null if the remote method returned null.
    • fireAndForget

      public void fireAndForget(@NonNull @NonNull NetworkChannel component)
      Fires the current rpc into the given network channel and doesn't wait for the result of the rpc to become available. This method will not suspend the current thread.
      Specified by:
      fireAndForget in interface RPCExecutable
      Parameters:
      component - the network channel to which the rpc should be sent.
    • fireSync

      @NonNull public <T> T fireSync(@NonNull @NonNull NetworkChannel component)
      Fires the current rpc into the given network channel and waits for the result to become available, or times out after 30 seconds. This method will suspend the calling thread.
      Specified by:
      fireSync in interface RPCExecutable
      Type Parameters:
      T - the expected return type.
      Parameters:
      component - the network channel to which the rpc should be sent.
      Returns:
      the result of the method invocation, might be null if the remote method returned null.
    • fire

      @NonNull public <T> @NonNull eu.cloudnetservice.common.concurrent.Task<T> fire(@NonNull @NonNull NetworkChannel component)
      Fires the current rpc into the given network channel and returns a future which will be completed with the return value of the method execution when it's available or completed with a timeout exception when the query packet future times out.
      Specified by:
      fire in interface RPCExecutable
      Type Parameters:
      T - the expected return type.
      Parameters:
      component - the network channel to which the rpc should be sent.
      Returns:
      a task completed with the result of the method invocation, null if the remote method returned null.
    • writeRPCInformation

      protected void writeRPCInformation(@NonNull DataBuf.Mutable dataBuf, @NonNull @NonNull RPC rpc, boolean last)
      Writes the given rpc into the given buffer.
      Parameters:
      dataBuf - the data buffer to write the rpc to.
      rpc - the rpc to serialize.
      last - true if the given rpc is the last rpc in the call chain, false otherwise.
      Throws:
      NullPointerException - if either the given buffer or rpc is null.