Class ServiceLocatorFactoryImpl
ServiceLocatorFactory
that looks
in the OSGi service registry or the META-INF/services for the implementation
to use. Failing those things, it uses the standard default locator
generator, which is found in auto-depends, which is the 99.9% case-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Nested classes/interfaces inherited from class org.glassfish.hk2.api.ServiceLocatorFactory
ServiceLocatorFactory.CreatePolicy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final boolean
private static final String
private static final String
private final HashSet
<ServiceLocatorListener> private final Object
private static int
private final HashMap
<String, ServiceLocator> private static final Object
-
Constructor Summary
ConstructorsConstructorDescriptionThis will create a new set of name to locator mappings -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(ServiceLocatorListener listener) Adds a service listener to the unordered set of listeners that will be notified when named listeners are added or removed from the system.private void
callListenerAdded
(ServiceLocator added) Creates (or finds) a ServiceLocator.create
(String name, ServiceLocator parent) Creates or finds a ServiceLocator.create
(String name, ServiceLocator parent, ServiceLocatorGenerator generator) Creates or finds a ServiceLocator.create
(String name, ServiceLocator parent, ServiceLocatorGenerator generator, ServiceLocatorFactory.CreatePolicy policy) Creates a ServiceLocator.void
Removes the ServiceLocator with this nameprivate void
destroy
(String name, ServiceLocator locator) void
destroy
(ServiceLocator locator) Removes the given ServiceLocatorFinds the ServiceLocator with this nameprivate static String
private static ServiceLocatorGenerator
private static ServiceLocatorGenerator
private static Iterable
<? extends ServiceLocatorGenerator> private ServiceLocator
internalCreate
(String name, ServiceLocator parent, ServiceLocatorGenerator generator) void
removeListener
(ServiceLocatorListener listener) Removes a service listener from the set of listeners that are notified when named listeners are added or removed from the systemMethods inherited from class org.glassfish.hk2.api.ServiceLocatorFactory
getInstance
-
Field Details
-
DEBUG_SERVICE_LOCATOR_PROPERTY
- See Also:
-
DEBUG_SERVICE_LOCATOR_LIFECYCLE
private static final boolean DEBUG_SERVICE_LOCATOR_LIFECYCLE -
sLock
-
name_count
private static int name_count -
GENERATED_NAME_PREFIX
- See Also:
-
lock
-
serviceLocators
-
listeners
-
-
Constructor Details
-
ServiceLocatorFactoryImpl
public ServiceLocatorFactoryImpl()This will create a new set of name to locator mappings
-
-
Method Details
-
getGeneratorSecure
-
getOSGiSafeGenerators
-
getGenerator
-
create
Description copied from class:ServiceLocatorFactory
Creates (or finds) a ServiceLocator.If there is already a ServiceLocator with the given name then this method will return that locator.
- Specified by:
create
in classServiceLocatorFactory
- Parameters:
name
- The name of this service locator. Passing a null name will result in a newly created service locator with a generated name and that will not be tracked by the system- Returns:
- The created or found named ServiceLocator
-
find
Description copied from class:ServiceLocatorFactory
Finds the ServiceLocator with this name- Specified by:
find
in classServiceLocatorFactory
- Parameters:
name
- May not be null, is the name of the ServiceLocator to find- Returns:
- The ServiceLocator with the given name, or null if there is no ServiceLocator with that name
-
destroy
Description copied from class:ServiceLocatorFactory
Removes the ServiceLocator with this nameAll services associated with this ServiceLocator will be shutdown
- Specified by:
destroy
in classServiceLocatorFactory
- Parameters:
name
- The name of the ServiceLocator to destroy
-
destroy
-
destroy
Description copied from class:ServiceLocatorFactory
Removes the given ServiceLocatorAll services associated with this ServiceLocator will be shutdown
- Specified by:
destroy
in classServiceLocatorFactory
- Parameters:
locator
- The ServiceLocator to destroy. If null this will do nothing. If the ServiceLocator given was already destroyed this will do nothing
-
create
Description copied from class:ServiceLocatorFactory
Creates or finds a ServiceLocator.If there is already a ServiceLocator with the given name then this method will return that ServiceLocator. The parent argument will be ignored in that case
- Specified by:
create
in classServiceLocatorFactory
- Parameters:
name
- The name of this service locator. Passing a null name will result in a newly created service locator with a generated name and that will not be tracked by the systemparent
- The parent of this ServiceLocator. Services can be found in the parent (and all grand-parents). May be null if the returned ServiceLocator should not be parented- Returns:
- The created or found named ServiceLocator
-
getGeneratedName
-
create
Description copied from class:ServiceLocatorFactory
Creates or finds a ServiceLocator.If there is already a ServiceLocator with the given name then this method will return that ServiceLocator. The parent argument will be ignored in that case. If a null name is given then a new ServiceLocator with a generated name will be returned.
- Specified by:
create
in classServiceLocatorFactory
- Parameters:
name
- The name of this service locator. Passing a null name will result in a newly created service locator with a generated name and that will not be tracked by the systemparent
- The parent of this ServiceLocator. Services can be found in the parent (and all grand-parents). May be null if the returned ServiceLocator should not be parentedgenerator
- An implementation of the generator interface that can be used to provide an implementation of ServiceLocator. If null then the generator used will be discovered from the OSGi service registry or from META-INF/services- Returns:
- The created or found named ServiceLocator
-
callListenerAdded
-
create
public ServiceLocator create(String name, ServiceLocator parent, ServiceLocatorGenerator generator, ServiceLocatorFactory.CreatePolicy policy) Description copied from class:ServiceLocatorFactory
Creates a ServiceLocator.If there is already a ServiceLocator with the given name then this method will honor the given CreatePolicy. return that ServiceLocator. The policies are
- RETURN: Return the existing locator
- DESTOY: Destroy the existing locator
- ERROR: Throw an IllegalStateException exception
- Specified by:
create
in classServiceLocatorFactory
- Parameters:
name
- The name of this service locator. Passing a null name will result in a newly created service locator with a generated name and that will not be tracked by the systemparent
- The parent of this ServiceLocator. Services can be found in the parent (and all grand-parents). May be null if the returned ServiceLocator should not be parentedgenerator
- An implementation of the generator interface that can be used to provide an implementation of ServiceLocator. If null then the generator used will be discovered from the OSGi service registry or from META-INF/servicespolicy
- The policy that should be used if there is an existing locator with the non-null name. If null the policy of RETURN will be used- Returns:
- The created or found named ServiceLocator
-
internalCreate
private ServiceLocator internalCreate(String name, ServiceLocator parent, ServiceLocatorGenerator generator) -
addListener
Description copied from class:ServiceLocatorFactory
Adds a service listener to the unordered set of listeners that will be notified when named listeners are added or removed from the system. If this listener is already registered this method does nothing- Specified by:
addListener
in classServiceLocatorFactory
- Parameters:
listener
- The non-null listener to add to the system
-
removeListener
Description copied from class:ServiceLocatorFactory
Removes a service listener from the set of listeners that are notified when named listeners are added or removed from the system- Specified by:
removeListener
in classServiceLocatorFactory
- Parameters:
listener
- The non-null listener to remove from the system
-