Class DefaultRPCChain
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
Represents the default implementation of a rpc chain.
- 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 RPCprivate final RPCprivate final Supplier<NetworkChannel> Fields inherited from class eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCProvider
dataBufFactory, objectMapper, sourceFactory, targetClass -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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.joins()Get all joins of the rpc in the order in which they get called.static @NonNull DefaultRPCChainConstructs a new rpc chain using the given root and tail rpc.tail()Get the current last call of the chain (the head).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
-
chainHead
-
chainTail
-
fullChain
-
channelSupplier
-
-
Constructor Details
-
DefaultRPCChain
private DefaultRPCChain(@NonNull @NonNull RPC chainHead, @NonNull @NonNull RPC chainTail, @NonNull @NonNull List<RPC> fullChain, @NonNull @NonNull Supplier<NetworkChannel> channelSupplier) Constructs a new rpc chain instance.- Parameters:
chainHead- the first rpc in the execution chain.chainTail- the last rpc in the execution chain.fullChain- the full chain of rpc to invoke.channelSupplier- the target channel supplier to use for method invocation if no channel is provided.- Throws:
NullPointerException- if one of the given parameters is null.
-
-
Method Details
-
of
@NonNull public static @NonNull DefaultRPCChain of(@NonNull @NonNull RPC root, @NonNull @NonNull RPC next, @NonNull @NonNull Supplier<NetworkChannel> channelSupplier) Constructs a new rpc chain using the given root and tail rpc.- Parameters:
root- the root rpc for the chain.next- the tail rpc for the chain.channelSupplier- the target channel supplier to use for method invocation if no channel is provided.- Returns:
- the constructed rpc chain.
- Throws:
NullPointerException- if the given root rpc, tail rpc or channel supplier is null.
-
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.
-
tail
-
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). -
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.
-