org.glassfish.jersey.internal
Class ServiceProviders

java.lang.Object
  extended by org.glassfish.jersey.internal.ServiceProviders

public class ServiceProviders
extends java.lang.Object

Combines access to custom provider classes and instances and providers registered via a HK2 module or Java Service Provider mechanism (META-INF/services).

Author:
Paul Sandoz, Marek Potociar (marek.potociar at oracle.com)

Nested Class Summary
static class ServiceProviders.Builder
          Service providers builder.
static interface ServiceProviders.ServiceListener<T>
          Asynchronous callback interface for handling all the service providers of a given contract type.
 
Method Summary
<T> java.util.Set<T>
getAll(java.lang.Class<T> providerContract)
          Get all provider instances of the requested provider type found both in the internal storage as well as by performing service provider lookup in META-INF/services.
<T> java.util.List<T>
getAll(java.lang.Class<T> providerContract, java.util.Comparator<T> comparator)
          Get all provider instances of the requested provider type found both in the internal storage as well as by performing service provider lookup in META-INF/services.
<T> void
getAll(java.lang.Class<T> providerContract, ServiceProviders.ServiceListener<T> listener)
          Get all provider instances of the requested provider type found both in the internal storage as well as by performing service provider lookup in META-INF/services.
<T> java.util.Set<T>
getCustom(java.lang.Class<T> providerContract)
          Get all provider instances of the requested provider type from the list of internally registered provider instances and classes.
<T> java.util.List<T>
getCustom(java.lang.Class<T> providerContract, java.util.Comparator<T> comparator)
          Get all provider instances of the requested provider type from the list of internally registered provider instances and classes.
<T> void
getCustom(java.lang.Class<T> providerContract, ServiceProviders.ServiceListener<T> listener)
          Get all provider instances of the requested provider type from the list of internally registered provider instances and classes.
<T> java.util.Set<T>
getDefault(java.lang.Class<T> providerContract)
          Get all provider instances of the requested provider type found by performing service provider lookup in META-INF/services.
<T> java.util.List<T>
getDefault(java.lang.Class<T> providerContract, java.util.Comparator<T> comparator)
          Get all provider instances of the requested provider type found by performing service provider lookup in META-INF/services.
<T> java.util.List<T>
instantiate(java.lang.Class<T> providerContract, java.lang.Class<? extends T>[] classes)
          Instantiate providers of the given type using the array of provider implementation classes.
<T> java.util.List<T>
instantiate(java.lang.Class<T> providerContract, java.lang.String[] classNames)
          Instantiate providers of the given type using the array of provider implementation class names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCustom

public <T> java.util.Set<T> getCustom(java.lang.Class<T> providerContract)
Get all provider instances of the requested provider type from the list of internally registered provider instances and classes. This method does not perform service provider lookup in META-INF/services.

Type Parameters:
T - provider Java type.
Parameters:
providerContract - provider contract class.
Returns:
instances of all internally registered providers of the given provider type.

getCustom

public <T> java.util.List<T> getCustom(java.lang.Class<T> providerContract,
                                       java.util.Comparator<T> comparator)
Get all provider instances of the requested provider type from the list of internally registered provider instances and classes. This method does not perform service provider lookup in META-INF/services.

The returned provider list, if not empty, is sorted using the supplied comparator before it is returned.

Type Parameters:
T - provider Java type.
Parameters:
providerContract - provider contract class.
comparator - contract comparator used for ordering provider instances in the set.
Returns:
sorted list of instances of all internally registered providers of the given provider type.

getDefault

public <T> java.util.Set<T> getDefault(java.lang.Class<T> providerContract)
Get all provider instances of the requested provider type found by performing service provider lookup in META-INF/services. This method ignores any internally registered provider instances or classes.

Type Parameters:
T - provider Java type.
Parameters:
providerContract - provider contract class.
Returns:
instances of all providers of the given provider type found during the service provider lookup.

getDefault

public <T> java.util.List<T> getDefault(java.lang.Class<T> providerContract,
                                        java.util.Comparator<T> comparator)
Get all provider instances of the requested provider type found by performing service provider lookup in META-INF/services. This method ignores any internally registered provider instances or classes.

The returned provider list, if not empty, is sorted using the supplied comparator before it is returned.

Type Parameters:
T - provider Java type.
Parameters:
providerContract - provider contract class.
comparator - contract comparator used for ordering provider instances in the set.
Returns:
sorted list of instances of all providers of the given provider type found during the service provider lookup.

getAll

public <T> java.util.Set<T> getAll(java.lang.Class<T> providerContract)
Get all provider instances of the requested provider type found both in the internal storage as well as by performing service provider lookup in META-INF/services. This method returns a result that is a combination of the results returned by getCustom(java.lang.Class) and getDefault(java.lang.Class).

Type Parameters:
T - provider Java type.
Parameters:
providerContract - provider contract class.
Returns:
instances of all providers of the given provider type found both in the internal storage as well as during the service provider lookup.

getAll

public <T> java.util.List<T> getAll(java.lang.Class<T> providerContract,
                                    java.util.Comparator<T> comparator)
Get all provider instances of the requested provider type found both in the internal storage as well as by performing service provider lookup in META-INF/services. This method returns a result that is a combination of the results returned by getCustom(java.lang.Class) and getDefault(java.lang.Class).

The returned provider list, if not empty, is sorted using the supplied comparator before it is returned.

Type Parameters:
T - provider Java type.
Parameters:
providerContract - provider contract class.
comparator - contract comparator used for ordering provider instances in the set.
Returns:
sorted list of instances of all providers of the given provider type found both in the internal storage as well as during the service provider lookup.

getCustom

public <T> void getCustom(java.lang.Class<T> providerContract,
                          ServiceProviders.ServiceListener<T> listener)
Get all provider instances of the requested provider type from the list of internally registered provider instances and classes. This method does not perform service provider lookup in META-INF/services.

Rather than returning the list of found provider instances, the method invokes the supplied provider listener for every provider instance that matches the requested provider type.

Type Parameters:
T - provider Java type.
Parameters:
providerContract - provider contract class.
listener - provider listener invoked with every matched provider instance.

getAll

public <T> void getAll(java.lang.Class<T> providerContract,
                       ServiceProviders.ServiceListener<T> listener)
Get all provider instances of the requested provider type found both in the internal storage as well as by performing service provider lookup in META-INF/services.

Rather than returning the list of found provider instances, the method invokes the supplied provider listener for every provider instance that matches the requested provider type.

Type Parameters:
T - provider Java type.
Parameters:
providerContract - provider contract class.
listener - provider listener invoked with every matched provider instance.

instantiate

public <T> java.util.List<T> instantiate(java.lang.Class<T> providerContract,
                                         java.lang.String[] classNames)
Instantiate providers of the given type using the array of provider implementation class names.

Note that this method does not fail in case any of the implementation classes cannot be found or instantiated or if it does not match the requested provider type. Instead, a severe log entry is recorded and the failing implementation class is ignored and not included in the returned list of provider instances.

Type Parameters:
T - requested provider Java type.
Parameters:
providerContract - provider contract class.
classNames - provider implementation class names.
Returns:
provider instances instantiated from the supplied provider implementation class names.

instantiate

public <T> java.util.List<T> instantiate(java.lang.Class<T> providerContract,
                                         java.lang.Class<? extends T>[] classes)
Instantiate providers of the given type using the array of provider implementation classes.

Note that this method does not fail in case any of the implementation classes cannot be instantiated or if it does not match the requested provider type. Instead, a severe log entry is recorded and the failing implementation class is ignored and not included in the returned list of provider instances.

Type Parameters:
T - requested provider Java type.
Parameters:
providerContract - provider contract class.
classes - provider implementation classes.
Returns:
provider instances instantiated from the supplied provider implementation class names.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.