Class ServiceRegistry<K,​S>

    • Field Detail

      • logger

        protected final org.slf4j.Logger logger
      • services

        protected Map<K,​S> services
    • Constructor Detail

      • ServiceRegistry

        protected ServiceRegistry​(Class<S> serviceClass)
    • Method Detail

      • add

        public Optional<S> add​(S service)
        Adds a service to the registry. Any service that is currently registered for the same key (as specified by getKey(Object)) will be replaced with the new service.
        Parameters:
        service - The service that should be added to the registry.
        Returns:
        The previous service that was registered for the same key, or Optional.empty() if there was no such service.
      • remove

        public void remove​(S service)
        Removes a service from the registry.
        Parameters:
        service - The service be removed from the registry.
      • get

        public Optional<S> get​(K key)
        Gets the service for the specified key, if any.
        Parameters:
        key - The key identifying which service to get.
        Returns:
        The service for the specified key, or Optional.empty() if no such service is avaiable.
      • has

        public boolean has​(K key)
        Checks whether a service for the specified key is available.
        Parameters:
        key - The key identifying which service to search for.
        Returns:
        true if a service for the specific key is available, false otherwise.
      • getAll

        public Collection<S> getAll()
        Gets all registered services.
        Returns:
        An unmodifiable collection containing all registered servivces.
      • getKeys

        public Set<K> getKeys()
        Gets the set of registered keys.
        Returns:
        An unmodifiable set containing all registered keys.
      • getKey

        protected abstract K getKey​(S service)
        Gets the key for the specified service.
        Parameters:
        service - The service to get the key for.
        Returns:
        The key for the specified service.