Class RPCClassMetadata
java.lang.Object
eu.cloudnetservice.driver.impl.network.rpc.introspec.RPCClassMetadata
Collected metadata for classes that can be called via rpc.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.google.common.collect.Table<String, String, DefaultRPCMethodMetadata> private final Durationprivate final Class<?> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateRPCClassMetadata(@NonNull Class<?> target) Constructs a new class metadata instance with the given target class.privateRPCClassMetadata(@NonNull Class<?> target, @Nullable Duration rpcTimeout, @NonNull com.google.common.collect.Table<String, String, DefaultRPCMethodMetadata> methods) Constructs a full instance of a class metadata from the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionGet the default rpc timeout that should be applied to all methods in the target class.findMethod(@NonNull String name, @NonNull TypeDescriptor typeDescriptor) Returns the method that matches the given name and type descriptor, or null if no such method exists.Returns all methods that are known to this class metadata that match the given filter.freeze()Freezes this metadata view which means that further modifications to the underlying data structures will return in an exception and not succeed.static @NonNull RPCClassMetadataintrospect(@NonNull Class<?> target) Introspects all methods in the class hierarchy of the given target class and wraps them into a class metadata.private voidIntrospects the methods located in the given class.private voidintrospectSuper(@NonNull Class<?> target, @NonNull Set<Class<?>> visitedClasses, @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.methods()Get an immutable collection of all methods that can be used for rpc in the target class.private booleanmethodVisibleToRoot(@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.parseRPCTimeout(@Nullable eu.cloudnetservice.driver.network.rpc.annotation.RPCTimeout annotation) Parses the given rpc timeout annotation.Get the class that is targeted by this rpc class metadata.voidunregisterMethod(@NonNull String name, @NonNull TypeDescriptor typeDescriptor) Unregisters the given method by name and descriptor for this class, for example to specifically ignore it.(package private) static voidvalidateTargetClass(@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.
-
Field Details
-
STANDARD_IGNORED_METHOD_FILTER
-
target
-
rpcTimeout
-
methods
-
-
Constructor Details
-
RPCClassMetadata
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
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
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
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
-
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 usingRPCTimeouton 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
@NonNull public @NonNull List<DefaultRPCMethodMetadata> findMethods(@NonNull @NonNull Predicate<DefaultRPCMethodMetadata> filter) 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
@Nullable public @Nullable DefaultRPCMethodMetadata findMethod(@NonNull @NonNull String name, @NonNull @NonNull TypeDescriptor typeDescriptor) 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.
-