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 Details

    • self

      protected jadex.core.impl.Component self
    • requiredserviceinfos

      protected Map<String,RequiredServiceInfo> requiredserviceinfos
      The required service infos.
    • subscriptions

      protected Set<jadex.future.SubscriptionIntermediateFuture<ServiceCallEvent>> subscriptions
      The current subscriptions.
  • Constructor Details

    • RequiredServiceFeature

      protected RequiredServiceFeature(jadex.core.impl.Component self)
  • Method Details

    • loadModel

      public RequiredServiceModel loadModel()
    • onStart

      public jadex.future.IFuture<Void> onStart()
      Specified by:
      onStart in interface jadex.execution.impl.ILifecycle
    • onEnd

      public jadex.future.IFuture<Void> onEnd()
      Specified by:
      onEnd in interface jadex.execution.impl.ILifecycle
    • getService

      public <T> jadex.future.IFuture<T> getService(String name)
      Resolve a declared required service of a given name. Asynchronous method for locally as well as remotely available services.
      Specified by:
      getService in interface IRequiredServiceFeature
      Parameters:
      name - The service name.
      Returns:
      The service.
    • getService

      public <T> jadex.future.IFuture<T> getService(Class<T> type)
      Resolve a required service of a given type. Asynchronous method for locally as well as remotely available services.
      Specified by:
      getService in interface IRequiredServiceFeature
      Parameters:
      type - The service type.
      Returns:
      The service.
    • getServices

      public <T> jadex.future.ITerminableIntermediateFuture<T> getServices(String name)
      Resolve a required services of a given name. Asynchronous method for locally as well as remotely available services.
      Specified by:
      getServices in interface IRequiredServiceFeature
      Parameters:
      name - The services name.
      Returns:
      Each service as an intermediate result and a collection of services as final result.
    • getServices

      public <T> jadex.future.ITerminableIntermediateFuture<T> getServices(Class<T> type)
      Resolve a required services of a given type. Asynchronous method for locally as well as remotely available services.
      Specified by:
      getServices in interface IRequiredServiceFeature
      Parameters:
      type - The services type.
      Returns:
      Each service as an intermediate result and a collection of services as final result.
    • getLocalService

      public <T> T getLocalService(String name)
      Resolve a declared required service of a given name. Synchronous method only for locally available services.
      Specified by:
      getLocalService in interface IRequiredServiceFeature
      Parameters:
      name - The service name.
      Returns:
      The service.
    • getLocalService

      public <T> T getLocalService(Class<T> type)
      Resolve a required service of a given type. Synchronous method only for locally available services.
      Specified by:
      getLocalService in interface IRequiredServiceFeature
      Parameters:
      type - The service type.
      Returns:
      The service.
    • getLocalService0

      public <T> T getLocalService0(Class<T> type)
      Resolve a required service of a given type. Synchronous method only for locally available services.
      Specified by:
      getLocalService0 in interface IRequiredServiceFeature
      Parameters:
      type - The service type.
      Returns:
      The service.
    • getLocalServices

      public <T> Collection<T> getLocalServices(String name)
      Resolve a required services of a given name. Synchronous method only for locally available services.
      Specified by:
      getLocalServices in interface IRequiredServiceFeature
      Parameters:
      name - The services name.
      Returns:
      Each service as an intermediate result and a collection of services as final result.
    • getLocalServices

      public <T> Collection<T> getLocalServices(Class<T> type)
      Resolve a required services of a given type. Synchronous method only for locally available services.
      Specified by:
      getLocalServices in interface IRequiredServiceFeature
      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 interface IRequiredServiceFeature
      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 interface IRequiredServiceFeature
      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 interface IRequiredServiceFeature
      Parameters:
      query - The search query.
      Returns:
      Future providing the corresponding services or ServiceNotFoundException when not found.
    • getLocalServices

      public <T> Collection<T> getLocalServices(jadex.providedservice.impl.search.ServiceQuery<T> query)
      Search for all matching services. Synchronous method only for locally available services.
      Specified by:
      getLocalServices in interface IRequiredServiceFeature
      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 interface IRequiredServiceFeature
      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 interface IRequiredServiceFeature
      Parameters:
      name - The name of the required service declaration.
      Returns:
      Future providing the corresponding services as intermediate results.
    • addQuery

      public <T> jadex.future.ISubscriptionIntermediateFuture<T> addQuery(String name)
      Add a query for a declared required service. Continuously searches for matching services.
      Specified by:
      addQuery in interface IRequiredServiceFeature
      Parameters:
      name - The name of the required service declaration.
      Returns:
      Future providing the corresponding services as intermediate results.
    • addQuery

      public <T> jadex.future.ISubscriptionIntermediateFuture<T> addQuery(Class<T> type)
      Add a query for a declared required service. Continuously searches for matching services.
      Specified by:
      addQuery in interface IRequiredServiceFeature
      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 interface IRequiredServiceFeature
      Parameters:
      query - The search query.
      Returns:
      Future providing the corresponding service or ServiceNotFoundException when not found.
    • getServiceInfos

      public RequiredServiceInfo[] getServiceInfos()
      Get the required services.
      Returns:
      The required services.
    • getServiceEvents

      public jadex.future.ISubscriptionIntermediateFuture<ServiceCallEvent> getServiceEvents()
      Listen to service call events (call, result and commands).
    • postServiceEvent

      public void postServiceEvent(ServiceCallEvent event)
      Post a service call event.
    • isMonitoring

      public boolean isMonitoring()
      Check if there is someone monitoring. To avoid posting when nobody is listening.
    • getRawService

      public <T> T getRawService(Class<T> type)
      Get a service raw (i.e. w/o required proxy).
      Returns:
      null when not found.
    • getRawServices

      public <T> Collection<T> getRawServices(Class<T> type)
      Get a service raw (i.e. w/o required proxy).
    • processResult

      protected Object processResult(Object result, RequiredServiceInfo info)
      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

      public RequiredServiceInfo getServiceInfo(String name)
      Get the required service info for a name.
      Specified by:
      getServiceInfo in interface IRequiredServiceFeature
      Parameters:
      name - The required service name.
    • getServiceInfo

      protected RequiredServiceInfo getServiceInfo(Class<?> type)
      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 interface IRequiredServiceFeature
    • 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

      public 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).
      Specified by:
      getServiceQuery in interface IRequiredServiceFeature
      Parameters:
      name - The name.
      Returns:
      The service query.
    • addRequiredServiceInfos

      protected void addRequiredServiceInfos(RequiredServiceInfo[] requiredservices)
      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

      public static boolean isRequiredServiceProxy(Object service)
      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.