Class RPCInternalInstanceFactory

java.lang.Object
eu.cloudnetservice.driver.impl.network.rpc.generation.RPCInternalInstanceFactory
Direct Known Subclasses:
RPCInternalInstanceFactory.TempRPCInternalInstanceFactory

public sealed class RPCInternalInstanceFactory extends Object permits RPCInternalInstanceFactory.TempRPCInternalInstanceFactory
The internal instance factory for generated rpc api implementations. This class is only used within this package to hide the actual work from the public-facing api.
Since:
4.0
  • Field Details

    • MT_BASIC_IMPLEMENTATION_CONSTRUCTOR

      static final MethodType MT_BASIC_IMPLEMENTATION_CONSTRUCTOR
    • MTD_BASIC_IMPLEMENTATION_CONSTRUCTOR

      static final MethodTypeDesc MTD_BASIC_IMPLEMENTATION_CONSTRUCTOR
    • allocationNotifier

      private final Runnable allocationNotifier
    • userArgCount

      private final int userArgCount
    • fallbackClassRPCSender

      private final eu.cloudnetservice.driver.network.rpc.RPCSender fallbackClassRPCSender
    • additionalInstanceFactories

      private final RPCInternalInstanceFactory[] additionalInstanceFactories
    • constructorMethodHandle

      private final MethodHandle constructorMethodHandle
  • Constructor Details

    • RPCInternalInstanceFactory

      private RPCInternalInstanceFactory()
      Internal constructor for TempRPCInternalInstanceFactory, do not use outside that implementation.
    • RPCInternalInstanceFactory

      private RPCInternalInstanceFactory(int userArgCount, @NonNull @NonNull Runnable allocationNotifier, @NonNull @NonNull eu.cloudnetservice.driver.network.rpc.RPCSender fallbackClassRPCSender, @NonNull @NonNull RPCInternalInstanceFactory[] additionalInstanceFactories, @NonNull @NonNull MethodHandle constructorMethodHandle)
      Constructs a new internal instance factory.
      Parameters:
      userArgCount - the count of arguments that are additionally supplied by the user.
      allocationNotifier - a runnable to run every time an instance of the class is allocated.
      fallbackClassRPCSender - the rpc sender instance to use for rpc lookups in the target class.
      additionalInstanceFactories - additional instance factories required for chained rpc constructions.
      constructorMethodHandle - the method handle for the constructor to invoke for construction requests.
      Throws:
      NullPointerException - if one of the given parameters is null.
  • Method Details

    • make

      @NonNull public static @NonNull RPCInternalInstanceFactory make(int userArgCount, @NonNull MethodHandles.Lookup lookup, @NonNull @NonNull Runnable allocationNotifier, @NonNull @NonNull eu.cloudnetservice.driver.network.rpc.RPCSender classRPCSender, @NonNull @NonNull RPCInternalInstanceFactory[] additionalInstanceFactories)
      Constructs a new internal instance factory for the generated rpc api implementation class.
      Parameters:
      userArgCount - the count of arguments that are additionally supplied by the user.
      lookup - a lookup method handle targeting the generated implementation class.
      allocationNotifier - a runnable to run every time an instance of the class is allocated.
      classRPCSender - the rpc sender instance to use for rpc lookups in the target class.
      additionalInstanceFactories - additional instance factories required for chained rpc constructions.
      Returns:
      a new internal instance factory to construct a generated api implementation.
      Throws:
      NullPointerException - if one of the given parameters is null.
      IllegalStateException - if the target constructor is missing in the generated class.
    • constructInstance

      @NonNull public @NonNull Object constructInstance(@Nullable @Nullable eu.cloudnetservice.driver.network.rpc.ChainableRPC baseRPC, @NonNull @NonNull Supplier<eu.cloudnetservice.driver.network.NetworkChannel> channelSupplier, @NonNull @NonNull Object[] additionalConstructorArgs)
      Constructs a new instance of the generated rpc class.
      Parameters:
      baseRPC - the base RPC to use for chained api calls.
      channelSupplier - the channel supplier to which all network requests should be sent.
      additionalConstructorArgs - the array of additional constructor args to supply to the generated class.
      Returns:
      a constructed instance of the generated rpc class implementation.
      Throws:
      NullPointerException - if the given channel supplier or additional args is null.
      IllegalArgumentException - if the given additional constructor args mismatch the expected count.
      IllegalStateException - if the construction of the generated class is not possible.
    • constructInstance

      @NonNull public @NonNull Object constructInstance(@Nullable @Nullable eu.cloudnetservice.driver.network.rpc.ChainableRPC baseRPC, @Nullable @Nullable eu.cloudnetservice.driver.network.rpc.RPCSender classRPCSender, @NonNull @NonNull Supplier<eu.cloudnetservice.driver.network.NetworkChannel> channelSupplier, @NonNull @NonNull Object[] additionalConstructorArgs)
      Constructs a new instance of the generated rpc class.
      Parameters:
      baseRPC - the base RPC to use for chained api calls.
      classRPCSender - the rpc sender to use instead of the fallback one given to this factory.
      channelSupplier - the channel supplier to which all network requests should be sent.
      additionalConstructorArgs - the array of additional constructor args to supply to the generated class.
      Returns:
      a constructed instance of the generated rpc class implementation.
      Throws:
      NullPointerException - if the given channel supplier or additional args is null.
      IllegalArgumentException - if the given additional constructor args mismatch the expected count.
      IllegalStateException - if the construction of the generated class is not possible.
    • replaceSpecialArgs

      private void replaceSpecialArgs(Object[] args, @Nullable @Nullable eu.cloudnetservice.driver.network.rpc.ChainableRPC baseRPC, @NonNull @NonNull Supplier<eu.cloudnetservice.driver.network.NetworkChannel> channelSupplier)
      Replaces all requests for special arguments in the given target array.
      Parameters:
      args - the argument to array to replace the special values in.
      baseRPC - the base RPC to use for chained api calls.
      channelSupplier - the channel supplier to which all network requests should be sent.
      Throws:
      NullPointerException - if the given args array or base rpc is null.