Package jadex.bridge.service.search
Class ServiceRegistry
- java.lang.Object
-
- jadex.bridge.service.search.ServiceRegistry
-
- All Implemented Interfaces:
IServiceRegistry
public class ServiceRegistry extends java.lang.Object implements IServiceRegistry
Local service registry. - Search fetches services by types and excludes some according to the scope. - Allows for adding persistent queries.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<IComponentIdentifier,java.util.Set<IServiceIdentifier>>
excludedservices
The excluded services cache.protected Indexer<IServiceIdentifier>
indexer
The service indexer.protected java.util.Map<IServiceIdentifier,IService>
localserviceproxies
Map for looking up local services using the service identifier.protected java.util.concurrent.locks.ReadWriteLock
proxyrwlock
Read-Write Lock for proxy map.protected Indexer<ServiceQueryInfo<?>>
queries
The persistent service queries.protected java.util.concurrent.locks.ReadWriteLock
rwlock
Read-Write Lock
-
Constructor Summary
Constructors Constructor Description ServiceRegistry()
Create a new registry.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExcludedComponent(IComponentIdentifier cid)
Add an excluded component.void
addLocalService(IService service)
Add a local service to the registry.<T> ISubscriptionIntermediateFuture<T>
addQuery(ServiceQuery<T> query)
Add a service query to the registry.void
addService(IServiceIdentifier service)
Add a service to the registry.protected boolean
checkLifecycleVisibility(ServiceQuery<?> query, IServiceIdentifier ser)
Test if a service is visible, i.e. visible after init for all components or visible for subcomponents also during init.protected boolean
checkPublicationScope(ServiceQuery<?> query, IServiceIdentifier ser)
Check if service is ok with respect to publication scope.protected IFuture<java.lang.Void>
checkQueries(IServiceIdentifier ser, int eventtype)
Check the persistent queries for a new service.protected boolean
checkRestrictions(ServiceQuery<?> query, IServiceIdentifier ser)
Check the services according additional restrictions like scope.protected boolean
checkSearchScope(ServiceQuery<?> query, IServiceIdentifier ser)
Check if service is ok with respect to search scope of caller.protected void
dispatchQueryEvent(ServiceQueryInfo<?> queryinfo, IServiceIdentifier ser, int eventtype)
java.util.Set<ServiceQueryInfo<?>>
getAllQueries()
Get all queries.java.util.Set<IServiceIdentifier>
getAllServices()
Get all services.static java.lang.String
getApplicationName(IComponentIdentifier cid)
Get the application name.static java.lang.String
getDotName(IComponentIdentifier cid)
Get the name without @ replaced by dot.protected Indexer<IServiceIdentifier>
getIndexer()
Get the indexer.IService
getLocalService(IServiceIdentifier serviceid)
Returns the service proxy of a local service identified by service ID.java.util.concurrent.locks.ReadWriteLock
getLock()
Returns the lock on the registry.static IServiceRegistry
getRegistry(IComponentIdentifier platform)
Get the registry from a component.static IServiceRegistry
getRegistry(IInternalAccess ia)
Get the registry from a component.protected java.util.Set<IServiceIdentifier>
getServices()
Get all services.protected java.util.Set<IServiceIdentifier>
getServices(ServiceQuery<?> query)
Get services per query.static java.lang.String
getSubcomponentName(IComponentIdentifier cid)
Get the subcomponent name.void
removeExcludedComponent(IComponentIdentifier cid)
Remove an excluded component.void
removeQueries(IComponentIdentifier owner)
Remove all service queries of a specific component from the registry.void
removeQueriesOfPlatform(IComponentIdentifier platform)
Remove all service queries of a specific platform from the registry.void
removeQuery(ServiceQuery<?> query)
Remove a service query from the registry.void
removeService(IServiceIdentifier service)
Remove a service from the registry.void
removeServices(IComponentIdentifier platform)
Remove services of a platform from the registry.IServiceIdentifier
searchService(ServiceQuery<?> query)
Search for services.java.util.Set<IServiceIdentifier>
searchServices(ServiceQuery<?> query)
Search for services.void
updateService(IServiceIdentifier service)
Updates a service if the service meta-information has changes.void
updateService(IServiceIdentifier service, java.lang.String propname)
Updates a service if the service meta-information has changes.
-
-
-
Field Detail
-
rwlock
protected java.util.concurrent.locks.ReadWriteLock rwlock
Read-Write Lock
-
indexer
protected Indexer<IServiceIdentifier> indexer
The service indexer.
-
queries
protected Indexer<ServiceQueryInfo<?>> queries
The persistent service queries.
-
excludedservices
protected java.util.Map<IComponentIdentifier,java.util.Set<IServiceIdentifier>> excludedservices
The excluded services cache.
-
proxyrwlock
protected java.util.concurrent.locks.ReadWriteLock proxyrwlock
Read-Write Lock for proxy map.
-
localserviceproxies
protected java.util.Map<IServiceIdentifier,IService> localserviceproxies
Map for looking up local services using the service identifier.
-
-
Method Detail
-
searchService
public IServiceIdentifier searchService(ServiceQuery<?> query)
Search for services.- Specified by:
searchService
in interfaceIServiceRegistry
-
searchServices
public java.util.Set<IServiceIdentifier> searchServices(ServiceQuery<?> query)
Search for services.- Specified by:
searchServices
in interfaceIServiceRegistry
-
addService
public void addService(IServiceIdentifier service)
Add a service to the registry.- Specified by:
addService
in interfaceIServiceRegistry
- Parameters:
service
- The service.
-
addLocalService
public void addLocalService(IService service)
Add a local service to the registry.- Specified by:
addLocalService
in interfaceIServiceRegistry
- Parameters:
service
- The local service.
-
updateService
public void updateService(IServiceIdentifier service)
Updates a service if the service meta-information has changes.- Specified by:
updateService
in interfaceIServiceRegistry
- Parameters:
service
- The service.
-
updateService
public void updateService(IServiceIdentifier service, java.lang.String propname)
Updates a service if the service meta-information has changes.- Parameters:
service
- The service (null = all).
-
removeService
public void removeService(IServiceIdentifier service)
Remove a service from the registry.- Specified by:
removeService
in interfaceIServiceRegistry
- Parameters:
sid
- The service id.
-
removeServices
public void removeServices(IComponentIdentifier platform)
Remove services of a platform from the registry.- Specified by:
removeServices
in interfaceIServiceRegistry
- Parameters:
platform
- The platform, null for everything.
-
getLocalService
public IService getLocalService(IServiceIdentifier serviceid)
Returns the service proxy of a local service identified by service ID.- Specified by:
getLocalService
in interfaceIServiceRegistry
- Parameters:
serviceid
- The service ID.- Returns:
- The service proxy.
-
getAllServices
public java.util.Set<IServiceIdentifier> getAllServices()
Get all services.- Specified by:
getAllServices
in interfaceIServiceRegistry
- Returns:
- All services (copy).
-
getAllQueries
public java.util.Set<ServiceQueryInfo<?>> getAllQueries()
Get all queries.- Specified by:
getAllQueries
in interfaceIServiceRegistry
- Returns:
- All queries (copy).
-
getLock
public java.util.concurrent.locks.ReadWriteLock getLock()
Returns the lock on the registry. Care must be taken to perform proper unlocking to avoid permanently blocking the registry. Note that the lock is reentrant, so operations can be performed while the lock is held.- Specified by:
getLock
in interfaceIServiceRegistry
- Returns:
- The registry lock.
-
addQuery
public <T> ISubscriptionIntermediateFuture<T> addQuery(ServiceQuery<T> query)
Add a service query to the registry.- Specified by:
addQuery
in interfaceIServiceRegistry
- Parameters:
query
- ServiceQuery.
-
removeQuery
public void removeQuery(ServiceQuery<?> query)
Remove a service query from the registry.- Specified by:
removeQuery
in interfaceIServiceRegistry
- Parameters:
query
- ServiceQuery.
-
removeQueries
public void removeQueries(IComponentIdentifier owner)
Remove all service queries of a specific component from the registry.- Specified by:
removeQueries
in interfaceIServiceRegistry
- Parameters:
owner
- The query owner.
-
removeQueriesOfPlatform
public void removeQueriesOfPlatform(IComponentIdentifier platform)
Remove all service queries of a specific platform from the registry.- Specified by:
removeQueriesOfPlatform
in interfaceIServiceRegistry
- Parameters:
platform
- The platform from which the query owner comes.
-
addExcludedComponent
public void addExcludedComponent(IComponentIdentifier cid)
Add an excluded component.- Specified by:
addExcludedComponent
in interfaceIServiceRegistry
- Parameters:
The
- component identifier.
-
removeExcludedComponent
public void removeExcludedComponent(IComponentIdentifier cid)
Remove an excluded component.- Specified by:
removeExcludedComponent
in interfaceIServiceRegistry
- Parameters:
The
- component identifier.
-
checkLifecycleVisibility
protected boolean checkLifecycleVisibility(ServiceQuery<?> query, IServiceIdentifier ser)
Test if a service is visible, i.e. visible after init for all components or visible for subcomponents also during init.- Parameters:
query
- The query.ser
- The service.- Returns:
- True if is included.
-
checkQueries
protected IFuture<java.lang.Void> checkQueries(IServiceIdentifier ser, int eventtype)
Check the persistent queries for a new service.- Parameters:
ser
- The service.removed
- Indicates if the query was removed.
-
dispatchQueryEvent
protected void dispatchQueryEvent(ServiceQueryInfo<?> queryinfo, IServiceIdentifier ser, int eventtype)
-
checkRestrictions
protected boolean checkRestrictions(ServiceQuery<?> query, IServiceIdentifier ser)
Check the services according additional restrictions like scope.- Parameters:
query
- The query.ser
- The service.- Returns:
- True, if service passes tests.
-
checkSearchScope
protected boolean checkSearchScope(ServiceQuery<?> query, IServiceIdentifier ser)
Check if service is ok with respect to search scope of caller.
-
checkPublicationScope
protected boolean checkPublicationScope(ServiceQuery<?> query, IServiceIdentifier ser)
Check if service is ok with respect to publication scope.
-
getServices
protected java.util.Set<IServiceIdentifier> getServices()
Get all services.- Returns:
- The services.
-
getServices
protected java.util.Set<IServiceIdentifier> getServices(ServiceQuery<?> query)
Get services per query. Uses not the full query spec and does not check scope and filter.- Parameters:
query
- The query.- Returns:
- First matching service or null.
-
getRegistry
public static IServiceRegistry getRegistry(IComponentIdentifier platform)
Get the registry from a component.
-
getRegistry
public static IServiceRegistry getRegistry(IInternalAccess ia)
Get the registry from a component.
-
getApplicationName
public static java.lang.String getApplicationName(IComponentIdentifier cid)
Get the application name. Equals the local component name in case it is a child of the platform. broadcast@awa.plat1 -> awa- Returns:
- The application name.
-
getSubcomponentName
public static java.lang.String getSubcomponentName(IComponentIdentifier cid)
Get the subcomponent name.- Parameters:
cid
- The component id.- Returns:
- The subcomponent name.
-
getDotName
public static java.lang.String getDotName(IComponentIdentifier cid)
Get the name without @ replaced by dot.
-
getIndexer
protected Indexer<IServiceIdentifier> getIndexer()
Get the indexer.- Returns:
- the indexer
-
-