Class InvocationHandler<T>
- java.lang.Object
-
- de.aristaflow.adept2.base.communication.invocation.InvocationHandler<T>
-
- Type Parameters:
T
- The type is the interface this invocation handler will handle invocations for, i.e. the type of the service (getComponent()
) and the type of the stub representing the service.
- All Implemented Interfaces:
InvocationHandler
public class InvocationHandler<T> extends Object implements InvocationHandler
This InvocationHandler handles invocations to a ADEPT2 service through the API-Interface designated by the type parameterT
in a distributed environment. It catches the API method calls to the proxy object that represents the service to the caller (i. e. the client) and delegates them to thecommunication submodule
that is responsible for doing the remote calls on the remote service the proxy object is a proxy for.If a callback object is passed within a parameter to the requested method, then the handler creates a callback URI, associates this URI with the passed callback object and passes this URI to the skeleton responsible for the execution of the requested method on server side instead of the callback object itself.
With this URI the receiver skeleton can create a stub/proxy object intended to do remote callback invocations on the callback object associated with the given callback URI.
The invocation handler only delegates calls to methods of the service interface, which are neither annotated with
ProxyIgnore
nor withProxyFollow
.Calls to methods which are annotated with
ProxyIgnore
, are dismissed.Calls to methods which are annotated with
Replaces
will be replaced by the method described in the annotation. All further then applies to the replacing method, i. e. using cached values for an immutable (replacing) method or following the proxy. Replacing methods may switch from virtual to static invocation (i. e. from an instance method to a class method). In this case the parameter values are shifted by one and the first parameter will be the provided object instance. The replacing method has to consider this appropriately, i. e. the first parameter has to be of the appropriate type (of the object instance).
Additionally, replacing may take place locally. In this case the method call on the proxy will not be forwarded but executed locally instead of remote.The return value of methods annotated with
Immutable
will cached internally using aWeakReference
. Consecutive calls will then use this cached value if it is still present.Calls to methods which are annotated with
ProxyFollow
, are replied with another proxy object.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
callback
Whether this invocation handler is a callback object, that is, it is a stub that has been created for a callback parameter in an invocation message.protected Class<T>
iface
The interface, this is a proxy for.protected long
lazyTime
The time span in milliseconds which a lazy method is considered immutable.protected Logger
logger
My logger.protected Map<Class<?>,Boolean>
proxyAnnotCache
The cache containing whether a class has a proxy annotation (ProxyAllow
,ProxyCallback
orServerSideProxyAllow
) or implementsServerSideProxy
.protected URI
registeredIdentifier
The original (logical) URI identifying the remote service to call, in case a URI mapping was applied on the remote identifier URI.protected URI
remoteIdentifier
The (physical) service URI of the ADEPT2 component this object is a proxy for.
-
Constructor Summary
Constructors Modifier Constructor Description protected
InvocationHandler(InvocationTarget invTarget, AtomicLong invId, long lazyTime, URI remoteObjectIdentifier, URI registeredIdentifier, boolean callback, Stack<Method> preceder, long cachingRemItInitAliveTime, long cachingRemItAliveTimeExt, Map<Class<?>,Boolean> proxyAnnotCache, Logger logger)
Create an invocation handler for the configured component name, following the provided methods to the interface this is a proxy for.protected
InvocationHandler(InvocationTarget invTarget, AtomicLong invId, long lazyTime, URI remoteObjectIdentifier, URI registeredIdentifier, boolean callback, Stack<Method> preceder, Map<Class<?>,Boolean> proxyAnnotCache, Logger logger)
Deprecated, for removal: This API element is subject to removal in a future version.InvocationHandler(InvocationTarget invTarget, AtomicLong invId, long lazyTime, URI remoteIdentifier, URI registeredIdentifier, Class<T> remoteInterface, boolean callback, long cachingRemItInitAliveTime, long cachingRemItAliveTimeExt, Map<Class<?>,Boolean> proxyAnnotCache, Logger logger)
Create a new invocation handler.InvocationHandler(InvocationTarget invTarget, AtomicLong invId, long lazyTime, URI remoteIdentifier, URI registeredIdentifier, Class<T> remoteInterface, boolean callback, Map<Class<?>,Boolean> proxyAnnotCache, Logger logger)
Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
getComponent()
URI
getRemoteIdentifier()
Gets the (physical) service URI of the ADEPT2 component this object is a proxy for.Object
invoke(Object proxyPar, Method method, Object[] args)
protected long
nextInvocationId()
Generates unique invocation IDs.
-
-
-
Field Detail
-
logger
protected final Logger logger
My logger.
-
proxyAnnotCache
protected final Map<Class<?>,Boolean> proxyAnnotCache
The cache containing whether a class has a proxy annotation (ProxyAllow
,ProxyCallback
orServerSideProxyAllow
) or implementsServerSideProxy
. This is shared across different invocation handlers.null
if no caching should be used.- See Also:
checkIface(Class)
-
lazyTime
protected final long lazyTime
The time span in milliseconds which a lazy method is considered immutable.
-
remoteIdentifier
protected final URI remoteIdentifier
The (physical) service URI of the ADEPT2 component this object is a proxy for.
-
registeredIdentifier
protected final URI registeredIdentifier
The original (logical) URI identifying the remote service to call, in case a URI mapping was applied on the remote identifier URI.
-
callback
protected final boolean callback
Whether this invocation handler is a callback object, that is, it is a stub that has been created for a callback parameter in an invocation message.
-
-
Constructor Detail
-
InvocationHandler
@Deprecated(since="15.0.0", forRemoval=true) public InvocationHandler(InvocationTarget invTarget, AtomicLong invId, long lazyTime, URI remoteIdentifier, URI registeredIdentifier, Class<T> remoteInterface, boolean callback, Map<Class<?>,Boolean> proxyAnnotCache, Logger logger)
Deprecated, for removal: This API element is subject to removal in a future version.Create a new invocation handler.- Parameters:
invTarget
- The invocation target providing the callback export and the invocation delegate to send messages to.invId
- The count of each invocation to each have its unique ID.lazyTime
- The time span in milliseconds which a lazy method is considered immutable.remoteIdentifier
- The (physical) service URI of the ADEPT2 component this object is a proxy for.remoteInterface
- The interface of the ADEPT2 component, withT
defining the generic type of this handler.registeredIdentifier
- The original (logical) URI identifying the remote service to call, in case a URI mapping was applied on the original URI.callback
- Whether this invocation handler is a callback object, that is, it is a stub that has been created for a callback parameter in an invocation message.proxyAnnotCache
- The cache containing whether a class has a proxy annotation (ProxyAllow
,ProxyCallback
orServerSideProxyAllow
) or implementsServerSideProxy
. This is shared across different invocation handlers.null
if no caching should be used.logger
- The class-specific logger for this invocation handler.
-
InvocationHandler
public InvocationHandler(InvocationTarget invTarget, AtomicLong invId, long lazyTime, URI remoteIdentifier, URI registeredIdentifier, Class<T> remoteInterface, boolean callback, long cachingRemItInitAliveTime, long cachingRemItAliveTimeExt, Map<Class<?>,Boolean> proxyAnnotCache, Logger logger)
Create a new invocation handler.- Parameters:
invTarget
- The invocation target providing the callback export and the invocation delegate to send messages to.invId
- The count of each invocation to each have its unique ID.lazyTime
- The time span in milliseconds which a lazy method is considered immutable.remoteIdentifier
- The service URI of the ADEPT2 component this object is a proxy for.remoteInterface
- The interface of the ADEPT2 component, withT
defining the generic type of this handler.registeredIdentifier
- The original URI identifying the remote service to call, in case a URI mapping was applied on the original URI.callback
- Whether this invocation handler is a callback object, that is, it is a stub that has been created for a callback parameter in an invocation message.cachingRemItInitAliveTime
- The time in milliseconds to keep a caching remote iterator created for each received remote iterator alive after creating it and before accessing it.cachingRemItAliveTimeExt
- The time in milliseconds to extend the alive time of a caching remote iterator created for each received remote iterator.proxyAnnotCache
- The cache containing whether a class has a proxy annotation (ProxyAllow
,ProxyCallback
orServerSideProxyAllow
) or implementsServerSideProxy
. This is shared across different invocation handlers.null
if no caching should be used.logger
- The class-specific logger for this invocation handler.
-
InvocationHandler
@Deprecated(since="15.0.0", forRemoval=true) protected InvocationHandler(InvocationTarget invTarget, AtomicLong invId, long lazyTime, URI remoteObjectIdentifier, URI registeredIdentifier, boolean callback, Stack<Method> preceder, Map<Class<?>,Boolean> proxyAnnotCache, Logger logger)
Deprecated, for removal: This API element is subject to removal in a future version.Create an invocation handler for the configured component name, following the provided methods to the interface this is a proxy for.Invocation handler for
ProxyFollow
objects are created automatically within this class.- Parameters:
invTarget
- The invocation target providing the callback export and the invocation delegate to send messages to.invId
- The count of each invocation to each have its unique ID.lazyTime
- The time span in milliseconds which a lazy method is considered immutable.remoteObjectIdentifier
- The (physical) service URI of the ADEPT2 component this object is a proxy for.registeredIdentifier
- The original (logical) URI identifying the remote service to call, in case a URI mapping was applied on the remote object identifier.callback
- Whether this invocation handler is a callback object, that is, it is a stub that has been created for a callback parameter in an invocation message.preceder
- The stack of methods of the component, to reach the object this is a proxy for.proxyAnnotCache
- The cache containing whether a class has a proxy annotation (ProxyAllow
,ProxyCallback
orServerSideProxyAllow
) or implementsServerSideProxy
. This is shared across different invocation handlers.null
if no caching should be used.logger
- The class-specific logger for this invocation handler.
-
InvocationHandler
protected InvocationHandler(InvocationTarget invTarget, AtomicLong invId, long lazyTime, URI remoteObjectIdentifier, URI registeredIdentifier, boolean callback, Stack<Method> preceder, long cachingRemItInitAliveTime, long cachingRemItAliveTimeExt, Map<Class<?>,Boolean> proxyAnnotCache, Logger logger)
Create an invocation handler for the configured component name, following the provided methods to the interface this is a proxy for.Invocation handler for
ProxyFollow
objects are created automatically within this class.- Parameters:
invTarget
- The invocation target providing the callback export and the invocation delegate to send messages to.invId
- The count of each invocation to each have its unique ID.lazyTime
- The time span in milliseconds which a lazy method is considered immutable.remoteObjectIdentifier
- The service URI of the ADEPT2 component this object is a proxy for.registeredIdentifier
- The original URI identifying the remote service to call, in case a URI mapping was applied on the remote object identifier.callback
- Whether this invocation handler is a callback object, that is, it is a stub that has been created for a callback parameter in an invocation message.preceder
- The stack of methods of the component, to reach the object this is a proxy for.cachingRemItInitAliveTime
- The time in milliseconds to keep a caching remote iterator created for each received remote iterator alive after creating it and before accessing it.cachingRemItAliveTimeExt
- The time in milliseconds to extend the alive time of a caching remote iterator created for each received remote iterator.proxyAnnotCache
- The cache containing whether a class has a proxy annotation (ProxyAllow
,ProxyCallback
orServerSideProxyAllow
) or implementsServerSideProxy
. This is shared across different invocation handlers.null
if no caching should be used.logger
- The class-specific logger for this invocation handler.
-
-
Method Detail
-
getRemoteIdentifier
public URI getRemoteIdentifier()
Gets the (physical) service URI of the ADEPT2 component this object is a proxy for.- Returns:
- The (physical) service URI of the ADEPT2 component this object is a proxy for.
-
nextInvocationId
protected long nextInvocationId()
Generates unique invocation IDs.- Returns:
- A new invocation ID.
-
-