Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBJ Hargrave2011-09-17 02:38:50 +0000
committerThomas Watson2011-09-26 14:06:14 +0000
commit27b217c6c3d7622ff2455f6ef4829778f1ee2730 (patch)
treed85b6f5b5d81f9015edaf899991fb7716eb617a6
parente13b75c05c99bc4cb16694e449bde94aaefbe57f (diff)
downloadrt.equinox.framework-27b217c6c3d7622ff2455f6ef4829778f1ee2730.tar.gz
rt.equinox.framework-27b217c6c3d7622ff2455f6ef4829778f1ee2730.tar.xz
rt.equinox.framework-27b217c6c3d7622ff2455f6ef4829778f1ee2730.zip
Bug 358897 - [R4.4] UnfilteredServiceListener support
-rw-r--r--bundles/org.eclipse.osgi/.settings/.api_filters9
-rwxr-xr-xbundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/FilteredServiceListener.java7
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/UnfilteredServiceListener.java73
3 files changed, 87 insertions, 2 deletions
diff --git a/bundles/org.eclipse.osgi/.settings/.api_filters b/bundles/org.eclipse.osgi/.settings/.api_filters
index af6340943..18c2d4c9d 100644
--- a/bundles/org.eclipse.osgi/.settings/.api_filters
+++ b/bundles/org.eclipse.osgi/.settings/.api_filters
@@ -890,6 +890,15 @@
</message_arguments>
</filter>
</resource>
+ <resource path="osgi/src/org/osgi/framework/UnfilteredServiceListener.java" type="org.osgi.framework.UnfilteredServiceListener">
+ <filter id="1108344834">
+ <message_arguments>
+ <message_argument value="1.7"/>
+ <message_argument value="3.8"/>
+ <message_argument value="org.osgi.framework.UnfilteredServiceListener"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="osgi/src/org/osgi/framework/Version.java" type="org.osgi.framework.Version">
<filter id="1143996420">
<message_arguments>
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/FilteredServiceListener.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/FilteredServiceListener.java
index 64aef1b71..528d8d2e6 100755
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/FilteredServiceListener.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/serviceregistry/FilteredServiceListener.java
@@ -29,6 +29,8 @@ class FilteredServiceListener implements ServiceListener, ListenerHook.ListenerI
private final BundleContextImpl context;
/** is this an AllServiceListener */
private final boolean allservices;
+ /** is this an UnfilteredServiceListener */
+ private final boolean unfiltered;
/** an objectClass required by the filter */
private final String objectClass;
/** indicates whether the listener has been removed */
@@ -43,13 +45,14 @@ class FilteredServiceListener implements ServiceListener, ListenerHook.ListenerI
* @exception InvalidSyntaxException if the filter is invalid.
*/
FilteredServiceListener(final BundleContextImpl context, final ServiceListener listener, final String filterstring) throws InvalidSyntaxException {
+ this.unfiltered = (listener instanceof UnfilteredServiceListener);
if (filterstring == null) {
this.filter = null;
this.objectClass = null;
} else {
FilterImpl filterImpl = FilterImpl.newInstance(filterstring);
String clazz = filterImpl.getRequiredObjectClass();
- if (clazz == null) {
+ if (unfiltered || (clazz == null)) {
this.objectClass = null;
this.filter = filterImpl;
} else {
@@ -115,7 +118,7 @@ class FilteredServiceListener implements ServiceListener, ListenerHook.ListenerI
private ServiceEvent filterMatch(ServiceEvent delivered) {
boolean modified = delivered.getType() == ServiceEvent.MODIFIED;
ServiceEvent event = modified ? ((ModifiedServiceEvent) delivered).getModifiedEvent() : delivered;
- if (filter == null) {
+ if (unfiltered || (filter == null)) {
return event;
}
ServiceReference<?> reference = event.getServiceReference();
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/UnfilteredServiceListener.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/UnfilteredServiceListener.java
new file mode 100644
index 000000000..d712fcf1b
--- /dev/null
+++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/UnfilteredServiceListener.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) OSGi Alliance (2011). All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.osgi.framework;
+
+import org.osgi.framework.hooks.service.ListenerHook;
+
+/**
+ * A {@code ServiceEvent} listener that does <i>not</i> filter based upon any
+ * filter string specified to
+ * {@link BundleContext#addServiceListener(ServiceListener, String)}. Using an
+ * {@code UnfilteredServiceListener} and specifying a filter string to
+ * {@link BundleContext#addServiceListener(ServiceListener, String)} allows the
+ * listener to receive all {@code ServiceEvent} objects while still advising
+ * {@link ListenerHook} implementation of the service interests in the filter
+ * string.
+ *
+ * For example, an implementation of Declarative Services would add an
+ * {@code UnfilteredServiceListener} with a filter string listing all the
+ * services referenced by all the service components. The Declarative Services
+ * implementation would receive all {@code ServiceEvent} objects for internal
+ * processing and a Remote Services discovery service implementation can observe
+ * the service interests of the service components using a {@link ListenerHook}.
+ * When the set of service components being processed changes, the Declarative
+ * Services implementation would re-add the {@code UnfilteredServiceListener}
+ * with an updated filter string.
+ *
+ * <p>
+ * When a {@code ServiceEvent} is fired, it is synchronously delivered to an
+ * {@code UnfilteredServiceListener}. The Framework may deliver
+ * {@code ServiceEvent} objects to an {@code UnfilteredServiceListener} out of
+ * order and may concurrently call and/or reenter an
+ * {@code UnfilteredServiceListener}.
+ *
+ * <p>
+ * An {@code UnfilteredServiceListener} object is registered with the Framework
+ * using the {@code BundleContext.addServiceListener} method.
+ * {@code UnfilteredServiceListener} objects are called with a
+ * {@code ServiceEvent} object when a service is registered, modified, or is in
+ * the process of unregistering.
+ *
+ * <p>
+ * {@code ServiceEvent} object delivery to {@code UnfilteredServiceListener}
+ * objects are <i>not</i> filtered by the filter specified when the listener was
+ * registered. If the Java Runtime Environment supports permissions, then some
+ * filtering is done. {@code ServiceEvent} objects are only delivered to the
+ * listener if the bundle which defines the listener object's class has the
+ * appropriate {@code ServicePermission} to get the service using at least one
+ * of the named classes under which the service was registered.
+ *
+ * @see ServiceEvent
+ * @see ServicePermission
+ * @ThreadSafe
+ * @since 1.7
+ * @version $Id: 543a345802f8dc7a49d29e8fb7aee7004ee2b329 $
+ */
+
+public interface UnfilteredServiceListener extends ServiceListener {
+ // This is a marker interface
+}

Back to the top