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

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

    • bindingClass

      protected final Class<?> bindingClass
    • bindingInstance

      protected final Object bindingInstance
    • generator

      protected final MethodInvokerGenerator generator
    • methodCache

      protected final com.github.benmanes.caffeine.cache.Cache<String,MethodInformation> methodCache
  • Constructor Details

    • DefaultRPCHandler

      public DefaultRPCHandler(@NonNull @NonNull Class<?> clazz, @Nullable @Nullable Object binding, @NonNull @NonNull ObjectMapper objectMapper, @NonNull @NonNull DataBufFactory dataBufFactory)
      Constructs a new default rpc handler instance.
      Parameters:
      clazz - the raw clazz to which the handler is bound.
      binding - the instance to which the handler is bound, might be null if not needed.
      objectMapper - the object mapper used for reading / writing of arguments and return values.
      dataBufFactory - the data buf factory used to allocate response buffers.
      Throws:
      NullPointerException - if either the given class, object mapper or buffer factory is null.
  • Method Details

    • registerTo

      public void registerTo(@NonNull @NonNull RPCHandlerRegistry registry)
      Registers this rpc handler to the given rpc handler registry.
      Specified by:
      registerTo in interface RPCHandler
      Parameters:
      registry - the registry to register to.
    • 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.