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

public class DefaultRPC extends DefaultRPCProvider implements RPC
The default implementation of a rpc.
Since:
4.0
  • Field Details

    • sender

      private final RPCSender sender
    • className

      private final String className
    • methodName

      private final String methodName
    • arguments

      private final Object[] arguments
    • expectedResultType

      private final Type expectedResultType
    • resultExpectation

      private boolean resultExpectation
  • Constructor Details

  • 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.
    • sender

      @NonNull public @NonNull RPCSender sender()
      Get the sender from which the rpc call is coming (better known as the base class in which the method to call by this rpc is located in).
      Specified by:
      sender in interface RPC
      Returns:
      the sender of this rpc.
    • className

      @NonNull public @NonNull String className()
      Get the fully qualified name of the class the target method is located in.
      Specified by:
      className in interface RPC
      Returns:
      the fully qualified name of the class the target method is located in.
    • methodName

      @NonNull public @NonNull String methodName()
      Get the name of the method which should get called.
      Specified by:
      methodName in interface RPC
      Returns:
      the name of the method which should get called.
    • arguments

      @NonNull public @NonNull Object[] arguments()
      Get the arguments which should get used to call the method. The main identification of a method happens based on the name and the amount of arguments supplied. Invalid arguments might cause exceptions on the receiver site.
      Specified by:
      arguments in interface RPC
      Returns:
      the arguments which should get used to call the method.
    • expectedResultType

      @NonNull public @NonNull Type expectedResultType()
      Get the expected result type of the method invocation. Can be void.
      Specified by:
      expectedResultType in interface RPC
      Returns:
      the expected result type of the method invocation.
    • disableResultExpectation

      @NonNull public @NonNull RPC disableResultExpectation()
      Disables that this rpc is waiting for a result from the target network component. By default, the current component will always wait for the target method to be executed on the receiver site, event if the method returns void.
      Specified by:
      disableResultExpectation in interface RPC
      Returns:
      the same instance used to call the method, for chaining.
    • expectsResult

      public boolean expectsResult()
      Get if this rpc expects a result from the network component the invoke request is sent to.
      Specified by:
      expectsResult in interface RPC
      Returns:
      true if the current rpc expects a result from the target network component, false otherwise.
    • 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

      @Nullable 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

      @Nullable 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.