Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Neo4j Community
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.neo4j.helpers
Class Service

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

Direct Known Subclasses:
  IndexProvider, KernelExtension, Service.CaseInsensitiveService, Version

    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
`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]).

Constructor Summary
`protected` | `Service(String key, String... altKeys)` Create a new instance of a service implementation identified with the specified key(s).

Method Summary
`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.
`String` | `toString()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Service

    protected Service(String key,
                      String... altKeys)

  Create a new instance of a service implementation identified with the specified key(s).

  Parameters:
    `key` - the main key for identifying this service implementation
    `altKeys` - alternative spellings of the identifier of this service implementation

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.

  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`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Neo4j Community
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011 The Neo4j Graph Database Project. All Rights Reserved.