Service (Neo4j Community 2.1.0-M01 API)
Date: 2014-02-20

org.neo4j.helpers

## Class Service

- java.lang.Object
- - org.neo4j.helpers.Service

- Direct Known Subclasses:
    org.neo4j.kernel.extension.KernelExtensionFactory, Service.CaseInsensitiveService

      public abstract class Service
      extends Object

  A utility for locating services. This implements the same functionality as the Java 6 ServiceLoader interface, in fact it uses the `ServiceLoader` if available, but backports the functionality to previous Java versions and adds some error handling to ignore misconfigured service implementations.

  Additionally this class can be used as a base class for implementing services that are differentiated by a String key. An example implementation might be:

       public abstract class StringConverter extends org.neo4j.commons.Service
       {
           protected StringConverter(String id)
           {
               super( id );
           }

           public abstract String convert( String input );

           public static StringConverter load( String id )
           {
               return org.neo4j.commons.Service.load( StringConverter.class, id );
           }
       }

  With for example these implementations:

       public final class UppercaseConverter extends StringConverter
       {
           public UppercaseConverter()
           {
               super( "uppercase" );
           }

           public String convert( String input )
           {
               return input.toUpperCase();
           }
       }

       public final class ReverseConverter extends StringConverter
       {
           public ReverseConverter()
           {
               super( "reverse" );
           }

           public String convert( String input )
           {
               char[] chars = input.toCharArray();
               for ( int i = 0; i < chars.length/2; i++ )
               {
                   char intermediate = chars[i];
                   chars[i] = chars[chars.length-1-i];
                   chars[chars.length-1-i] = chars[i];
               }
               return new String( chars );
           }
       }

  This would then be used as:

       String atad = StringConverter.load( "reverse" ).convert( "data" );

  Author:
    Tobias Ivarsson

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Service.CaseInsensitiveService` A base class for services, similar to `Service`, that compares keys using case insensitive comparison instead of exact comparison.
    `static interface` | `Service.Implementation` Designates that a class implements the specified service and should be added to the services listings file (META-INF/services/[service-name]).

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object o)`
    `Iterable<String>` | `getKeys()`
    `int` | `hashCode()`
    `static <T> Iterable<T>` | `load(Class<T> type)` Load all implementations of a Service.
    `static <T extends Service> T` | `load(Class<T> type, String key)` Load the Service implementation with the specified key.
    `boolean` | `matches(String key)`
    `String` | `toString()`

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

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### load

          public static <T> Iterable<T> load(Class<T> type)

      Load all implementations of a Service.
      Type Parameters:
        `T` - the type of the Service
      Parameters:
        `type` - the type of the Service to load
      Returns:
        all registered implementations of the Service

    - #### load

          public static <T extends Service> T load(Class<T> type,
                                   String key)

      Load the Service implementation with the specified key. This method should never return null.
      Type Parameters:
        `T` - the type of the Service
      Parameters:
        `type` - the type of the Service to load
        `key` - the key that identifies the desired implementation
      Returns:
        the matching Service implementation

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### matches

          public boolean matches(String key)

    - #### getKeys

          public Iterable<String> getKeys()

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

Copyright © 2002–2014 The Neo4j Graph Database Project. All rights reserved.