Class DefaultRPCHandler

java.lang.Object
eu.cloudnetservice.driver.impl.network.rpc.DefaultRPCProvider
eu.cloudnetservice.driver.impl.network.rpc.handler.DefaultRPCHandler
All Implemented Interfaces:
eu.cloudnetservice.driver.network.rpc.handler.RPCHandler, eu.cloudnetservice.driver.network.rpc.RPCProvider

final class DefaultRPCHandler extends DefaultRPCProvider implements eu.cloudnetservice.driver.network.rpc.handler.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<DefaultRPCMethodMetadata, MethodInvoker> methodInvokerCache
  • Constructor Details

    • DefaultRPCHandler

      DefaultRPCHandler(@NonNull @NonNull eu.cloudnetservice.driver.network.rpc.factory.RPCFactory sourceFactory, @NonNull @NonNull eu.cloudnetservice.driver.network.object.ObjectMapper objectMapper, @NonNull @NonNull eu.cloudnetservice.driver.network.buffer.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<eu.cloudnetservice.driver.network.rpc.handler.RPCInvocationResult> handle(@NonNull @NonNull eu.cloudnetservice.driver.network.rpc.handler.RPCInvocationContext context)
      Specified by:
      handle in interface eu.cloudnetservice.driver.network.rpc.handler.RPCHandler
    • getOrCreateMethodInvoker

      @NonNull private @NonNull Try<MethodInvoker> getOrCreateMethodInvoker(@NonNull @NonNull DefaultRPCMethodMetadata 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 DefaultRPCMethodMetadata targetMethod, @NonNull @NonNull eu.cloudnetservice.driver.network.buffer.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.