Interface RPCFactory
- All Known Implementing Classes:
DefaultRPCFactory
- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionGet the default data buf factory used by this factory if no other data buf factory is supplied to a factory method.Get the default object mapper used by this factory if no other mapper is supplied to a factory method.<T> @NonNull InstanceFactory<T>generateRPCBasedApi(@NonNull Class<T> baseClass, @NonNull GenerationContext context) Generates an api implementation for the given base class, invoking all of its method using rpc.<T> @NonNull ChainInstanceFactory<T>generateRPCChainBasedApi(@NonNull RPCSender baseSender, @NonNull Class<T> chainBaseClass, @NonNull GenerationContext context) Generates an api implementation for the given base class, invoking all of its method using a chained rpc call.<T> @NonNull ChainInstanceFactory<T>generateRPCChainBasedApi(@NonNull RPCSender baseSender, @NonNull String baseCallerMethod, @NonNull Class<T> chainBaseClass, @NonNull GenerationContext context) Generates an api implementation for the given base class, invoking all of its method using a chained rpc call.newHandler(@NonNull Class<?> clazz, @Nullable Object binding) Constructs a new rpc handler for the given class.newHandler(@NonNull Class<?> clazz, @Nullable Object binding, @NonNull ObjectMapper objectMapper, @NonNull DataBufFactory dataBufFactory) Constructs a new rpc handler for the given class.providerForClass(@Nullable NetworkComponent component, @NonNull Class<?> clazz) Constructs a new rpc sender for the given class.providerForClass(@Nullable NetworkComponent component, @NonNull Class<?> clazz, @NonNull ObjectMapper objectMapper, @NonNull DataBufFactory dataBufFactory) Constructs a new rpc sender for the given class.
-
Method Details
-
defaultObjectMapper
Get the default object mapper used by this factory if no other mapper is supplied to a factory method.- Returns:
- the default object mapper of this factory.
-
defaultDataBufFactory
Get the default data buf factory used by this factory if no other data buf factory is supplied to a factory method.- Returns:
- the default data buf factory of this factory.
-
providerForClass
@NonNull @NonNull RPCSender providerForClass(@Nullable @Nullable NetworkComponent component, @NonNull @NonNull Class<?> clazz) Constructs a new rpc sender for the given class.- Parameters:
component- the associated network component, or null if not associated.clazz- the class which the handler should handler.- Returns:
- a new rpc sender targeting the given class.
- Throws:
NullPointerException- if the given target class is null.
-
providerForClass
@NonNull @NonNull RPCSender providerForClass(@Nullable @Nullable NetworkComponent component, @NonNull @NonNull Class<?> clazz, @NonNull @NonNull ObjectMapper objectMapper, @NonNull @NonNull DataBufFactory dataBufFactory) Constructs a new rpc sender for the given class.- Parameters:
component- the associated network component, or null if not associated.clazz- the class which the handler should handler.objectMapper- the object mapper to use for argument (de-) serialization.dataBufFactory- the data buf factory to use for buffer allocation.- Returns:
- a new rpc sender targeting the given class.
- Throws:
NullPointerException- if either the given class, mapper or buffer factory is null.
-
generateRPCBasedApi
@NonNull <T> @NonNull InstanceFactory<T> generateRPCBasedApi(@NonNull @NonNull Class<T> baseClass, @NonNull @NonNull GenerationContext context) Generates an api implementation for the given base class, invoking all of its method using rpc. This method only overrides methods which are abstract in the given class tree. In other words, if you're passing an implementation which has all methods which need to be processed locally already done, no rpc based method implementation will be generated for the class.The defined base class in the context must define one of the following constructors:
- A constructor with no arguments, or
- A constructor taking exactly one argument, a rpc sender instance.
This method will cache the result of the generation, calling this method twice will only result in two different instances in the same class, but only if the given generation context did not change between the calls.
- Type Parameters:
T- the type which gets generated.- Parameters:
baseClass- the base class to generate the class methods based on.context- the context of the class generation, holding the options for it.- Returns:
- an implementation of the given class which has all abstract methods rpc based implemented.
- Throws:
NullPointerException- if the given base class or generation context is null.ClassCreationException- if the generator is unable to generate an implementation of the class.
-
generateRPCChainBasedApi
@NonNull <T> @NonNull ChainInstanceFactory<T> generateRPCChainBasedApi(@NonNull @NonNull RPCSender baseSender, @NonNull @NonNull Class<T> chainBaseClass, @NonNull @NonNull GenerationContext context) Generates an api implementation for the given base class, invoking all of its method using a chained rpc call. The base rpc is discovered using the given rpc sender and the name of the method which called the method. The invoker of the method must be direct (1 up in the local stack trace). If the method name cannot be determined by the stack, usegenerateRPCChainBasedApi(RPCSender, String, Class, GenerationContext)to supply the name of the method to use instead. This method only overrides methods which are abstract in the given class tree. In other words, if you're passing an implementation which has all methods which need to be processed locally already done, no rpc based method implementation will be generated for the class.If the base class defined in the invocation context needs arguments to be supplied, they must get passed to the created instance factory. Note: the constructor parameters are not required to match the parameters supplied to the base rpc call.
This method will cache the result of the generation, calling this method twice will only result in two different instances in the same class, but only if the given generation context and the calling method name did not change between the calls.
- Type Parameters:
T- the type which gets generated.- Parameters:
baseSender- the rpc sender for the base class from which the chain should start.chainBaseClass- the base class from which methods one step into the chain should get called.context- the context of the class generation, holding the options for it.- Returns:
- a factory which is capable to create new instances of the given chain base class, for rpc chain calls.
- Throws:
NullPointerException- if the given base sender, chain base class or generation context is null.ClassCreationException- if the generator is unable to generate an implementation of the class.
-
generateRPCChainBasedApi
@NonNull <T> @NonNull ChainInstanceFactory<T> generateRPCChainBasedApi(@NonNull @NonNull RPCSender baseSender, @NonNull @NonNull String baseCallerMethod, @NonNull @NonNull Class<T> chainBaseClass, @NonNull @NonNull GenerationContext context) Generates an api implementation for the given base class, invoking all of its method using a chained rpc call. The base rpc is discovered using the given rpc sender and the given method name. This method only overrides methods which are abstract in the given class tree. In other words, if you're passing an implementation which has all methods which need to be processed locally already done, no rpc based method implementation will be generated for the class.If the base class defined in the invocation context needs arguments to be supplied, they must get passed to the created instance factory. Note: the constructor parameters are not required to match the parameters supplied to the base rpc call.
This method will cache the result of the generation, calling this method twice will only result in two different instances in the same class, but only if the given generation context and the calling method name did not change between the calls.
- Type Parameters:
T- the type which gets generated.- Parameters:
baseSender- the rpc sender for the base class from which the chain should start.baseCallerMethod- the name of the method to use to obtain the base instance to call the chain on.chainBaseClass- the base class from which methods one step into the chain should get called.context- the context of the class generation, holding the options for it.- Returns:
- a factory which is capable to create new instances of the given chain base class, for rpc chain calls.
- Throws:
NullPointerException- if the given base sender, method, chain base class or generation context is null.ClassCreationException- if the generator is unable to generate an implementation of the class.
-
newHandler
@NonNull @NonNull RPCHandler newHandler(@NonNull @NonNull Class<?> clazz, @Nullable @Nullable Object binding) Constructs a new rpc handler for the given class.- Parameters:
clazz- the class which the handler handles.binding- an optional instance binding for the handler, can be null if relying on contextual instances.- Returns:
- a new rpc handler for the given class.
- Throws:
NullPointerException- if the given target class is null.
-
newHandler
@NonNull @NonNull RPCHandler newHandler(@NonNull @NonNull Class<?> clazz, @Nullable @Nullable Object binding, @NonNull @NonNull ObjectMapper objectMapper, @NonNull @NonNull DataBufFactory dataBufFactory) Constructs a new rpc handler for the given class.- Parameters:
clazz- the class which the handler handles.binding- an optional instance binding for the handler, null if relying on contextual instances.objectMapper- the object mapper to use for argument (de-) serialization.dataBufFactory- the data buf factory to use for buffer allocation.- Returns:
- a new rpc handler for the given class.
- Throws:
NullPointerException- if either the given class, mapper or buffer factory is null.
-