Class ServiceRegistry

java.lang.Object
jadex.providedservice.impl.search.ServiceRegistry
All Implemented Interfaces:
IServiceRegistry

public class ServiceRegistry extends Object implements IServiceRegistry
Local service registry. - todo?: clean up queries of terminated components. Currently removes queries when an event occurs and scheduling on component thread does not work any longer. - Search fetches services by types and excludes some according to the scope. - Allows for adding persistent queries.
  • Field Details

  • Constructor Details

    • ServiceRegistry

      public ServiceRegistry()
      Create a new registry.
  • Method Details

    • getRegistry

      public static IServiceRegistry getRegistry()
      Get the registry from a component.
    • searchService

      public IServiceIdentifier searchService(ServiceQuery<?> query)
      Search for services.
      Specified by:
      searchService in interface IServiceRegistry
    • searchServices

      public Set<IServiceIdentifier> searchServices(ServiceQuery<?> query)
      Search for services.
      Specified by:
      searchServices in interface IServiceRegistry
    • addService

      public void addService(IServiceIdentifier service)
      Add a service to the registry.
      Specified by:
      addService in interface IServiceRegistry
      Parameters:
      service - The service.
    • addLocalService

      public void addLocalService(IService service)
      Add a local service to the registry.
      Specified by:
      addLocalService in interface IServiceRegistry
      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 interface IServiceRegistry
      Parameters:
      service - The service.
    • updateService

      public void updateService(IServiceIdentifier service, 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 interface IServiceRegistry
      Parameters:
      service - The service.
      sid - The service id.
    • getLocalService

      public IService getLocalService(IServiceIdentifier serviceid)
      Returns the service proxy of a local service identified by service ID.
      Specified by:
      getLocalService in interface IServiceRegistry
      Parameters:
      serviceid - The service ID.
      Returns:
      The service proxy.
    • getAllServices

      public Set<IServiceIdentifier> getAllServices()
      Get all services.
      Specified by:
      getAllServices in interface IServiceRegistry
      Returns:
      All services (copy).
    • getAllQueries

      public Set<ServiceQueryInfo<?>> getAllQueries()
      Get all queries.
      Specified by:
      getAllQueries in interface IServiceRegistry
      Returns:
      All queries (copy).
    • getLock

      public 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 interface IServiceRegistry
      Returns:
      The registry lock.
    • addQuery

      public <T> jadex.future.ISubscriptionIntermediateFuture<T> addQuery(ServiceQuery<T> query)
      Add a service query to the registry.
      Specified by:
      addQuery in interface IServiceRegistry
      Parameters:
      query - ServiceQuery.
    • removeQuery

      public void removeQuery(ServiceQuery<?> query)
      Remove a service query from the registry.
      Specified by:
      removeQuery in interface IServiceRegistry
      Parameters:
      query - ServiceQuery.
    • checkQueries

      protected jadex.future.IFuture<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 Set<IServiceIdentifier> getServices()
      Get all services.
      Returns:
      The services.
    • getServices

      protected 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.
    • subscribeToQueries

      public jadex.future.ISubscriptionIntermediateFuture<QueryEvent> subscribeToQueries()
      Subscribe for query events.
      Specified by:
      subscribeToQueries in interface IServiceRegistry
    • notifyQueryListeners

      protected void notifyQueryListeners(QueryEvent event)
      Notify all listeners.
      Parameters:
      fut -
      type -
    • getIndexer

      protected Indexer<IServiceIdentifier> getIndexer()
      Get the indexer.
      Returns:
      the indexer