Class RPCClassMetadata

java.lang.Object
eu.cloudnetservice.driver.impl.network.rpc.introspec.RPCClassMetadata

public final class RPCClassMetadata extends Object
Collected metadata for classes that can be called via rpc.
Since:
4.0
  • Field Details

  • Constructor Details

    • RPCClassMetadata

      private RPCClassMetadata(@NonNull @NonNull Class<?> target)
      Constructs a new class metadata instance with the given target class.
      Parameters:
      target - the target class of this metadata.
      Throws:
      NullPointerException - if the given target class is null.
    • RPCClassMetadata

      private RPCClassMetadata(@NonNull @NonNull Class<?> target, @Nullable @Nullable Duration rpcTimeout, @NonNull @NonNull com.google.common.collect.Table<String, String, DefaultRPCMethodMetadata> methods)
      Constructs a full instance of a class metadata from the given parameters.
      Parameters:
      target - the target class of this metadata.
      rpcTimeout - the class-wide default timeout of the rpc methods.
      methods - the methods that can be called via rpc in the given target class.
      Throws:
      NullPointerException - if the given target class or method table is null.
  • Method Details

    • parseRPCTimeout

      @Nullable static @Nullable Duration parseRPCTimeout(@Nullable @Nullable eu.cloudnetservice.driver.network.rpc.annotation.RPCTimeout annotation)
      Parses the given rpc timeout annotation. While some timeouts relly make no sense to apply, this method just assumes the user knows that he is doing and applies every timeout that is at least 1.
      Parameters:
      annotation - the annotation to parse, can be null.
      Returns:
      the parsed rpc timeout or null if the parsing wasn't applicable.
    • validateTargetClass

      static void validateTargetClass(@NonNull @NonNull Class<?> target)
      Validates that the given target class is actually visible to the outside world and not some sort of hidden class in which methods cannot be called anyway.
      Parameters:
      target - the class to validate.
      Throws:
      NullPointerException - if the given target class is null.
      IllegalArgumentException - if the given target class is some sort of hidden class.
    • introspect

      @NonNull public static @NonNull RPCClassMetadata introspect(@NonNull @NonNull Class<?> target)
      Introspects all methods in the class hierarchy of the given target class and wraps them into a class metadata.
      Parameters:
      target - the target class to introspect.
      Returns:
      the generated class metadata for the given class.
      Throws:
      NullPointerException - if the given target class is null.
      IllegalArgumentException - if some precondition, to ensure functionality with rpc, fails.
      IllegalStateException - if some precondition, to ensure functionality with rpc, fails.
    • introspectMethods

      private void introspectMethods(@NonNull @NonNull Class<?> target, @NonNull @NonNull Set<Class<?>> visitedClasses)
      Introspects the methods located in the given class. This method is recursively called for all classes and interfaces in the class hierarchy of the given target, hence the visited class set to prevent infinite loops due to circular class references.
      Parameters:
      target - the target class to introspect for methods that can be used with rpc.
      visitedClasses - the classes that were already introspected in the process.
      Throws:
      NullPointerException - if the given target class or visited class set is null.
      IllegalArgumentException - if some precondition, to ensure functionality with rpc, fails.
      IllegalStateException - if some precondition, to ensure functionality with rpc, fails.
    • methodVisibleToRoot

      private boolean methodVisibleToRoot(@NonNull @NonNull Method method)
      Validates that the given method is always visible to the root class and a possible nest mate class implementation of the root class. This means that the given method is either public or protected, or the defining class resides in the same package as the root class. Private members are always marked as not visible.
      Parameters:
      method - the method that should be checked for visibility.
      Returns:
      true if the given method is visible to the root type, false otherwise.
      Throws:
      NullPointerException - if the given method is null.
    • introspectSuper

      private void introspectSuper(@NonNull @NonNull Class<?> target, @NonNull @NonNull Set<Class<?>> visitedClasses, @NonNull @NonNull Consumer<Class<?>> introspectCallback)
      Calls the given introspect callback for the super class and super interfaces of the given target class unless they were already visited. This method marks a class as visited before calling the introspect callback on it.
      Parameters:
      target - the target class to visit the superclass and super interfaces of.
      visitedClasses - the classes that were already visited in the process.
      introspectCallback - the callback to call with the non-visited super classes.
      Throws:
      NullPointerException - if the given target class, visited class set or introspect callback is null.
    • targetClass

      @NonNull public @NonNull Class<?> targetClass()
      Get the class that is targeted by this rpc class metadata.
      Returns:
      the class that is targeted by this rpc class metadata.
    • defaultRPCTimeout

      @Nullable public @Nullable Duration defaultRPCTimeout()
      Get the default rpc timeout that should be applied to all methods in the target class. Can be null if no such timeout was explicitly declared using RPCTimeout on the target class.
      Returns:
      the default rpc timeout that should be applied to all methods in the target class, can be null.
    • methods

      Get an immutable collection of all methods that can be used for rpc in the target class.
      Returns:
      all methods that can be used for rpc in the target class.
    • freeze

      Freezes this metadata view which means that further modifications to the underlying data structures will return in an exception and not succeed. If this metadata is already frozen, the same instance is returned as no work needs to be done.
      Returns:
      this metadata but frozen.
    • unregisterMethod

      public void unregisterMethod(@NonNull @NonNull String name, @NonNull @NonNull TypeDescriptor typeDescriptor)
      Unregisters the given method by name and descriptor for this class, for example to specifically ignore it.
      Parameters:
      name - the name of the method to unregister.
      typeDescriptor - the type descriptor of the method to unregister.
      Throws:
      NullPointerException - if the given name or type descriptor is null.
      UnsupportedOperationException - if this class metadata is frozen.
    • findMethods

      Returns all methods that are known to this class metadata that match the given filter.
      Parameters:
      filter - the filter to apply to each method metadata known to this class metadata.
      Returns:
      the method metas that matched the given filter.
      Throws:
      NullPointerException - if the given filter is null.
    • findMethod

      Returns the method that matches the given name and type descriptor, or null if no such method exists.
      Parameters:
      name - the name of the method metadata to get.
      typeDescriptor - the type descriptor of the method metadata to get.
      Returns:
      the meta of the method with the given name and descriptor, of null if no such method exists.
      Throws:
      NullPointerException - if the given name or type descriptor is null.