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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object[]private final Stringprivate final Typeprivate final Stringprivate booleanprivate final RPCSenderFields inherited from class eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCProvider
dataBufFactory, objectMapper, targetClass -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRPC(@NonNull RPCSender sender, @NonNull Class<?> clazz, @NonNull String methodName, @NonNull Object[] arguments, @NonNull ObjectMapper objectMapper, @NonNull Type expectedResultType, @NonNull DataBufFactory dataBufFactory) 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.booleanGet if this rpc expects a result from the network component the invoke request is sent to.<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.<T> @NonNull eu.cloudnetservice.common.concurrent.Task<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> 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 name of the method which should get called.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).Methods inherited from class eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCProvider
dataBufFactory, objectMapper, 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, targetClass
-
Field Details
-
sender
-
className
-
methodName
-
arguments
-
expectedResultType
-
resultExpectation
private boolean resultExpectation
-
-
Constructor Details
-
DefaultRPC
public DefaultRPC(@NonNull @NonNull RPCSender sender, @NonNull @NonNull Class<?> clazz, @NonNull @NonNull String methodName, @NonNull @NonNull Object[] arguments, @NonNull @NonNull ObjectMapper objectMapper, @NonNull @NonNull Type expectedResultType, @NonNull @NonNull DataBufFactory dataBufFactory) Constructs a new default rpc instance.- Parameters:
sender- the sender of this rpc.clazz- the target class of this rpc.methodName- the name of the method which should get invoked.arguments- the arguments which should get supplied to the method to invoke.objectMapper- the object mapper used to write/read data from constructed buffers.expectedResultType- true if this rpc execution expects a result, false otherwise.dataBufFactory- the data buf factory to use for data buf allocation.- Throws:
NullPointerException- if one of the given arguments 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
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). -
className
Get the fully qualified name of the class the target method is located in. -
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.
-
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.
-
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:
disableResultExpectationin interfaceRPC- 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:
expectsResultin interfaceRPC- 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:
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
@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:
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.
-