Package jadex.requiredservice.impl
Class RequiredServiceFeature
java.lang.Object
jadex.requiredservice.impl.RequiredServiceFeature
- All Implemented Interfaces:
jadex.execution.impl.ILifecycle
,IRequiredServiceFeature
public class RequiredServiceFeature
extends Object
implements jadex.execution.impl.ILifecycle, IRequiredServiceFeature
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map
<String, RequiredServiceInfo> The required service infos.protected jadex.core.impl.Component
protected Set
<jadex.future.SubscriptionIntermediateFuture<ServiceCallEvent>> The current subscriptions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> jadex.future.ISubscriptionIntermediateFuture
<T> addQuery
(jadex.providedservice.impl.search.ServiceQuery<T> query) Add a service query.<T> jadex.future.ISubscriptionIntermediateFuture
<T> addQuery
(jadex.providedservice.impl.search.ServiceQuery<T> query, long timeout) Add a query for a declared required service.<T> jadex.future.ISubscriptionIntermediateFuture
<T> Add a query for a declared required service.<T> jadex.future.ISubscriptionIntermediateFuture
<T> Add a query for a declared required service.protected void
addRequiredServiceInfos
(RequiredServiceInfo[] requiredservices) Add required services for a given prefix.protected static jadex.providedservice.IService
addRequiredServiceProxy
(jadex.providedservice.IService service, RequiredServiceInfo info, jadex.core.impl.Component component) static jadex.providedservice.IService
createRequiredServiceProxy
(jadex.core.impl.Component ia, jadex.providedservice.IService service, IRequiredServiceFetcher fetcher, RequiredServiceBinding binding) Static method for creating a standard service proxy for a required service.static <T> RequiredServiceInfo
createServiceInfo
(jadex.providedservice.impl.search.ServiceQuery<T> query) When searching with query -> create required service info from service query.protected <T> void
enhanceQuery
(jadex.providedservice.impl.search.ServiceQuery<T> query, boolean multi) Enhance a query before processing.protected jadex.core.impl.Component
<T> T
getLocalService
(jadex.providedservice.impl.search.ServiceQuery<T> query) Search for matching services and provide first result.<T> T
getLocalService
(Class<T> type) Resolve a required service of a given type.<T> T
getLocalService
(String name) Resolve a declared required service of a given name.<T> T
getLocalService0
(Class<T> type) Resolve a required service of a given type.<T> Collection
<T> getLocalServices
(jadex.providedservice.impl.search.ServiceQuery<T> query) Search for all matching services.<T> Collection
<T> getLocalServices
(Class<T> type) Resolve a required services of a given type.<T> Collection
<T> getLocalServices
(String name) Resolve a required services of a given name.<T> T
getRawService
(Class<T> type) Get a service raw (i.e.<T> Collection
<T> getRawServices
(Class<T> type) Get a service raw (i.e.<T> jadex.future.IFuture
<T> getService
(Class<T> type) Resolve a required service of a given type.<T> jadex.future.IFuture
<T> getService
(String name) Resolve a declared required service of a given name.jadex.future.ISubscriptionIntermediateFuture
<ServiceCallEvent> Listen to service call events (call, result and commands).protected RequiredServiceInfo
getServiceInfo
(Class<?> type) Get the required service info for a type.getServiceInfo
(String name) Get the required service info for a name.Get the required services.jadex.providedservice.IService
getServiceProxy
(jadex.providedservice.IServiceIdentifier sid, RequiredServiceInfo info) Create the user-facing object from the received search or query result.static jadex.providedservice.IService
getServiceProxy
(jadex.providedservice.IServiceIdentifier sid, RequiredServiceInfo info, jadex.core.impl.Component component) Create the user-facing object from the received search or query result.static <T> jadex.providedservice.impl.search.ServiceQuery
<T> getServiceQuery
(jadex.core.impl.Component ia, RequiredServiceInfo info) When searching for declared service -> map required service declaration to service query.<T> jadex.providedservice.impl.search.ServiceQuery
<T> When searching for declared service -> map required service declaration to service query.jadex.providedservice.impl.search.ServiceQuery
<?> getServiceQuery
(String name) Get a service query for a required service info (as defined in the agent under that name).<T> jadex.future.ITerminableIntermediateFuture
<T> getServices
(Class<T> type) Resolve a required services of a given type.<T> jadex.future.ITerminableIntermediateFuture
<T> getServices
(String name) Resolve a required services of a given name.boolean
Check if there is someone monitoring.boolean
isRemote
(jadex.providedservice.impl.search.ServiceQuery<?> query) Check if a query is potentially remote.static boolean
isRequiredServiceProxy
(Object service) Test if a service is a required service proxy.jadex.future.IFuture
<Void> onEnd()
jadex.future.IFuture
<Void> onStart()
void
postServiceEvent
(ServiceCallEvent event) Post a service call event.protected Object
processResult
(Object result, RequiredServiceInfo info) <T> T
resolveLocalService
(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Search for matching services and provide first result.<T> Collection
<T> resolveLocalServices
(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Search for all matching services.<T> jadex.future.ISubscriptionIntermediateFuture
<T> resolveQuery
(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Query for all matching services.<T> jadex.future.ITerminableFuture
<T> resolveService
(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Search for matching services and provide first result.<T> jadex.future.ITerminableIntermediateFuture
<T> resolveServices
(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Search for all matching services.<T> jadex.future.IFuture
<T> searchService
(jadex.providedservice.impl.search.ServiceQuery<T> query) Search for matching services and provide first result.<T> jadex.future.IFuture
<T> searchService
(jadex.providedservice.impl.search.ServiceQuery<T> query, long timeout) Performs a sustained search for a service.<T> jadex.future.ITerminableIntermediateFuture
<T> searchServices
(jadex.providedservice.impl.search.ServiceQuery<T> query) Search for all matching services.
-
Field Details
-
self
protected jadex.core.impl.Component self -
requiredserviceinfos
The required service infos. -
subscriptions
The current subscriptions.
-
-
Constructor Details
-
RequiredServiceFeature
protected RequiredServiceFeature(jadex.core.impl.Component self)
-
-
Method Details
-
loadModel
-
onStart
- Specified by:
onStart
in interfacejadex.execution.impl.ILifecycle
-
onEnd
- Specified by:
onEnd
in interfacejadex.execution.impl.ILifecycle
-
getService
Resolve a declared required service of a given name. Asynchronous method for locally as well as remotely available services.- Specified by:
getService
in interfaceIRequiredServiceFeature
- Parameters:
name
- The service name.- Returns:
- The service.
-
getService
Resolve a required service of a given type. Asynchronous method for locally as well as remotely available services.- Specified by:
getService
in interfaceIRequiredServiceFeature
- Parameters:
type
- The service type.- Returns:
- The service.
-
getServices
Resolve a required services of a given name. Asynchronous method for locally as well as remotely available services.- Specified by:
getServices
in interfaceIRequiredServiceFeature
- Parameters:
name
- The services name.- Returns:
- Each service as an intermediate result and a collection of services as final result.
-
getServices
Resolve a required services of a given type. Asynchronous method for locally as well as remotely available services.- Specified by:
getServices
in interfaceIRequiredServiceFeature
- Parameters:
type
- The services type.- Returns:
- Each service as an intermediate result and a collection of services as final result.
-
getLocalService
Resolve a declared required service of a given name. Synchronous method only for locally available services.- Specified by:
getLocalService
in interfaceIRequiredServiceFeature
- Parameters:
name
- The service name.- Returns:
- The service.
-
getLocalService
Resolve a required service of a given type. Synchronous method only for locally available services.- Specified by:
getLocalService
in interfaceIRequiredServiceFeature
- Parameters:
type
- The service type.- Returns:
- The service.
-
getLocalService0
Resolve a required service of a given type. Synchronous method only for locally available services.- Specified by:
getLocalService0
in interfaceIRequiredServiceFeature
- Parameters:
type
- The service type.- Returns:
- The service.
-
getLocalServices
Resolve a required services of a given name. Synchronous method only for locally available services.- Specified by:
getLocalServices
in interfaceIRequiredServiceFeature
- Parameters:
name
- The services name.- Returns:
- Each service as an intermediate result and a collection of services as final result.
-
getLocalServices
Resolve a required services of a given type. Synchronous method only for locally available services.- Specified by:
getLocalServices
in interfaceIRequiredServiceFeature
- Parameters:
type
- The services type.- Returns:
- Each service as an intermediate result and a collection of services as final result.
-
searchService
public <T> jadex.future.IFuture<T> searchService(jadex.providedservice.impl.search.ServiceQuery<T> query) Search for matching services and provide first result.- Specified by:
searchService
in interfaceIRequiredServiceFeature
- Parameters:
query
- The search query.- Returns:
- Future providing the corresponding service or ServiceNotFoundException when not found.
-
getLocalService
public <T> T getLocalService(jadex.providedservice.impl.search.ServiceQuery<T> query) Search for matching services and provide first result. Synchronous method only for locally available services.- Specified by:
getLocalService
in interfaceIRequiredServiceFeature
- Parameters:
query
- The search query.- Returns:
- Future providing the corresponding service or ServiceNotFoundException when not found.
-
searchServices
public <T> jadex.future.ITerminableIntermediateFuture<T> searchServices(jadex.providedservice.impl.search.ServiceQuery<T> query) Search for all matching services.- Specified by:
searchServices
in interfaceIRequiredServiceFeature
- Parameters:
query
- The search query.- Returns:
- Future providing the corresponding services or ServiceNotFoundException when not found.
-
getLocalServices
Search for all matching services. Synchronous method only for locally available services.- Specified by:
getLocalServices
in interfaceIRequiredServiceFeature
- Parameters:
query
- The search query.- Returns:
- Future providing the corresponding services or ServiceNotFoundException when not found.
-
searchService
public <T> jadex.future.IFuture<T> searchService(jadex.providedservice.impl.search.ServiceQuery<T> query, long timeout) Performs a sustained search for a service. Attempts to find a service for a maximum duration until timeout occurs.- Specified by:
searchService
in interfaceIRequiredServiceFeature
- Parameters:
query
- The search query.timeout
- Maximum time period to search, -1 for no wait.- Returns:
- Service matching the query, exception if service is not found.
-
addQuery
public <T> jadex.future.ISubscriptionIntermediateFuture<T> addQuery(jadex.providedservice.impl.search.ServiceQuery<T> query, long timeout) Add a query for a declared required service. Continuously searches for matching services.- Specified by:
addQuery
in interfaceIRequiredServiceFeature
- Parameters:
name
- The name of the required service declaration.- Returns:
- Future providing the corresponding services as intermediate results.
-
addQuery
Add a query for a declared required service. Continuously searches for matching services.- Specified by:
addQuery
in interfaceIRequiredServiceFeature
- Parameters:
name
- The name of the required service declaration.- Returns:
- Future providing the corresponding services as intermediate results.
-
addQuery
Add a query for a declared required service. Continuously searches for matching services.- Specified by:
addQuery
in interfaceIRequiredServiceFeature
- Parameters:
type
- The type of the required service declaration.- Returns:
- Future providing the corresponding services as intermediate results.
-
addQuery
public <T> jadex.future.ISubscriptionIntermediateFuture<T> addQuery(jadex.providedservice.impl.search.ServiceQuery<T> query) Add a service query. Continuously searches for matching services.- Specified by:
addQuery
in interfaceIRequiredServiceFeature
- Parameters:
query
- The search query.- Returns:
- Future providing the corresponding service or ServiceNotFoundException when not found.
-
getServiceInfos
Get the required services.- Returns:
- The required services.
-
getServiceEvents
Listen to service call events (call, result and commands). -
postServiceEvent
Post a service call event. -
isMonitoring
public boolean isMonitoring()Check if there is someone monitoring. To avoid posting when nobody is listening. -
getRawService
Get a service raw (i.e. w/o required proxy).- Returns:
- null when not found.
-
getRawServices
Get a service raw (i.e. w/o required proxy). -
processResult
- Parameters:
result
-info
-- Returns:
-
resolveService
public <T> jadex.future.ITerminableFuture<T> resolveService(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Search for matching services and provide first result.- Parameters:
query
- The search query.info
- Used for required service proxy configuration -> null for no proxy.- Returns:
- Future providing the corresponding service or ServiceNotFoundException when not found.
-
resolveLocalService
public <T> T resolveLocalService(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Search for matching services and provide first result. Synchronous method only for locally available services.- Parameters:
query
- The search query.info
- Used for required service proxy configuration -> null for no proxy.- Returns:
- Future providing the corresponding service or ServiceNotFoundException when not found.
-
resolveServices
public <T> jadex.future.ITerminableIntermediateFuture<T> resolveServices(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Search for all matching services.- Parameters:
query
- The search query.info
- Used for required service proxy configuration -> null for no proxy.- Returns:
- Future providing the corresponding services or ServiceNotFoundException when not found.
-
resolveLocalServices
public <T> Collection<T> resolveLocalServices(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Search for all matching services. Synchronous method only for locally available services.- Parameters:
query
- The search query.info
- Used for required service proxy configuration -> null for no proxy.- Returns:
- Future providing the corresponding services or ServiceNotFoundException when not found.
-
resolveQuery
public <T> jadex.future.ISubscriptionIntermediateFuture<T> resolveQuery(jadex.providedservice.impl.search.ServiceQuery<T> query, RequiredServiceInfo info) Query for all matching services.- Parameters:
query
- The search query.info
- Used for required service proxy configuration -> null for no proxy.- Returns:
- Future providing the corresponding services or ServiceNotFoundException when not found.
-
getServiceQuery
public <T> jadex.providedservice.impl.search.ServiceQuery<T> getServiceQuery(RequiredServiceInfo info) When searching for declared service -> map required service declaration to service query. -
getServiceInfo
Get the required service info for a name.- Specified by:
getServiceInfo
in interfaceIRequiredServiceFeature
- Parameters:
name
- The required service name.
-
getServiceInfo
Get the required service info for a type.- Parameters:
type
- The required service type.
-
getServiceProxy
public jadex.providedservice.IService getServiceProxy(jadex.providedservice.IServiceIdentifier sid, RequiredServiceInfo info) Create the user-facing object from the received search or query result. Result may be service object, service identifier (local or remote), or event. User object is either event or service (with or without required proxy).- Specified by:
getServiceProxy
in interfaceIRequiredServiceFeature
-
getServiceProxy
public static jadex.providedservice.IService getServiceProxy(jadex.providedservice.IServiceIdentifier sid, RequiredServiceInfo info, jadex.core.impl.Component component) Create the user-facing object from the received search or query result. Result may be service object, service identifier (local or remote), or event. User object is either event or service (with or without required proxy). -
addRequiredServiceProxy
protected static jadex.providedservice.IService addRequiredServiceProxy(jadex.providedservice.IService service, RequiredServiceInfo info, jadex.core.impl.Component component) - Parameters:
service
-info
-
-
enhanceQuery
protected <T> void enhanceQuery(jadex.providedservice.impl.search.ServiceQuery<T> query, boolean multi) Enhance a query before processing. Does some necessary preprocessing and needs to be called at least once before processing the query.- Parameters:
query
- The query to be enhanced.
-
isRemote
public boolean isRemote(jadex.providedservice.impl.search.ServiceQuery<?> query) Check if a query is potentially remote.- Returns:
- True, if scope is set to a remote scope (e.g. global or network).
-
getServiceQuery
Get a service query for a required service info (as defined in the agent under that name).- Specified by:
getServiceQuery
in interfaceIRequiredServiceFeature
- Parameters:
name
- The name.- Returns:
- The service query.
-
addRequiredServiceInfos
Add required services for a given prefix.- Parameters:
prefix
- The name prefix to use.required
- services The required services to set.
-
createServiceInfo
public static <T> RequiredServiceInfo createServiceInfo(jadex.providedservice.impl.search.ServiceQuery<T> query) When searching with query -> create required service info from service query. -
getComponent
protected jadex.core.impl.Component getComponent() -
createRequiredServiceProxy
public static jadex.providedservice.IService createRequiredServiceProxy(jadex.core.impl.Component ia, jadex.providedservice.IService service, IRequiredServiceFetcher fetcher, RequiredServiceBinding binding) Static method for creating a standard service proxy for a required service. -
isRequiredServiceProxy
Test if a service is a required service proxy.- Parameters:
service
- The service.- Returns:
- True, if is required service proxy.
-
getServiceQuery
public static <T> jadex.providedservice.impl.search.ServiceQuery<T> getServiceQuery(jadex.core.impl.Component ia, RequiredServiceInfo info) When searching for declared service -> map required service declaration to service query.
-