public class ServiceLocatorFactoryImpl extends ServiceLocatorFactory
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% caseModifier and Type | Class and Description |
---|---|
private static class |
ServiceLocatorFactoryImpl.DefaultGeneratorInitializer |
ServiceLocatorFactory.CreatePolicy
Modifier and Type | Field and Description |
---|---|
private static boolean |
DEBUG_SERVICE_LOCATOR_LIFECYCLE |
private static java.lang.String |
DEBUG_SERVICE_LOCATOR_PROPERTY |
private static java.lang.String |
GENERATED_NAME_PREFIX |
private java.util.HashSet<ServiceLocatorListener> |
listeners |
private java.lang.Object |
lock |
private static int |
name_count |
private java.util.HashMap<java.lang.String,ServiceLocator> |
serviceLocators |
private static java.lang.Object |
sLock |
Constructor and Description |
---|
ServiceLocatorFactoryImpl()
This will create a new set of name to locator mappings
|
Modifier and Type | Method and Description |
---|---|
void |
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) |
ServiceLocator |
create(java.lang.String name)
Creates (or finds) a ServiceLocator.
|
ServiceLocator |
create(java.lang.String name,
ServiceLocator parent)
Creates or finds a ServiceLocator.
|
ServiceLocator |
create(java.lang.String name,
ServiceLocator parent,
ServiceLocatorGenerator generator)
Creates or finds a ServiceLocator.
|
ServiceLocator |
create(java.lang.String name,
ServiceLocator parent,
ServiceLocatorGenerator generator,
ServiceLocatorFactory.CreatePolicy policy)
Creates a ServiceLocator.
|
void |
destroy(ServiceLocator locator)
Removes the given ServiceLocator
|
void |
destroy(java.lang.String name)
Removes the ServiceLocator with this name
|
private void |
destroy(java.lang.String name,
ServiceLocator locator) |
ServiceLocator |
find(java.lang.String name)
Finds the ServiceLocator with this name
|
private static java.lang.String |
getGeneratedName() |
private static ServiceLocatorGenerator |
getGenerator() |
private static ServiceLocatorGenerator |
getGeneratorSecure() |
private static java.lang.Iterable<? extends ServiceLocatorGenerator> |
getOSGiSafeGenerators() |
private ServiceLocator |
internalCreate(java.lang.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 system
|
getInstance
private static final java.lang.String DEBUG_SERVICE_LOCATOR_PROPERTY
private static final boolean DEBUG_SERVICE_LOCATOR_LIFECYCLE
private static final java.lang.Object sLock
private static int name_count
private static final java.lang.String GENERATED_NAME_PREFIX
private final java.lang.Object lock
private final java.util.HashMap<java.lang.String,ServiceLocator> serviceLocators
private final java.util.HashSet<ServiceLocatorListener> listeners
public ServiceLocatorFactoryImpl()
private static ServiceLocatorGenerator getGeneratorSecure()
private static java.lang.Iterable<? extends ServiceLocatorGenerator> getOSGiSafeGenerators()
private static ServiceLocatorGenerator getGenerator()
public ServiceLocator create(java.lang.String name)
ServiceLocatorFactory
If there is already a ServiceLocator with the given name then this method will return that locator.
create
in class ServiceLocatorFactory
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 systempublic ServiceLocator find(java.lang.String name)
ServiceLocatorFactory
find
in class ServiceLocatorFactory
name
- May not be null, is the name of the ServiceLocator to findpublic void destroy(java.lang.String name)
ServiceLocatorFactory
All services associated with this ServiceLocator will be shutdown
destroy
in class ServiceLocatorFactory
name
- The name of the ServiceLocator to destroyprivate void destroy(java.lang.String name, ServiceLocator locator)
public void destroy(ServiceLocator locator)
ServiceLocatorFactory
All services associated with this ServiceLocator will be shutdown
destroy
in class ServiceLocatorFactory
locator
- The ServiceLocator to destroy. If null this will do nothing.
If the ServiceLocator given was already destroyed this will do nothingpublic ServiceLocator create(java.lang.String name, ServiceLocator parent)
ServiceLocatorFactory
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
create
in class ServiceLocatorFactory
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 parentedprivate static java.lang.String getGeneratedName()
public ServiceLocator create(java.lang.String name, ServiceLocator parent, ServiceLocatorGenerator generator)
ServiceLocatorFactory
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.
create
in class ServiceLocatorFactory
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/servicesprivate void callListenerAdded(ServiceLocator added)
public ServiceLocator create(java.lang.String name, ServiceLocator parent, ServiceLocatorGenerator generator, ServiceLocatorFactory.CreatePolicy policy)
ServiceLocatorFactory
If there is already a ServiceLocator with the given name then this method will honor the given CreatePolicy. return that ServiceLocator. The policies are
create
in class ServiceLocatorFactory
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 usedprivate ServiceLocator internalCreate(java.lang.String name, ServiceLocator parent, ServiceLocatorGenerator generator)
public void addListener(ServiceLocatorListener listener)
ServiceLocatorFactory
addListener
in class ServiceLocatorFactory
listener
- The non-null listener to add to the systempublic void removeListener(ServiceLocatorListener listener)
ServiceLocatorFactory
removeListener
in class ServiceLocatorFactory
listener
- The non-null listener to remove from the system