Package jadex.bridge.service.component
Class ProvidedServicesComponentFeature
- java.lang.Object
-
- jadex.bridge.component.impl.AbstractComponentFeature
-
- jadex.bridge.service.component.ProvidedServicesComponentFeature
-
- All Implemented Interfaces:
IComponentFeature
,IExternalProvidedServicesFeature
,IProvidedServicesFeature
public class ProvidedServicesComponentFeature extends jadex.bridge.component.impl.AbstractComponentFeature implements IProvidedServicesFeature
Feature for provided services.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<IServiceIdentifier,ProvidedServiceInfo>
serviceinfos
The map of provided service infos.protected java.util.Map<IServiceIdentifier,MethodListenerHandler>
servicelisteners
The map of provided service infos.protected java.util.Map<java.lang.Class<?>,java.util.Collection<IInternalService>>
services
The map of platform services.
-
Constructor Summary
Constructors Constructor Description ProvidedServicesComponentFeature(IInternalAccess component, ComponentCreationInfo cinfo)
Factory method constructor for instance level.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addInterceptor(IServiceInvocationInterceptor interceptor, java.lang.Object service, int pos)
Add a service interceptor.void
addMethodInvocationListener(IServiceIdentifier sid, MethodInfo mi, IMethodInvocationListener listener)
Add a method invocation handler.protected void
addService(IInternalService service, ProvidedServiceInfo info)
Add a service.IFuture<java.lang.Void>
addService(java.lang.String name, java.lang.Class<?> type, java.lang.Object service)
Add a service to the platform.IFuture<java.lang.Void>
addService(java.lang.String name, java.lang.Class<?> type, java.lang.Object service, PublishInfo pi, ServiceScope scope)
Add a service to the platform.IFuture<java.lang.Void>
addService(java.lang.String name, java.lang.Class<?> type, java.lang.Object service, java.lang.String proxytype)
Add a service to the platform.IFuture<java.lang.Void>
addService(java.lang.String name, java.lang.Class<?> type, java.lang.String proxytype, IServiceInvocationInterceptor[] ics, java.lang.Object service, ProvidedServiceInfo info, ServiceScope scope)
Add a service to the component.IFuture<java.lang.Object>
createServiceImplementation(ProvidedServiceInfo info, IValueFetcher fetcher)
Create a service implementation from description.protected java.util.Collection<IInternalService>
getAllServices()
Get all services in a single collection.IServiceInvocationInterceptor[]
getInterceptors(java.lang.Object service)
Get the interceptors of a service.java.lang.Object
getProvidedService(IServiceIdentifier sid)
Get the provided service implementation object by id.<T> T
getProvidedService(java.lang.Class<T> clazz)
Get provided (declared) service.IService
getProvidedService(java.lang.String name)
Get provided (declared) service.protected ProvidedServiceInfo
getProvidedServiceInfo(IServiceIdentifier sid)
Get the provided service info for a service.java.lang.Object
getProvidedServiceRawImpl(IServiceIdentifier sid)
Get the provided service implementation object by id.<T> T
getProvidedServiceRawImpl(java.lang.Class<T> clazz)
Get the raw implementation of the provided service.java.lang.Object
getProvidedServiceRawImpl(java.lang.String name)
Get the provided service implementation object by name.<T> T[]
getProvidedServices(java.lang.Class<T> clazz)
Get provided (declared) service.static IFuture<IPublishService>
getPublishService(IInternalAccess instance, java.lang.String type, ServiceScope scope, java.util.Iterator<IPublishService> services)
Get the publish service for a publish type (e.g.java.util.Map<java.lang.Class<?>,java.util.Collection<IInternalService>>
getServices()
Get the services.IFuture<java.lang.Class<?>>
getServiceType(IServiceIdentifier sid)
IFuture<java.util.Collection<java.lang.Class<?>>>
getServiceTypes(IServiceIdentifier sid)
boolean
hasMethodListeners(IServiceIdentifier sid, MethodInfo mi)
Test if service and method has listeners.boolean
hasUserBody()
Check if the feature potentially executed user code in body.IFuture<java.lang.Void>
init()
Initialize the feature.protected IFuture<java.lang.Void>
initService(IInternalService is)
Init a service, i.e.protected IFuture<java.lang.Void>
initServices(java.util.Iterator<IInternalService> services)
Init the services one by one.void
notifyMethodListeners(IServiceIdentifier sid, boolean start, java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args, java.lang.Object callid, ServiceInvocationContext context)
Notify listeners that a service method has been called.void
removeInterceptor(IServiceInvocationInterceptor interceptor, java.lang.Object service)
Remove a service interceptor.void
removeMethodInvocationListener(IServiceIdentifier sid, MethodInfo mi, IMethodInvocationListener listener)
Remove a method invocation handler.protected void
removeService(IInternalService service)
Remove a service.IFuture<java.lang.Void>
removeService(IServiceIdentifier sid)
Removes a service from the platform (shutdowns also the service).IFuture<java.lang.Void>
serviceShutdowned(IInternalService service)
Called after a service has been shutdowned.IFuture<java.lang.Void>
serviceStarted(IInternalService service)
Called after a service has been started.IFuture<java.lang.Void>
setTags(IServiceIdentifier sid, java.lang.String... tags)
Sets the tags of a service.IFuture<java.lang.Void>
shutdown()
Called when the feature is shutdowned.protected IFuture<java.lang.Void>
shutdownServices(java.util.Iterator<IInternalService> services)
Shutdown the services one by one.
-
-
-
Field Detail
-
services
protected java.util.Map<java.lang.Class<?>,java.util.Collection<IInternalService>> services
The map of platform services.
-
servicelisteners
protected java.util.Map<IServiceIdentifier,MethodListenerHandler> servicelisteners
The map of provided service infos. (sid -> method listener)
-
serviceinfos
protected java.util.Map<IServiceIdentifier,ProvidedServiceInfo> serviceinfos
The map of provided service infos. (sid -> provided service info)
-
-
Constructor Detail
-
ProvidedServicesComponentFeature
public ProvidedServicesComponentFeature(IInternalAccess component, ComponentCreationInfo cinfo)
Factory method constructor for instance level.
-
-
Method Detail
-
init
public IFuture<java.lang.Void> init()
Initialize the feature.- Specified by:
init
in interfaceIComponentFeature
- Overrides:
init
in classjadex.bridge.component.impl.AbstractComponentFeature
-
hasUserBody
public boolean hasUserBody()
Check if the feature potentially executed user code in body. Allows blocking operations in user bodies by using separate steps for each feature. Non-user-body-features are directly executed for speed. If unsure just return true. ;-)- Specified by:
hasUserBody
in interfaceIComponentFeature
- Overrides:
hasUserBody
in classjadex.bridge.component.impl.AbstractComponentFeature
-
shutdown
public IFuture<java.lang.Void> shutdown()
Called when the feature is shutdowned.- Specified by:
shutdown
in interfaceIComponentFeature
- Overrides:
shutdown
in classjadex.bridge.component.impl.AbstractComponentFeature
-
addService
protected void addService(IInternalService service, ProvidedServiceInfo info)
Add a service.- Parameters:
service
- The service object.info
- The service info.
-
getProvidedServiceInfo
protected ProvidedServiceInfo getProvidedServiceInfo(IServiceIdentifier sid)
Get the provided service info for a service.- Parameters:
sid
- The service identifier.- Returns:
- The provided service info.
-
removeService
protected void removeService(IInternalService service)
Remove a service.- Parameters:
service
- The service object.info
- The service info.
-
createServiceImplementation
public IFuture<java.lang.Object> createServiceImplementation(ProvidedServiceInfo info, IValueFetcher fetcher)
Create a service implementation from description.
-
getAllServices
protected java.util.Collection<IInternalService> getAllServices()
Get all services in a single collection.
-
initServices
protected IFuture<java.lang.Void> initServices(java.util.Iterator<IInternalService> services)
Init the services one by one.
-
initService
protected IFuture<java.lang.Void> initService(IInternalService is)
Init a service, i.e. set the component (internal access) and call startService.
-
serviceStarted
public IFuture<java.lang.Void> serviceStarted(IInternalService service)
Called after a service has been started.
-
serviceShutdowned
public IFuture<java.lang.Void> serviceShutdowned(IInternalService service)
Called after a service has been shutdowned.
-
getPublishService
public static IFuture<IPublishService> getPublishService(IInternalAccess instance, java.lang.String type, ServiceScope scope, java.util.Iterator<IPublishService> services)
Get the publish service for a publish type (e.g. web service).- Parameters:
type
- The type.services
- The iterator of publish services (can be null).- Returns:
- The publish service.
-
shutdownServices
protected IFuture<java.lang.Void> shutdownServices(java.util.Iterator<IInternalService> services)
Shutdown the services one by one.
-
getProvidedService
public IService getProvidedService(java.lang.String name)
Get provided (declared) service.- Specified by:
getProvidedService
in interfaceIProvidedServicesFeature
- Parameters:
name
- The service name.- Returns:
- The service.
-
getProvidedServiceRawImpl
public <T> T getProvidedServiceRawImpl(java.lang.Class<T> clazz)
Get the raw implementation of the provided service.- Specified by:
getProvidedServiceRawImpl
in interfaceIProvidedServicesFeature
- Parameters:
clazz
- The class.- Returns:
- The raw object.
-
getProvidedServiceRawImpl
public java.lang.Object getProvidedServiceRawImpl(java.lang.String name)
Get the provided service implementation object by name.- Specified by:
getProvidedServiceRawImpl
in interfaceIProvidedServicesFeature
- Parameters:
name
- The service name.- Returns:
- The service.
-
getProvidedService
public java.lang.Object getProvidedService(IServiceIdentifier sid)
Get the provided service implementation object by id.- Specified by:
getProvidedService
in interfaceIProvidedServicesFeature
- Parameters:
name
- The service identifier.- Returns:
- The service.
-
getProvidedServiceRawImpl
public java.lang.Object getProvidedServiceRawImpl(IServiceIdentifier sid)
Get the provided service implementation object by id.- Specified by:
getProvidedServiceRawImpl
in interfaceIProvidedServicesFeature
- Parameters:
name
- The service identifier.- Returns:
- The service.
-
getProvidedServices
public <T> T[] getProvidedServices(java.lang.Class<T> clazz)
Get provided (declared) service.- Specified by:
getProvidedServices
in interfaceIProvidedServicesFeature
- Parameters:
clazz
- The interface.- Returns:
- The service.
-
getProvidedService
public <T> T getProvidedService(java.lang.Class<T> clazz)
Get provided (declared) service.- Specified by:
getProvidedService
in interfaceIProvidedServicesFeature
- Parameters:
clazz
- The interface.- Returns:
- The service.
-
getServices
public java.util.Map<java.lang.Class<?>,java.util.Collection<IInternalService>> getServices()
Get the services.- Returns:
- The services.
-
addService
public IFuture<java.lang.Void> addService(java.lang.String name, java.lang.Class<?> type, java.lang.Object service)
Add a service to the platform. If under the same name and type a service was contained, the old one is removed and shutdowned.- Specified by:
addService
in interfaceIExternalProvidedServicesFeature
- Parameters:
type
- The public service interface.service
- The service.- Returns:
- A future that is done when the service has completed starting.
-
addService
public IFuture<java.lang.Void> addService(java.lang.String name, java.lang.Class<?> type, java.lang.Object service, java.lang.String proxytype)
Add a service to the platform. If under the same name and type a service was contained, the old one is removed and shutdowned.- Specified by:
addService
in interfaceIExternalProvidedServicesFeature
- Parameters:
type
- The public service interface.service
- The service.type
- The proxy type (@see{BasicServiceInvocationHandler}).
-
addService
public IFuture<java.lang.Void> addService(java.lang.String name, java.lang.Class<?> type, java.lang.Object service, PublishInfo pi, ServiceScope scope)
Add a service to the platform. If under the same name and type a service was contained, the old one is removed and shutdowned.- Specified by:
addService
in interfaceIExternalProvidedServicesFeature
- Parameters:
type
- The public service interface.service
- The service.scope
- The service scope.
-
setTags
public IFuture<java.lang.Void> setTags(IServiceIdentifier sid, java.lang.String... tags)
Sets the tags of a service.- Specified by:
setTags
in interfaceIExternalProvidedServicesFeature
- Parameters:
sid
- The Service identifier.tags
- The tags.- Returns:
- New service identifier.
-
removeService
public IFuture<java.lang.Void> removeService(IServiceIdentifier sid)
Removes a service from the platform (shutdowns also the service).- Specified by:
removeService
in interfaceIExternalProvidedServicesFeature
- Parameters:
service
- The service.- Returns:
- A future that is done when the service has completed its shutdown.
-
getServiceTypes
public IFuture<java.util.Collection<java.lang.Class<?>>> getServiceTypes(IServiceIdentifier sid)
-
getServiceType
public IFuture<java.lang.Class<?>> getServiceType(IServiceIdentifier sid)
-
addService
public IFuture<java.lang.Void> addService(java.lang.String name, java.lang.Class<?> type, java.lang.String proxytype, IServiceInvocationInterceptor[] ics, java.lang.Object service, ProvidedServiceInfo info, ServiceScope scope)
Add a service to the component.- Parameters:
type
- The service interface.service
- The service.proxytype
- The proxy type (@see{BasicServiceInvocationHandler}).
-
addMethodInvocationListener
public void addMethodInvocationListener(IServiceIdentifier sid, MethodInfo mi, IMethodInvocationListener listener)
Add a method invocation handler.- Specified by:
addMethodInvocationListener
in interfaceIProvidedServicesFeature
- Parameters:
sid
- The service identifier.mi
- The method info.listener
- The method listener.
-
removeMethodInvocationListener
public void removeMethodInvocationListener(IServiceIdentifier sid, MethodInfo mi, IMethodInvocationListener listener)
Remove a method invocation handler.- Specified by:
removeMethodInvocationListener
in interfaceIProvidedServicesFeature
- Parameters:
sid
- The service identifier.mi
- The method info.listener
- The method listener.
-
notifyMethodListeners
public void notifyMethodListeners(IServiceIdentifier sid, boolean start, java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args, java.lang.Object callid, ServiceInvocationContext context)
Notify listeners that a service method has been called.- Specified by:
notifyMethodListeners
in interfaceIProvidedServicesFeature
-
hasMethodListeners
public boolean hasMethodListeners(IServiceIdentifier sid, MethodInfo mi)
Test if service and method has listeners.- Specified by:
hasMethodListeners
in interfaceIProvidedServicesFeature
- Parameters:
sid
- The service identifier.mi
- The method info.
-
addInterceptor
public void addInterceptor(IServiceInvocationInterceptor interceptor, java.lang.Object service, int pos)
Add a service interceptor.- Specified by:
addInterceptor
in interfaceIProvidedServicesFeature
- Parameters:
interceptor
- The interceptor.service
- The service.pos
- The position (0=first, -1=last-1, i.e. one before method invocation).
-
removeInterceptor
public void removeInterceptor(IServiceInvocationInterceptor interceptor, java.lang.Object service)
Remove a service interceptor.- Specified by:
removeInterceptor
in interfaceIProvidedServicesFeature
- Parameters:
interceptor
- The interceptor.service
- The service.
-
getInterceptors
public IServiceInvocationInterceptor[] getInterceptors(java.lang.Object service)
Get the interceptors of a service.- Specified by:
getInterceptors
in interfaceIProvidedServicesFeature
- Parameters:
service
- The service.- Returns:
- The interceptors.
-
-