public abstract class OsgiListenerUtils extends Object
ServiceListener
s. This class contains common functionality such as
broadcasting events or safely registering an OSGi listener.Constructor and Description |
---|
OsgiListenerUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addServiceListener(org.osgi.framework.BundleContext context,
org.osgi.framework.ServiceListener listener,
org.osgi.framework.Filter filter)
Adds a service listener to the given bundle context under the specified
filter.
|
static void |
addServiceListener(org.osgi.framework.BundleContext context,
org.osgi.framework.ServiceListener listener,
String filter)
Adds a service listener to the given bundle context under the specified
filter given as a String.
|
static void |
addSingleServiceListener(org.osgi.framework.BundleContext context,
org.osgi.framework.ServiceListener listener,
org.osgi.framework.Filter filter)
Adds a service listener to the given bundle context, under the specified
filter.
|
static void |
addSingleServiceListener(org.osgi.framework.BundleContext context,
org.osgi.framework.ServiceListener listener,
String filter)
Adds a service listener to the given application context, under the
specified filter given as a String.
|
static boolean |
removeServiceListener(org.osgi.framework.BundleContext context,
org.osgi.framework.ServiceListener listener)
Removes a service listener from the given bundle context.
|
public static void addServiceListener(org.osgi.framework.BundleContext context, org.osgi.framework.ServiceListener listener, org.osgi.framework.Filter filter)
REGISTERED
for all existing services (that
match the given filter) as if the services were registered after the
listener registration.
This might cause problems if a service is registered between the
listener registration and the retrieval of existing services since the
listener will receive two events for the same service. For most listeners
implementations however, this should not be a problemcontext
- bundle context to register the listener withlistener
- service listener to be registeredfilter
- OSGi filter (given as a Filter) for registering the
listener (can be null
)addServiceListener(BundleContext, ServiceListener, String)
public static void addServiceListener(org.osgi.framework.BundleContext context, org.osgi.framework.ServiceListener listener, String filter)
REGISTERED
.
This might cause problems if a service is registered between the
listener registration and the retrieval of existing services since the
listener will receive two events for the same service. For most listeners
implementations however, this should not be a problemcontext
- bundle context to register the listener withlistener
- service listener to be registeredfilter
- OSGi filter (given as a String) for registering the
listener (can be null
)BundleContext.getServiceReference(String)
,
BundleContext.getServiceReferences(String, String)
public static void addSingleServiceListener(org.osgi.framework.BundleContext context, org.osgi.framework.ServiceListener listener, org.osgi.framework.Filter filter)
REGISTERED
for the best matching
existing service as if the services were registered after the listener
registration.
This might cause problems if a service is registered between the
listener registration and the retrieval of existing services since the
listener will receive two events for the same service. For most listeners
implementations however, this should not be a problemcontext
- bundle context to register the listener withlistener
- service listener to be registeredfilter
- OSGi filter (given as a Filter) for registering the
listener (can be null
)addSingleServiceListener(BundleContext, ServiceListener, String)
public static void addSingleServiceListener(org.osgi.framework.BundleContext context, org.osgi.framework.ServiceListener listener, String filter)
REGISTERED
. This is the only difference from
addServiceListener(BundleContext, ServiceListener, Filter)
which
considers all services, not just the best match.
This might cause problems if a service is registered between the
listener registration and the retrieval of existing services since the
listener will receive two events for the same service. For most listeners
implementations however, this should not be a problemcontext
- bundle context to register the listener withlistener
- service listener to be registeredfilter
- OSGi filter (given as a String) for registering the
listener (can be null
)BundleContext.getServiceReference(String)
,
BundleContext.getServiceReferences(String, String)
public static boolean removeServiceListener(org.osgi.framework.BundleContext context, org.osgi.framework.ServiceListener listener)
context
- bundle context to unregister the listener fromlistener
- service listener to unregisterCopyright © 2006–2019. All rights reserved.