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

final class DefaultRPCHandler extends DefaultRPCProvider implements RPCHandler
Represents the default implementation of a rpc handler.
Since:
4.0
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • boundInstance

      private final Object boundInstance
    • targetClassMeta

      private final RPCClassMetadata targetClassMeta
    • methodInvokerCache

      private final com.github.benmanes.caffeine.cache.Cache<RPCMethodMetadata,MethodInvoker> methodInvokerCache
  • Constructor Details

  • 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

      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:
      handle in interface RPCHandler
      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.