Package nbbrd.service

Annotation Type ServiceDefinition


@Documented @Target(TYPE) @Retention(SOURCE) public @interface ServiceDefinition
Declarative definition of a service that generates a specialized service loader that takes care of the loading and enforces a specific usage.

Internal storage summary:

 optional none                  :        final           Optional<T>
 optional basic                 :                        Optional<T>
 optional concurrent            :        final AtomicRef<Optional<T>>
 optional none       +singleton : static final           Optional<T>
 optional basic      +singleton : static                 Optional<T>
 optional concurrent +singleton : static final AtomicRef<Optional<T>>

 single   none                  :        final           T
 single   basic                 :                        T
 single   concurrent            :        final AtomicRef<T>
 single   none       +singleton : static final           T
 single   basic      +singleton : static                 T
 single   concurrent +singleton : static final AtomicRef<T>

 multiple none                  :        final           UmodifiableList<T>
 multiple basic                 :                        UmodifiableList<T>
 multiple concurrent            :        final AtomicRef<UmodifiableList<T>>
 multiple none       +singleton : static final           UmodifiableList<T>
 multiple basic      +singleton : static                 UmodifiableList<T>
 multiple concurrent +singleton : static final AtomicRef<UmodifiableList<T>>
 
Author:
Philippe Charles
  • Element Details

    • quantifier

      Quantifier quantifier
      Specifies how many instances are returned by the loader.
      Returns:
      a non-null quantifier
      Default:
      OPTIONAL
    • mutability

      Mutability mutability
      Specifies the mutability of the loader.
      Returns:
      a non-null mutability
      Default:
      NONE
    • singleton

      boolean singleton
      Specifies if the loader must be a singleton.
      Returns:
      true if the loader is a singleton, false otherwise
      Default:
      false
    • fallback

      Class<?> fallback
      Specifies the fallback class to use if no service is available.
      This option is only used in conjunction with Quantifier.SINGLE.

      Requirements:

      • must be assignable to the service type
      • must be instantiable either by constructor, static method, enum field or static final field
      Returns:
      the fallback class if required, Void otherwise
      Default:
      java.lang.Void.class
    • wrapper

      Class<?> wrapper
      Specifies the wrapper class to be used in basic preprocessing.

      Requirements:

      • must be assignable to the service type
      • must be instantiable either by constructor or static method, both with single parameter of service type
      Returns:
      the wrapper class if required, Void otherwise
      Default:
      java.lang.Void.class
    • preprocessor

      Class<? extends UnaryOperator<? extends Stream>> preprocessor
      Specifies the preprocessor class to be used in advanced preprocessing.
      This operation happens between loading and storage.
      It may include filtering, sorting and mapping.

      Requirements:

      • must be assignable to UnaryOperator<? extends Stream<SERVICE_TYPE>>
      • must be instantiable either by constructor, static method, enum field or static final field
      Returns:
      the preprocessor class if required, ServiceDefinition.NoProcessing otherwise
      Default:
      nbbrd.service.ServiceDefinition.NoProcessing.class
    • loaderName

      String loaderName
      Specifies the fully qualified name of the loader. An empty value generates an automatic name.
      Returns:
      a fully qualified name
      Default:
      ""
    • backend

      Class<? extends Function<? extends Class,? extends Iterable>> backend
      Specifies the class that creates a service loader.
      The default backend uses ServiceLoader.load(Class).

      Requirements:

      • must be assignable to Function<Class, ? extends Iterable>
      • must be instantiable either by constructor, static method, enum field or static final field
      Returns:
      the backend class if required, ServiceDefinition.DefaultBackend otherwise
      Default:
      nbbrd.service.ServiceDefinition.DefaultBackend.class
    • cleaner

      Class<? extends Consumer<? extends Iterable>> cleaner
      Specifies the class that deals with the cache cleaning.
      The default cleaner uses ServiceLoader.reload().

      Requirements:

      • must be assignable to Consumer<? extends Iterable>
      • must be instantiable either by constructor, static method, enum field or static final field
      Returns:
      the backend class if required, ServiceDefinition.DefaultCleaner otherwise
      Default:
      nbbrd.service.ServiceDefinition.DefaultCleaner.class
    • batch

      boolean batch
      Specifies if batch loading should be allowed.
      Returns:
      true if batch loading should be allowed, false otherwise
      Default:
      false
    • batchName

      String batchName
      Specifies the fully qualified name of the batch loading. An empty value generates an automatic name.
      Returns:
      a fully qualified name
      Default:
      ""