- java.lang.Object
-
- org.apache.logging.log4j.util.ServiceRegistry
-
@InternalApi public final class ServiceRegistry extends Object
Registry for service instances loaded fromServiceLoader
. This abstracts the differences between using a flat classpath, a module path, and OSGi modules.- Since:
- 3.0.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ServiceRegistry
getInstance()
Returns the singleton ServiceRegistry instance.<S> List<S>
getServices(Class<S> serviceType, MethodHandles.Lookup lookup, Predicate<S> validator)
Gets service instances loaded from the calling context and any previously registered bundle services.<S> void
loadServicesFromBundle(Class<S> serviceType, long bundleId, ClassLoader bundleClassLoader)
Loads and registers services from an OSGi context.<S> void
registerBundleServices(Class<S> serviceType, long bundleId, List<S> services)
Registers a list of service instances from an OSGi context.void
unregisterBundleServices(long bundleId)
Unregisters all services instances from an OSGi context.
-
-
-
Method Detail
-
getInstance
public static ServiceRegistry getInstance()
Returns the singleton ServiceRegistry instance.
-
getServices
public <S> List<S> getServices(Class<S> serviceType, MethodHandles.Lookup lookup, Predicate<S> validator)
Gets service instances loaded from the calling context and any previously registered bundle services. TheloaderCallerContext
parameter is provided to ensure the caller can specify which calling function context to load services.- Type Parameters:
S
- type of service- Parameters:
serviceType
- service classlookup
- MethodHandle lookup created in same module as caller context to use for loading servicesvalidator
- if non-null, used to validate service instances, removing invalid instances from the returned list- Returns:
- loaded service instances
-
loadServicesFromBundle
public <S> void loadServicesFromBundle(Class<S> serviceType, long bundleId, ClassLoader bundleClassLoader)
Loads and registers services from an OSGi context.- Type Parameters:
S
- type of service- Parameters:
serviceType
- service classbundleId
- bundle id to load services frombundleClassLoader
- bundle ClassLoader to load services from
-
registerBundleServices
public <S> void registerBundleServices(Class<S> serviceType, long bundleId, List<S> services)
Registers a list of service instances from an OSGi context.- Type Parameters:
S
- type of service- Parameters:
serviceType
- service classbundleId
- bundle id where services are being registeredservices
- list of services to register for this bundle
-
unregisterBundleServices
public void unregisterBundleServices(long bundleId)
Unregisters all services instances from an OSGi context.- Parameters:
bundleId
- bundle id where services are being unregistered
-
-