Adds the specified {@code ServiceListener} object with the specified{@code filter} to the context bundle's list of listeners. See{@link Filter} for a description of the filter syntax.{@code ServiceListener} objects are notified when a service has alifecycle state change.
If the context bundle's list of listeners already contains a listener {@code l} such that {@code (l==listener)}, then this method replaces that listener's filter (which may be {@code null}) with the specified one (which may be {@code null}).
The listener is called if the filter criteria is met. To filter based upon the class of the service, the filter should reference the {@link Constants#OBJECTCLASS} property. If {@code filter} is {@code null}, all services are considered to match the filter.
When using a {@code filter}, it is possible that the {@code ServiceEvent}s for the complete lifecycle of a service will not be delivered to the listener. For example, if the {@code filter} only matches when theproperty {@code x} has the value {@code 1}, the listener will not be called if the service is registered with the property {@code x} not setto the value {@code 1}. Subsequently, when the service is modified setting property {@code x} to the value {@code 1}, the filter will match and the listener will be called with a {@code ServiceEvent} of type{@code MODIFIED}. Thus, the listener will not be called with a {@code ServiceEvent} of type {@code REGISTERED}.
If the Java Runtime Environment supports permissions, the {@code ServiceListener} object will be notified of a service event onlyif the bundle that is registering it has the {@code ServicePermission} toget the service using at least one of the named classes the service was registered under.
@param listener The {@code ServiceListener} object to be added.
@param filter The filter criteria.
@throws InvalidSyntaxException If {@code filter} contains an invalidfilter string that cannot be parsed.
@throws IllegalStateException If this BundleContext is no longer valid.
@see ServiceEvent
@see ServiceListener
@see ServicePermission