Package jadex.bridge.service.component
Class BasicServiceInvocationHandler
- java.lang.Object
-
- jadex.bridge.service.component.BasicServiceInvocationHandler
-
- All Implemented Interfaces:
ISwitchCall
,java.lang.reflect.InvocationHandler
public class BasicServiceInvocationHandler extends java.lang.Object implements java.lang.reflect.InvocationHandler, ISwitchCall
Basic service invocation interceptor. It has a multi collection of interceptors per method. Executes the list of interceptors one by one. In case no handler can be found a fallback handler is used.
-
-
Field Summary
Fields Modifier and Type Field Description protected IInternalAccess
comp
The internal access.protected java.util.List<IServiceInvocationInterceptor>
interceptors
The list of interceptors.protected java.util.logging.Logger
logger
The logger for errors/warnings.protected static java.util.Map<java.lang.Object,IService>
pojoproxies
The pojo service map (pojo -> proxy).static java.lang.String
PROXYTYPE_DECOUPLED
The (default) decoupled proxy type (decouples from caller thread to component thread).static java.lang.String
PROXYTYPE_DIRECT
The direct proxy type (supports custom interceptors, but uses caller thread).static java.lang.String
PROXYTYPE_RAW
The raw proxy type (i.e.protected boolean
required
The flag if the proxy is required (provided otherwise).protected java.lang.Object
service
The service.protected IServiceIdentifier
sid
The service identifier.protected boolean
switchcall
The flag if a switchcall should be done.
-
Constructor Summary
Constructors Constructor Description BasicServiceInvocationHandler(IInternalAccess comp, ServiceInfo service, java.util.logging.Logger logger)
Create a new invocation handler.BasicServiceInvocationHandler(IInternalAccess comp, IServiceIdentifier sid, java.util.logging.Logger logger, boolean required)
Create a new invocation handler.BasicServiceInvocationHandler(IInternalAccess comp, IService service, java.util.logging.Logger logger, boolean required)
Create a new invocation handler.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFirstServiceInterceptor(IServiceInvocationInterceptor interceptor)
Add an interceptor.static void
addPojoServiceProxy(java.lang.Object pojo, IService proxy)
Add a service proxy.protected static void
addProvidedInterceptors(BasicServiceInvocationHandler handler, java.lang.Object service, IServiceInvocationInterceptor[] ics, IInternalAccess ia, java.lang.String proxytype, boolean monitoring, IServiceIdentifier sid)
Add the standard and custom interceptors.void
addServiceInterceptor(IServiceInvocationInterceptor interceptor)
Add an interceptor.void
addServiceInterceptor(IServiceInvocationInterceptor interceptor, int pos)
Add an interceptor.static IInternalService
createDelegationProvidedServiceProxy(IInternalAccess ia, IServiceIdentifier sid, RequiredServiceInfo info, RequiredServiceBinding binding, java.lang.ClassLoader classloader, boolean realtime)
Static method for creating a delegation service proxy for provided service that is not offered by the component itself.protected static BasicServiceInvocationHandler
createProvidedHandler(java.lang.String name, IInternalAccess ia, java.lang.Class<?> type, java.lang.Object service, ProvidedServiceInfo info)
Create a basic invocation handler for a provided service.static IInternalService
createProvidedServiceProxy(IInternalAccess ia, java.lang.Object service, java.lang.String name, java.lang.Class<?> type, IServiceInvocationInterceptor[] ics, boolean monitoring, ProvidedServiceInfo info)
Static method for creating a standard service proxy for a provided service.static IService
createRequiredServiceProxy(IInternalAccess ia, IService service, IRequiredServiceFetcher fetcher, RequiredServiceInfo info, RequiredServiceBinding binding, boolean realtime)
Static method for creating a standard service proxy for a required service.boolean
equals(java.lang.Object obj)
Test if two objects are equal.java.lang.Object
getDomainService()
Get the domain service.IServiceInvocationInterceptor[]
getInterceptors()
Get interceptors.static IService
getPojoServiceProxy(java.lang.Object pojo)
Get the proxy of a pojo service.java.lang.Object
getService()
Get the service.IServiceIdentifier
getServiceIdentifier()
Get the sid.int
hashCode()
Return the hash code.java.lang.Object
invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
A proxy method has been invoked.static boolean
isProvidedServiceProxy(java.lang.Object service)
Test if a service is a provided service proxy.boolean
isRequired()
Check if the handler is for a required service proxy.static boolean
isRequiredServiceProxy(java.lang.Object service)
Test if a service is a required service proxy.boolean
isSwitchCall()
Check if a switch call should be done.static void
removePojoServiceProxy(IServiceIdentifier sid)
Remove a pojo - proxy pair.void
removeServiceInterceptor(IServiceInvocationInterceptor interceptor)
Remove an interceptor.java.lang.String
toString()
Get a string representation.
-
-
-
Field Detail
-
PROXYTYPE_RAW
public static final java.lang.String PROXYTYPE_RAW
The raw proxy type (i.e. no proxy).- See Also:
- Constant Field Values
-
PROXYTYPE_DIRECT
public static final java.lang.String PROXYTYPE_DIRECT
The direct proxy type (supports custom interceptors, but uses caller thread).- See Also:
- Constant Field Values
-
PROXYTYPE_DECOUPLED
public static final java.lang.String PROXYTYPE_DECOUPLED
The (default) decoupled proxy type (decouples from caller thread to component thread).- See Also:
- Constant Field Values
-
comp
protected IInternalAccess comp
The internal access.
-
sid
protected IServiceIdentifier sid
The service identifier.
-
service
protected java.lang.Object service
The service.
-
logger
protected java.util.logging.Logger logger
The logger for errors/warnings.
-
interceptors
protected java.util.List<IServiceInvocationInterceptor> interceptors
The list of interceptors.
-
required
protected boolean required
The flag if the proxy is required (provided otherwise).
-
switchcall
protected boolean switchcall
The flag if a switchcall should be done.
-
pojoproxies
protected static java.util.Map<java.lang.Object,IService> pojoproxies
The pojo service map (pojo -> proxy).
-
-
Constructor Detail
-
BasicServiceInvocationHandler
public BasicServiceInvocationHandler(IInternalAccess comp, IServiceIdentifier sid, java.util.logging.Logger logger, boolean required)
Create a new invocation handler.
-
BasicServiceInvocationHandler
public BasicServiceInvocationHandler(IInternalAccess comp, IService service, java.util.logging.Logger logger, boolean required)
Create a new invocation handler.
-
BasicServiceInvocationHandler
public BasicServiceInvocationHandler(IInternalAccess comp, ServiceInfo service, java.util.logging.Logger logger)
Create a new invocation handler.
-
-
Method Detail
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
A proxy method has been invoked.- Specified by:
invoke
in interfacejava.lang.reflect.InvocationHandler
- Throws:
java.lang.Throwable
-
getServiceIdentifier
public IServiceIdentifier getServiceIdentifier()
Get the sid.- Returns:
- the sid.
-
getService
public java.lang.Object getService()
Get the service.- Returns:
- The service.
-
getDomainService
public java.lang.Object getDomainService()
Get the domain service.- Returns:
- The domain service.
-
addFirstServiceInterceptor
public void addFirstServiceInterceptor(IServiceInvocationInterceptor interceptor)
Add an interceptor. Must be synchronized as invoke() is called from arbitrary threads.
-
addServiceInterceptor
public void addServiceInterceptor(IServiceInvocationInterceptor interceptor, int pos)
Add an interceptor. Must be synchronized as invoke() is called from arbitrary threads.
-
addServiceInterceptor
public void addServiceInterceptor(IServiceInvocationInterceptor interceptor)
Add an interceptor. Must be synchronized as invoke() is called from arbitrary threads.
-
removeServiceInterceptor
public void removeServiceInterceptor(IServiceInvocationInterceptor interceptor)
Remove an interceptor. Must be synchronized as invoke() is called from arbitrary threads.
-
getInterceptors
public IServiceInvocationInterceptor[] getInterceptors()
Get interceptors. Must be synchronized as invoke() is called from arbitrary threads.
-
hashCode
public int hashCode()
Return the hash code.- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Test if two objects are equal.- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
Get a string representation.- Overrides:
toString
in classjava.lang.Object
-
createProvidedServiceProxy
public static IInternalService createProvidedServiceProxy(IInternalAccess ia, java.lang.Object service, java.lang.String name, java.lang.Class<?> type, IServiceInvocationInterceptor[] ics, boolean monitoring, ProvidedServiceInfo info)
Static method for creating a standard service proxy for a provided service.
-
createProvidedHandler
protected static BasicServiceInvocationHandler createProvidedHandler(java.lang.String name, IInternalAccess ia, java.lang.Class<?> type, java.lang.Object service, ProvidedServiceInfo info)
Create a basic invocation handler for a provided service.
-
addProvidedInterceptors
protected static void addProvidedInterceptors(BasicServiceInvocationHandler handler, java.lang.Object service, IServiceInvocationInterceptor[] ics, IInternalAccess ia, java.lang.String proxytype, boolean monitoring, IServiceIdentifier sid)
Add the standard and custom interceptors.
-
createDelegationProvidedServiceProxy
public static IInternalService createDelegationProvidedServiceProxy(IInternalAccess ia, IServiceIdentifier sid, RequiredServiceInfo info, RequiredServiceBinding binding, java.lang.ClassLoader classloader, boolean realtime)
Static method for creating a delegation service proxy for provided service that is not offered by the component itself.
-
createRequiredServiceProxy
public static IService createRequiredServiceProxy(IInternalAccess ia, IService service, IRequiredServiceFetcher fetcher, RequiredServiceInfo info, RequiredServiceBinding binding, boolean realtime)
Static method for creating a standard service proxy for a required service.
-
addPojoServiceProxy
public static void addPojoServiceProxy(java.lang.Object pojo, IService proxy)
Add a service proxy.- Parameters:
pojo
- The pojo.proxy
- The proxy.
-
removePojoServiceProxy
public static void removePojoServiceProxy(IServiceIdentifier sid)
Remove a pojo - proxy pair.- Parameters:
sid
- The service identifier.
-
getPojoServiceProxy
public static IService getPojoServiceProxy(java.lang.Object pojo)
Get the proxy of a pojo service.- Parameters:
pojo
- The pojo service.- Returns:
- The proxy of the service.
-
isSwitchCall
public boolean isSwitchCall()
Check if a switch call should be done.- Specified by:
isSwitchCall
in interfaceISwitchCall
- Returns:
- True, if switch should be done.
-
isRequired
public boolean isRequired()
Check if the handler is for a required service proxy.
-
isRequiredServiceProxy
public static boolean isRequiredServiceProxy(java.lang.Object service)
Test if a service is a required service proxy.- Parameters:
service
- The service.- Returns:
- True, if is required service proxy.
-
isProvidedServiceProxy
public static boolean isProvidedServiceProxy(java.lang.Object service)
Test if a service is a provided service proxy.- Parameters:
service
- The service.- Returns:
- True, if is provided service proxy.
-
-