Class DefaultRPC
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
The default implementation of a rpc.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.network.rpc.RPCProvider
RPCProvider.Builder<B extends RPCProvider.Builder<B>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object[]private final Supplier<NetworkChannel> private booleanprivate Durationprivate final RPCSenderprivate final RPCMethodMetadataFields inherited from class eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCProvider
dataBufFactory, objectMapper, sourceFactory, targetClass -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRPC(@NonNull Class<?> targetClass, @NonNull RPCFactory sourceFactory, @NonNull ObjectMapper objectMapper, @NonNull DataBufFactory dataBufFactory, @NonNull RPCSender sender, @NonNull Supplier<NetworkChannel> channelSupplier, @Nullable Duration executionTimeout, @NonNull RPCMethodMetadata targetMethod, @NonNull Object[] arguments) Constructs a new default rpc instance. -
Method Summary
Modifier and TypeMethodDescriptionGet the arguments which should get used to call the method.Get the fully qualified name of the class the target method is located in.Disables that this rpc is waiting for a result from the target network component.Get the expected result type of the method invocation.<T> @NonNull CompletableFuture<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.<T> @NonNull CompletableFuture<T> fire(@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.voidFires 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.voidfireAndForget(@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.<T> @UnknownNullability TfireSync()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.<T> TfireSync(@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.Adds a join statement to the current rpc chain.Get the descriptor string of the method that should be invoked.Get the name of the method which should get called.booleanGet whether the result of the method call is discarded and the execution of the method should not be waited for.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).Get the full metadata of the target method.timeout()Get the timeout that is applied to this RPC, if any.Sets the timeout that should be applied to the RPC.Methods inherited from class eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCProvider
dataBufFactory, objectMapper, sourceFactory, targetClassMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.rpc.RPCProvider
dataBufFactory, objectMapper, sourceFactory, targetClass
-
Field Details
-
sender
-
channelSupplier
-
arguments
-
targetMethod
-
dropResult
private boolean dropResult -
executionTimeout
-
-
Constructor Details
-
DefaultRPC
public DefaultRPC(@NonNull @NonNull Class<?> targetClass, @NonNull @NonNull RPCFactory sourceFactory, @NonNull @NonNull ObjectMapper objectMapper, @NonNull @NonNull DataBufFactory dataBufFactory, @NonNull @NonNull RPCSender sender, @NonNull @NonNull Supplier<NetworkChannel> channelSupplier, @Nullable @Nullable Duration executionTimeout, @NonNull @NonNull RPCMethodMetadata targetMethod, @NonNull @NonNull Object[] arguments) Constructs a new default rpc instance.- Parameters:
targetClass- the class targeted by the RPC.sourceFactory- the rpc factory that constructed this object.objectMapper- the object mapper used for data serialization during rpc execution.dataBufFactory- the data buffer factory to use for buffer allocations during rpc execution.sender- the sender that constructed this rpc.channelSupplier- the default channel supplier to use during execution if none is provided.executionTimeout- the timeout for the execution of this rpc.targetMethod- the target method that should be invoked.arguments- the arguments to supply for execution.- Throws:
NullPointerException- if one of the given arguments, except the timeout, 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:
joinin interfaceChainableRPC- 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
-
className
-
methodName
Get the name of the method which should get called.- Specified by:
methodNamein interfaceRPC- Returns:
- the name of the method which should get called.
-
methodDescriptor
Get the descriptor string of the method that should be invoked.- Specified by:
methodDescriptorin interfaceRPC- Returns:
- the descriptor string of the method that should be invoked.
-
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. -
expectedResultType
Get the expected result type of the method invocation. Can be void.- Specified by:
expectedResultTypein interfaceRPC- Returns:
- the expected result type of the method invocation.
-
targetMethod
Get the full metadata of the target method.- Specified by:
targetMethodin interfaceRPC- Returns:
- the full metadata of the target method.
-
timeout
Sets the timeout that should be applied to the RPC. The default value is derived from the target in the target class (using theRPCTimeoutannotation). If no timeout is set, the fire methods will wait for a method result forever. -
timeout
-
dropResult
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:
dropResultin interfaceRPC- Returns:
- the same instance used to call the method, for chaining.
-
resultDropped
public boolean resultDropped()Get whether the result of the method call is discarded and the execution of the method should not be waited for.- Specified by:
resultDroppedin interfaceRPC- Returns:
- true if the result of this RPC gets discarded, 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:
fireAndForgetin interfaceRPCExecutable
-
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:
fireSyncin interfaceRPCExecutable- Type Parameters:
T- the expected return type.- Returns:
- the result of the method invocation, might be null if the remote method returned null.
-
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:
firein interfaceRPCExecutable- 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
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:
fireAndForgetin interfaceRPCExecutable- Parameters:
component- the network channel to which the rpc should be sent.
-
fireSync
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:
fireSyncin interfaceRPCExecutable- 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
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. Note: if the target method return a task, this method does not return a task wrapping a task, but rather the return value in the task directly.- Specified by:
firein interfaceRPCExecutable- 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.
-