org.eclipse.rdf4j.common.lang.service

## Class ServiceRegistry<K,S>

- java.lang.Object
- - org.eclipse.rdf4j.common.lang.service.ServiceRegistry<K,S>

- Direct Known Subclasses:
    DatatypeHandlerRegistry, FileFormatServiceRegistry, FunctionRegistry, LanguageHandlerRegistry, QueryParserRegistry, RepositoryRegistry, SailRegistry, TransactionSettingRegistry, TupleFunctionRegistry

      public abstract class ServiceRegistry<K,S>
      extends Object

  A registry that stores services by some key. Upon initialization, the registry searches for service description files at `META-INF/services/<service class name>` and initializes itself accordingly.
  Author:
    Arjohn Kampman
  See Also:
    `ServiceRegistry`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected org.slf4j.Logger` | `logger`
    `protected Map<K,S>` | `services`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ServiceRegistry(Class<S> serviceClass)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Optional<S>` | `add(S service)` Adds a service to the registry.
    `Optional<S>` | `get(K key)` Gets the service for the specified key, if any.
    `Collection<S>` | `getAll()` Gets all registered services.
    `protected abstract K` | `getKey(S service)` Gets the key for the specified service.
    `Set<K>` | `getKeys()` Gets the set of registered keys.
    `boolean` | `has(K key)` Checks whether a service for the specified key is available.
    `void` | `remove(S service)` Removes a service from the registry.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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.

Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.