Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.eclipse.gemini.blueprint.util
Class OsgiListenerUtils

    java.lang.Object
      org.eclipse.gemini.blueprint.util.OsgiListenerUtils

    public abstract class OsgiListenerUtils

extends Object

Utility class for dealing with various OSGi listeners, mainly `ServiceListener`s. This class contains common functionality such as broadcasting events or safely registering an OSGi listener.

Author:
  Costin Leau

Constructor Summary
`OsgiListenerUtils()`

Method Summary
`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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### OsgiListenerUtils

    public OsgiListenerUtils()

Method Detail

### addServiceListener

    public 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. This method will deliver synthetic events of type `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 problem

  Parameters:
    `context` - bundle context to register the listener with
    `listener` - service listener to be registered
    `filter` - OSGi filter (given as a Filter) for registering the listener (can be `null`)
  See Also:
    `addServiceListener(BundleContext, ServiceListener, String)`

### addServiceListener

    public 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. The method will also retrieve all the services registered before the listener registration (that match the given filter) and will inform the listener through service events of type `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 problem

  Parameters:
    `context` - bundle context to register the listener with
    `listener` - service listener to be registered
    `filter` - OSGi filter (given as a String) for registering the listener (can be `null`)
  See Also:
    `BundleContext.getServiceReference(String)`, `BundleContext.getServiceReferences(String, String)`

### addSingleServiceListener

    public 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. This method will deliver at most one synthetic event of type `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 problem

  Parameters:
    `context` - bundle context to register the listener with
    `listener` - service listener to be registered
    `filter` - OSGi filter (given as a Filter) for registering the listener (can be `null`)
  See Also:
    `addSingleServiceListener(BundleContext, ServiceListener, String)`

### addSingleServiceListener

    public 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. The method will also retrieve the best matching service registered before the listener registration and will inform the listener through a service event of type `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 problem

  Parameters:
    `context` - bundle context to register the listener with
    `listener` - service listener to be registered
    `filter` - OSGi filter (given as a String) for registering the listener (can be `null`)
  See Also:
    `BundleContext.getServiceReference(String)`, `BundleContext.getServiceReferences(String, String)`

### removeServiceListener

    public static boolean removeServiceListener(org.osgi.framework.BundleContext context,
                                                org.osgi.framework.ServiceListener listener)

  Removes a service listener from the given bundle context. This method simply takes care of any exceptions that might be thrown (in case the context is invalid).

  Parameters:
    `context` - bundle context to unregister the listener from
    `listener` - service listener to unregister
  Returns:
    true if the listener unregistration has succeeded, false otherwise (for example if the bundle context is invalid)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2006-2013. All Rights Reserved.