Class DefaultRPCHandler
java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCProvider
eu.cloudnetservice.driver.network.rpc.defaults.handler.DefaultRPCHandler
- All Implemented Interfaces:
RPCHandler,RPCProvider
Represents the default implementation of a rpc handler.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.network.rpc.handler.RPCHandler
RPCHandler.Builder<T>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 Objectprivate static final org.slf4j.Loggerprivate final com.github.benmanes.caffeine.cache.Cache<RPCMethodMetadata, MethodInvoker> private final RPCClassMetadataFields inherited from class eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCProvider
dataBufFactory, objectMapper, sourceFactory, targetClass -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRPCHandler(@NonNull RPCFactory sourceFactory, @NonNull ObjectMapper objectMapper, @NonNull DataBufFactory dataBufFactory, @Nullable Object boundInstance, @NonNull RPCClassMetadata targetClassMeta) Constructs a new rpc handler instance. -
Method Summary
Modifier and TypeMethodDescriptiondeserializeMethodArguments(@NonNull RPCMethodMetadata targetMethod, @NonNull DataBuf encodedArgumentsBuffer) Deserializes the method arguments provided in the given buffer based on the generic parameter types provided from the given target method metadata (in order).private @NonNull io.vavr.control.Try<MethodInvoker> getOrCreateMethodInvoker(@NonNull RPCMethodMetadata methodMetadata) Gets an existing method invoker for the given target method from the cache or creates a new one.handle(@NonNull RPCInvocationContext context) Handles the given rpc context using the information of this handler.private static @Nullable MethodTypeDescparseMethodDescriptor(@NonNull String descriptor) Tries to parse the given method descriptor, returning null if the given method descriptor is invalid.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
-
LOGGER
private static final org.slf4j.Logger LOGGER -
boundInstance
-
targetClassMeta
-
methodInvokerCache
private final com.github.benmanes.caffeine.cache.Cache<RPCMethodMetadata,MethodInvoker> methodInvokerCache
-
-
Constructor Details
-
DefaultRPCHandler
DefaultRPCHandler(@NonNull @NonNull RPCFactory sourceFactory, @NonNull @NonNull ObjectMapper objectMapper, @NonNull @NonNull DataBufFactory dataBufFactory, @Nullable @Nullable Object boundInstance, @NonNull @NonNull RPCClassMetadata targetClassMeta) Constructs a new rpc handler instance.- Parameters:
sourceFactory- the rpc factory that constructed this object.objectMapper- the object mapper to use to write and read data from the buffers.dataBufFactory- the buffer factory used for buffer allocations.boundInstance- the instance to which this handler is bound, can be null.targetClassMeta- the metadata of the target class in which this handler should call methods.- Throws:
NullPointerException- if any parameter, except the bound instance, is null.
-
-
Method Details
-
parseMethodDescriptor
@Nullable private static @Nullable MethodTypeDesc parseMethodDescriptor(@NonNull @NonNull String descriptor) Tries to parse the given method descriptor, returning null if the given method descriptor is invalid.- Parameters:
descriptor- the descriptor that should be parsed.- Returns:
- the parsed method descriptor or null if the given descriptor is invalĂd.
- Throws:
NullPointerException- if the given descriptor is null.
-
handle
@NonNull public @NonNull CompletableFuture<RPCInvocationResult> handle(@NonNull @NonNull RPCInvocationContext context) Handles the given rpc context using the information of this handler. A handler must respect all settings set in the context. The handler decides whether it can handle the request based on the information provided through the context. If the instance use is set to strict in the context (or this handler has no instance set since construction) and no instance is provided through the context, the handler should return a successful result containing either null or the default primitive value based on the return value of the target method (if normalize primitives is set to true in the context). If an exception happens during the post of the rpc to the underlying method the result should be a failure containing as its result the thrown exception.- Specified by:
handlein interfaceRPCHandler- Parameters:
context- the context of the handler invocation.- Returns:
- the result of the handler execution.
-
getOrCreateMethodInvoker
@NonNull private @NonNull io.vavr.control.Try<MethodInvoker> getOrCreateMethodInvoker(@NonNull @NonNull RPCMethodMetadata methodMetadata) Gets an existing method invoker for the given target method from the cache or creates a new one. A failure is returned in case a method invoker couldn't be generated for some reason.- Parameters:
methodMetadata- the metadata of the method to get or create the method invoker for.- Returns:
- a method invoker for the given target method.
- Throws:
NullPointerException- if the given method metadata is null.
-
deserializeMethodArguments
@Nullable private @Nullable Object[] deserializeMethodArguments(@NonNull @NonNull RPCMethodMetadata targetMethod, @NonNull @NonNull DataBuf encodedArgumentsBuffer) Deserializes the method arguments provided in the given buffer based on the generic parameter types provided from the given target method metadata (in order). If an argument at a position is invalid (e.g. bad data or null for a primitive) this method returns null.- Parameters:
targetMethod- the target method to deserialize the method arguments for.encodedArgumentsBuffer- the buffer which holds the encoded method arguments to deserialize.- Returns:
- an array containing the deserialized method arguments, null if the buffer contained bad argument data.
- Throws:
NullPointerException- if the given target method or argument buffer is null.
-