86
|
1 /*
|
|
2 * $Header: /cvshome/build/org.osgi.util.tracker/src/org/osgi/util/tracker/ServiceTracker.java,v 1.22 2006/07/20 16:14:43 hargrave Exp $
|
|
3 *
|
|
4 * Copyright (c) OSGi Alliance (2000, 2007). All Rights Reserved.
|
|
5 *
|
|
6 * Licensed under the Apache License, Version 2.0 (the "License");
|
|
7 * you may not use this file except in compliance with the License.
|
|
8 * You may obtain a copy of the License at
|
|
9 *
|
|
10 * http://www.apache.org/licenses/LICENSE-2.0
|
|
11 *
|
|
12 * Unless required by applicable law or agreed to in writing, software
|
|
13 * distributed under the License is distributed on an "AS IS" BASIS,
|
|
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15 * See the License for the specific language governing permissions and
|
|
16 * limitations under the License.
|
|
17 */
|
|
18
|
|
19 module org.osgi.util.tracker.ServiceTracker;
|
|
20 import org.osgi.util.tracker.ServiceTrackerCustomizer;
|
|
21
|
|
22 import java.lang.all;
|
|
23 import java.util.ArrayList;
|
|
24 import java.util.Enumeration;
|
|
25 import java.util.Hashtable;
|
|
26 import java.util.LinkedList;
|
|
27
|
|
28 //FIXME tmp remove: import org.eclipse.osgi.framework.internal.core.FilterImpl;
|
|
29 //FIXME tmp remove: import org.osgi.framework.AllServiceListener;
|
|
30 import org.osgi.framework.BundleContext;
|
|
31 //FIXME tmp remove: import org.osgi.framework.Constants;
|
|
32 import org.osgi.framework.Filter;
|
|
33 //FIXME tmp remove: import org.osgi.framework.InvalidSyntaxException;
|
|
34 import org.osgi.framework.ServiceEvent;
|
|
35 import org.osgi.framework.ServiceListener;
|
|
36 import org.osgi.framework.ServiceReference;
|
|
37
|
|
38 /**
|
|
39 * The <code>ServiceTracker</code> class simplifies using services from the
|
|
40 * Framework's service registry.
|
|
41 * <p>
|
|
42 * A <code>ServiceTracker</code> object is constructed with search criteria
|
|
43 * and a <code>ServiceTrackerCustomizer</code> object. A
|
|
44 * <code>ServiceTracker</code> object can use the
|
|
45 * <code>ServiceTrackerCustomizer</code> object to customize the service
|
|
46 * objects to be tracked. The <code>ServiceTracker</code> object can then be
|
|
47 * opened to begin tracking all services in the Framework's service registry
|
|
48 * that match the specified search criteria. The <code>ServiceTracker</code>
|
|
49 * object correctly handles all of the details of listening to
|
|
50 * <code>ServiceEvent</code> objects and getting and ungetting services.
|
|
51 * <p>
|
|
52 * The <code>getServiceReferences</code> method can be called to get
|
|
53 * references to the services being tracked. The <code>getService</code> and
|
|
54 * <code>getServices</code> methods can be called to get the service objects
|
|
55 * for the tracked service.
|
|
56 * <p>
|
|
57 * The <code>ServiceTracker</code> class is thread-safe. It does not call a
|
|
58 * <code>ServiceTrackerCustomizer</code> object while holding any locks.
|
|
59 * <code>ServiceTrackerCustomizer</code> implementations must also be
|
|
60 * thread-safe.
|
|
61 *
|
|
62 * @ThreadSafe
|
|
63 * @version $Revision: 1.29 $
|
|
64 */
|
|
65
|
|
66 /*
|
|
67 * This implementation has been customized to only work with the Equinox OSGi framework.
|
|
68 * In all cases a filter string containing objectClass is passed to BundleContext.addServiceListener
|
|
69 * to take advantage of the ServiceEvent delivery optimizations.
|
|
70 */
|
|
71
|
|
72 public class ServiceTracker : ServiceTrackerCustomizer {
|
|
73 public this(BundleContext context, ServiceReference reference, ServiceTrackerCustomizer customizer) {
|
|
74 implMissing(__FILE__,__LINE__);
|
|
75 }
|
|
76 public this(BundleContext context, String clazz, ServiceTrackerCustomizer customizer) {
|
|
77 implMissing(__FILE__,__LINE__);
|
|
78 }
|
|
79 public this(BundleContext context, Filter filter, ServiceTrackerCustomizer customizer) {
|
|
80 implMissing(__FILE__,__LINE__);
|
|
81 }
|
|
82 public Object addingService(ServiceReference reference){
|
|
83 implMissing(__FILE__,__LINE__);
|
|
84 return null;
|
|
85 }
|
|
86 public void modifiedService(ServiceReference reference, Object service){
|
|
87 implMissing(__FILE__,__LINE__);
|
|
88 }
|
|
89 public void removedService(ServiceReference reference, Object service){
|
|
90 implMissing(__FILE__,__LINE__);
|
|
91 }
|
|
92 public void open() {
|
|
93 implMissing(__FILE__,__LINE__);
|
|
94 }
|
|
95 public void open( bool trackAll) {
|
|
96 implMissing(__FILE__,__LINE__);
|
|
97 }
|
|
98 public synchronized void close() {
|
|
99 implMissing(__FILE__,__LINE__);
|
|
100 }
|
|
101 public Object getService(ServiceReference reference) {
|
|
102 implMissing(__FILE__,__LINE__);
|
|
103 return null;
|
|
104 }
|
|
105 public Object getService() {
|
|
106 implMissing(__FILE__,__LINE__);
|
|
107 return null;
|
|
108 }
|
|
109 }
|
|
110 //FIXME Dummy class
|
|
111 /+++
|
|
112 public class ServiceTracker : ServiceTrackerCustomizer {
|
|
113 /* set this to true to compile in debug messages */
|
|
114 static final bool DEBUG = false;
|
|
115 /**
|
|
116 * Bundle context against which this <code>ServiceTracker</code> object is
|
|
117 * tracking.
|
|
118 */
|
|
119 protected final BundleContext context;
|
|
120 /**
|
|
121 * Filter specifying search criteria for the services to track.
|
|
122 *
|
|
123 * @since 1.1
|
|
124 */
|
|
125 protected final Filter filter;
|
|
126 /**
|
|
127 * <code>ServiceTrackerCustomizer</code> object for this tracker.
|
|
128 */
|
|
129 final ServiceTrackerCustomizer customizer;
|
|
130 /**
|
|
131 * Filter string for use when adding the ServiceListener.
|
|
132 */
|
|
133 private final String listenerFilter;
|
|
134 /**
|
|
135 * Class name to be tracked. If this field is set, then we are tracking by
|
|
136 * class name.
|
|
137 */
|
|
138 private final String trackClass;
|
|
139 /**
|
|
140 * Reference to be tracked. If this field is set, then we are tracking a
|
|
141 * single ServiceReference.
|
|
142 */
|
|
143 private final ServiceReference trackReference;
|
|
144 /**
|
|
145 * True if no Filter object was supplied in a constructor or we are not
|
|
146 * using the supplied filter.
|
|
147 */
|
|
148 final bool noUserFilter;
|
|
149 /**
|
|
150 * Tracked services: <code>ServiceReference</code> object -> customized
|
|
151 * Object and <code>ServiceListener</code> object
|
|
152 */
|
|
153 private volatile Tracked tracked;
|
|
154 /**
|
|
155 * Modification count. This field is initialized to zero by open, set to -1
|
|
156 * by close and incremented by modified.
|
|
157 *
|
|
158 * This field is volatile since it is accessed by multiple threads.
|
|
159 */
|
|
160 private volatile int trackingCount = -1;
|
|
161 /**
|
|
162 * Cached ServiceReference for getServiceReference.
|
|
163 *
|
|
164 * This field is volatile since it is accessed by multiple threads.
|
|
165 */
|
|
166 private volatile ServiceReference cachedReference;
|
|
167 /**
|
|
168 * Cached service object for getService.
|
|
169 *
|
|
170 * This field is volatile since it is accessed by multiple threads.
|
|
171 */
|
|
172 private volatile Object cachedService;
|
|
173
|
|
174 /**
|
|
175 * Create a <code>ServiceTracker</code> object on the specified
|
|
176 * <code>ServiceReference</code> object.
|
|
177 *
|
|
178 * <p>
|
|
179 * The service referenced by the specified <code>ServiceReference</code>
|
|
180 * object will be tracked by this <code>ServiceTracker</code> object.
|
|
181 *
|
|
182 * @param context <code>BundleContext</code> object against which the
|
|
183 * tracking is done.
|
|
184 * @param reference <code>ServiceReference</code> object for the service
|
|
185 * to be tracked.
|
|
186 * @param customizer The customizer object to call when services are added,
|
|
187 * modified, or removed in this <code>ServiceTracker</code> object.
|
|
188 * If customizer is <code>null</code>, then this
|
|
189 * <code>ServiceTracker</code> object will be used as the
|
|
190 * <code>ServiceTrackerCustomizer</code> object and the
|
|
191 * <code>ServiceTracker</code> object will call the
|
|
192 * <code>ServiceTrackerCustomizer</code> methods on itself.
|
|
193 */
|
|
194 public this(BundleContext context, ServiceReference reference,
|
|
195 ServiceTrackerCustomizer customizer) {
|
|
196 this.context = context;
|
|
197 this.trackReference = reference;
|
|
198 this.trackClass = null;
|
|
199 this.customizer = (customizer == null) ? this : customizer;
|
|
200 this.listenerFilter = "(&(" + Constants.OBJECTCLASS + "=" + ((String[]) reference.getProperty(Constants.OBJECTCLASS))[0] //$NON-NLS-1$ //$NON-NLS-2$
|
|
201 + ")(" + Constants.SERVICE_ID + "=" + reference.getProperty(Constants.SERVICE_ID).toString() + "))" ; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
202 this.noUserFilter = true;
|
|
203 try {
|
|
204 this.filter = context.createFilter(listenerFilter);
|
|
205 }
|
|
206 catch (InvalidSyntaxException e) { // we could only get this exception
|
|
207 // if the ServiceReference was
|
|
208 // invalid
|
|
209 throw new IllegalArgumentException(
|
|
210 "unexpected InvalidSyntaxException: " + e.getMessage()); //$NON-NLS-1$
|
|
211 }
|
|
212 }
|
|
213
|
|
214 /**
|
|
215 * Create a <code>ServiceTracker</code> object on the specified class
|
|
216 * name.
|
|
217 *
|
|
218 * <p>
|
|
219 * Services registered under the specified class name will be tracked by
|
|
220 * this <code>ServiceTracker</code> object.
|
|
221 *
|
|
222 * @param context <code>BundleContext</code> object against which the
|
|
223 * tracking is done.
|
|
224 * @param clazz Class name of the services to be tracked.
|
|
225 * @param customizer The customizer object to call when services are added,
|
|
226 * modified, or removed in this <code>ServiceTracker</code> object.
|
|
227 * If customizer is <code>null</code>, then this
|
|
228 * <code>ServiceTracker</code> object will be used as the
|
|
229 * <code>ServiceTrackerCustomizer</code> object and the
|
|
230 * <code>ServiceTracker</code> object will call the
|
|
231 * <code>ServiceTrackerCustomizer</code> methods on itself.
|
|
232 */
|
|
233 public this(BundleContext context, String clazz,
|
|
234 ServiceTrackerCustomizer customizer) {
|
|
235 this.context = context;
|
|
236 this.trackReference = null;
|
|
237 this.trackClass = clazz;
|
|
238 this.customizer = (customizer == null) ? this : customizer;
|
|
239 this.listenerFilter = "(" + Constants.OBJECTCLASS + "=" + clazz.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
240 this.noUserFilter = true;
|
|
241 try {
|
|
242 this.filter = context.createFilter(listenerFilter);
|
|
243 }
|
|
244 catch (InvalidSyntaxException e) { // we could only get this exception
|
|
245 // if the clazz argument was
|
|
246 // malformed
|
|
247 throw new IllegalArgumentException(
|
|
248 "unexpected InvalidSyntaxException: " + e.getMessage()); //$NON-NLS-1$
|
|
249 }
|
|
250 }
|
|
251
|
|
252 /**
|
|
253 * Create a <code>ServiceTracker</code> object on the specified
|
|
254 * <code>Filter</code> object.
|
|
255 *
|
|
256 * <p>
|
|
257 * Services which match the specified <code>Filter</code> object will be
|
|
258 * tracked by this <code>ServiceTracker</code> object.
|
|
259 *
|
|
260 * @param context <code>BundleContext</code> object against which the
|
|
261 * tracking is done.
|
|
262 * @param filter <code>Filter</code> object to select the services to be
|
|
263 * tracked.
|
|
264 * @param customizer The customizer object to call when services are added,
|
|
265 * modified, or removed in this <code>ServiceTracker</code> object.
|
|
266 * If customizer is null, then this <code>ServiceTracker</code>
|
|
267 * object will be used as the <code>ServiceTrackerCustomizer</code>
|
|
268 * object and the <code>ServiceTracker</code> object will call the
|
|
269 * <code>ServiceTrackerCustomizer</code> methods on itself.
|
|
270 * @since 1.1
|
|
271 */
|
|
272 public this(BundleContext context, Filter filter,
|
|
273 ServiceTrackerCustomizer customizer) {
|
|
274 this.context = context;
|
|
275 this.trackReference = null;
|
|
276
|
|
277 // obtain a required objectClass from the user supplied filter
|
|
278 if (filter instanceof FilterImpl) {
|
|
279 this.trackClass = ((FilterImpl)filter).getRequiredObjectClass();
|
|
280 } else {
|
|
281 this.trackClass = null;
|
|
282 }
|
|
283
|
|
284 if (this.trackClass != null) {
|
|
285 this.listenerFilter = FilterImpl.getObjectClassFilterString(this.trackClass);
|
|
286 //convert to track by class instead of filter if the user filter is in the form (objectClass=some.Clazz)
|
|
287 this.noUserFilter = this.listenerFilter.equals(filter.toString());
|
|
288 } else {
|
|
289 this.listenerFilter = null;
|
|
290 this.noUserFilter = false;
|
|
291 }
|
|
292
|
|
293 this.filter = filter;
|
|
294 this.customizer = (customizer == null) ? this : customizer;
|
|
295 if ((context == null) || (filter == null)) { // we throw a NPE here
|
|
296 // to
|
|
297 // be consistent with the
|
|
298 // other constructors
|
|
299 throw new NullPointerException();
|
|
300 }
|
|
301 }
|
|
302
|
|
303 /**
|
|
304 * Open this <code>ServiceTracker</code> object and begin tracking
|
|
305 * services.
|
|
306 *
|
|
307 * <p>
|
|
308 * This method calls <code>open(false)</code>.
|
|
309 *
|
|
310 * @throws java.lang.IllegalStateException if the <code>BundleContext</code>
|
|
311 * object with which this <code>ServiceTracker</code> object was
|
|
312 * created is no longer valid.
|
|
313 * @see #open(bool)
|
|
314 */
|
|
315 public void open() {
|
|
316 open(false);
|
|
317 }
|
|
318
|
|
319 /**
|
|
320 * Open this <code>ServiceTracker</code> object and begin tracking
|
|
321 * services.
|
|
322 *
|
|
323 * <p>
|
|
324 * Services which match the search criteria specified when this
|
|
325 * <code>ServiceTracker</code> object was created are now tracked by this
|
|
326 * <code>ServiceTracker</code> object.
|
|
327 *
|
|
328 * @param trackAllServices If <code>true</code>, then this
|
|
329 * <code>ServiceTracker</code> will track all matching services
|
|
330 * regardless of class loader accessibility. If <code>false</code>,
|
|
331 * then this <code>ServiceTracker</code> will only track matching
|
|
332 * services which are class loader accessibile to the bundle whose
|
|
333 * <code>BundleContext</code> is used by this
|
|
334 * <code>ServiceTracker</code>.
|
|
335 * @throws java.lang.IllegalStateException if the <code>BundleContext</code>
|
|
336 * object with which this <code>ServiceTracker</code> object was
|
|
337 * created is no longer valid.
|
|
338 * @since 1.3
|
|
339 */
|
|
340 public synchronized void open(bool trackAllServices) {
|
|
341 if (tracked != null) {
|
|
342 return;
|
|
343 }
|
|
344 if (DEBUG) {
|
|
345 System.out.println("ServiceTracker.open: " + filter); //$NON-NLS-1$
|
|
346 }
|
|
347 tracked = trackAllServices ? new AllTracked() : new Tracked();
|
|
348 trackingCount = 0;
|
|
349 synchronized (tracked) {
|
|
350 try {
|
|
351 context.addServiceListener(tracked, listenerFilter);
|
|
352 ServiceReference[] references;
|
|
353
|
|
354 if (trackReference != null) { // tracking a single reference
|
|
355 references = new ServiceReference[] {trackReference};
|
|
356 }
|
|
357 else { // tracking a set of references
|
|
358 references = getInitialReferences(trackAllServices, trackClass,
|
|
359 noUserFilter ? null: filter.toString());
|
|
360 }
|
|
361
|
|
362 tracked.setInitialServices(references); // set tracked with
|
|
363 // the initial
|
|
364 // references
|
|
365 }
|
|
366 catch (InvalidSyntaxException e) {
|
|
367 throw new RuntimeException(
|
|
368 "unexpected InvalidSyntaxException: " + e.getMessage()); //$NON-NLS-1$
|
|
369 }
|
|
370 }
|
|
371 /* Call tracked outside of synchronized region */
|
|
372 tracked.trackInitialServices(); // process the initial references
|
|
373 }
|
|
374
|
|
375 /**
|
|
376 * Returns the list of initial <code>ServiceReference</code> objects that
|
|
377 * will be tracked by this <code>ServiceTracker</code> object.
|
|
378 *
|
|
379 * @param trackAllServices If true, use getAllServiceReferences.
|
|
380 * @param trackClass the class name with which the service was registered,
|
|
381 * or null for all services.
|
|
382 * @param filterString the filter criteria or null for all services.
|
|
383 * @return the list of initial <code>ServiceReference</code> objects.
|
|
384 * @throws InvalidSyntaxException if the filter uses an invalid syntax.
|
|
385 */
|
|
386 private ServiceReference[] getInitialReferences(bool trackAllServices,
|
|
387 String trackClass, String filterString)
|
|
388 throws InvalidSyntaxException {
|
|
389 if (trackAllServices) {
|
|
390 return context.getAllServiceReferences(trackClass, filterString);
|
|
391 }
|
|
392 else {
|
|
393 return context.getServiceReferences(trackClass, filterString);
|
|
394 }
|
|
395 }
|
|
396
|
|
397 /**
|
|
398 * Close this <code>ServiceTracker</code> object.
|
|
399 *
|
|
400 * <p>
|
|
401 * This method should be called when this <code>ServiceTracker</code>
|
|
402 * object should end the tracking of services.
|
|
403 */
|
|
404 public synchronized void close() {
|
|
405 if (tracked == null) {
|
|
406 return;
|
|
407 }
|
|
408 if (DEBUG) {
|
|
409 System.out.println("ServiceTracker.close: " + filter); //$NON-NLS-1$
|
|
410 }
|
|
411 tracked.close();
|
|
412 ServiceReference[] references = getServiceReferences();
|
|
413 Tracked outgoing = tracked;
|
|
414 tracked = null;
|
|
415 try {
|
|
416 context.removeServiceListener(outgoing);
|
|
417 }
|
|
418 catch (IllegalStateException e) {
|
|
419 /* In case the context was stopped. */
|
|
420 }
|
|
421 if (references != null) {
|
|
422 for (int i = 0; i < references.length; i++) {
|
|
423 outgoing.untrack(references[i]);
|
|
424 }
|
|
425 }
|
|
426 trackingCount = -1;
|
|
427 if (DEBUG) {
|
|
428 if ((cachedReference == null) && (cachedService == null)) {
|
|
429 System.out
|
|
430 .println("ServiceTracker.close[cached cleared]: " + filter); //$NON-NLS-1$
|
|
431 }
|
|
432 }
|
|
433 }
|
|
434
|
|
435 /**
|
|
436 * Default implementation of the
|
|
437 * <code>ServiceTrackerCustomizer.addingService</code> method.
|
|
438 *
|
|
439 * <p>
|
|
440 * This method is only called when this <code>ServiceTracker</code> object
|
|
441 * has been constructed with a <code>null ServiceTrackerCustomizer</code>
|
|
442 * argument.
|
|
443 *
|
|
444 * The default implementation returns the result of calling
|
|
445 * <code>getService</code>, on the <code>BundleContext</code> object
|
|
446 * with which this <code>ServiceTracker</code> object was created, passing
|
|
447 * the specified <code>ServiceReference</code> object.
|
|
448 * <p>
|
|
449 * This method can be overridden in a subclass to customize the service
|
|
450 * object to be tracked for the service being added. In that case, take care
|
|
451 * not to rely on the default implementation of removedService that will
|
|
452 * unget the service.
|
|
453 *
|
|
454 * @param reference Reference to service being added to this
|
|
455 * <code>ServiceTracker</code> object.
|
|
456 * @return The service object to be tracked for the service added to this
|
|
457 * <code>ServiceTracker</code> object.
|
|
458 * @see ServiceTrackerCustomizer
|
|
459 */
|
|
460 public Object addingService(ServiceReference reference) {
|
|
461 return context.getService(reference);
|
|
462 }
|
|
463
|
|
464 /**
|
|
465 * Default implementation of the
|
|
466 * <code>ServiceTrackerCustomizer.modifiedService</code> method.
|
|
467 *
|
|
468 * <p>
|
|
469 * This method is only called when this <code>ServiceTracker</code> object
|
|
470 * has been constructed with a <code>null ServiceTrackerCustomizer</code>
|
|
471 * argument.
|
|
472 *
|
|
473 * The default implementation does nothing.
|
|
474 *
|
|
475 * @param reference Reference to modified service.
|
|
476 * @param service The service object for the modified service.
|
|
477 * @see ServiceTrackerCustomizer
|
|
478 */
|
|
479 public void modifiedService(ServiceReference reference, Object service) {
|
|
480 }
|
|
481
|
|
482 /**
|
|
483 * Default implementation of the
|
|
484 * <code>ServiceTrackerCustomizer.removedService</code> method.
|
|
485 *
|
|
486 * <p>
|
|
487 * This method is only called when this <code>ServiceTracker</code> object
|
|
488 * has been constructed with a <code>null ServiceTrackerCustomizer</code>
|
|
489 * argument.
|
|
490 *
|
|
491 * The default implementation calls <code>ungetService</code>, on the
|
|
492 * <code>BundleContext</code> object with which this
|
|
493 * <code>ServiceTracker</code> object was created, passing the specified
|
|
494 * <code>ServiceReference</code> object.
|
|
495 * <p>
|
|
496 * This method can be overridden in a subclass. If the default
|
|
497 * implementation of <code>addingService</code> method was used, this
|
|
498 * method must unget the service.
|
|
499 *
|
|
500 * @param reference Reference to removed service.
|
|
501 * @param service The service object for the removed service.
|
|
502 * @see ServiceTrackerCustomizer
|
|
503 */
|
|
504 public void removedService(ServiceReference reference, Object service) {
|
|
505 context.ungetService(reference);
|
|
506 }
|
|
507
|
|
508 /**
|
|
509 * Wait for at least one service to be tracked by this
|
|
510 * <code>ServiceTracker</code> object.
|
|
511 * <p>
|
|
512 * It is strongly recommended that <code>waitForService</code> is not used
|
|
513 * during the calling of the <code>BundleActivator</code> methods.
|
|
514 * <code>BundleActivator</code> methods are expected to complete in a
|
|
515 * short period of time.
|
|
516 *
|
|
517 * @param timeout time interval in milliseconds to wait. If zero, the method
|
|
518 * will wait indefinately.
|
|
519 * @return Returns the result of <code>getService()</code>.
|
|
520 * @throws InterruptedException If another thread has interrupted the
|
|
521 * current thread.
|
|
522 * @throws IllegalArgumentException If the value of timeout is negative.
|
|
523 */
|
|
524 public Object waitForService(long timeout) throws InterruptedException {
|
|
525 if (timeout < 0) {
|
|
526 throw new IllegalArgumentException("timeout value is negative"); //$NON-NLS-1$
|
|
527 }
|
|
528 Object object = getService();
|
|
529 while (object == null) {
|
|
530 Tracked tracked = this.tracked; /*
|
|
531 * use local var since we are not
|
|
532 * synchronized
|
|
533 */
|
|
534 if (tracked == null) { /* if ServiceTracker is not open */
|
|
535 return null;
|
|
536 }
|
|
537 synchronized (tracked) {
|
|
538 if (tracked.size() == 0) {
|
|
539 tracked.wait(timeout);
|
|
540 }
|
|
541 }
|
|
542 object = getService();
|
|
543 if (timeout > 0) {
|
|
544 return object;
|
|
545 }
|
|
546 }
|
|
547 return object;
|
|
548 }
|
|
549
|
|
550 /**
|
|
551 * Return an array of <code>ServiceReference</code> objects for all
|
|
552 * services being tracked by this <code>ServiceTracker</code> object.
|
|
553 *
|
|
554 * @return Array of <code>ServiceReference</code> objects or
|
|
555 * <code>null</code> if no service are being tracked.
|
|
556 */
|
|
557 public ServiceReference[] getServiceReferences() {
|
|
558 Tracked tracked = this.tracked; /*
|
|
559 * use local var since we are not
|
|
560 * synchronized
|
|
561 */
|
|
562 if (tracked == null) { /* if ServiceTracker is not open */
|
|
563 return null;
|
|
564 }
|
|
565 synchronized (tracked) {
|
|
566 int length = tracked.size();
|
|
567 if (length == 0) {
|
|
568 return null;
|
|
569 }
|
|
570 ServiceReference[] references = new ServiceReference[length];
|
|
571 Enumeration keys = tracked.keys();
|
|
572 for (int i = 0; i < length; i++) {
|
|
573 references[i] = (ServiceReference) keys.nextElement();
|
|
574 }
|
|
575 return references;
|
|
576 }
|
|
577 }
|
|
578
|
|
579 /**
|
|
580 * Returns a <code>ServiceReference</code> object for one of the services
|
|
581 * being tracked by this <code>ServiceTracker</code> object.
|
|
582 *
|
|
583 * <p>
|
|
584 * If multiple services are being tracked, the service with the highest
|
|
585 * ranking (as specified in its <code>service.ranking</code> property) is
|
|
586 * returned.
|
|
587 *
|
|
588 * <p>
|
|
589 * If there is a tie in ranking, the service with the lowest service ID (as
|
|
590 * specified in its <code>service.id</code> property); that is, the
|
|
591 * service that was registered first is returned.
|
|
592 * <p>
|
|
593 * This is the same algorithm used by
|
|
594 * <code>BundleContext.getServiceReference</code>.
|
|
595 *
|
|
596 * @return <code>ServiceReference</code> object or <code>null</code> if
|
|
597 * no service is being tracked.
|
|
598 * @since 1.1
|
|
599 */
|
|
600 public ServiceReference getServiceReference() {
|
|
601 ServiceReference reference = cachedReference;
|
|
602 if (reference != null) {
|
|
603 if (DEBUG) {
|
|
604 System.out
|
|
605 .println("ServiceTracker.getServiceReference[cached]: " + filter); //$NON-NLS-1$
|
|
606 }
|
|
607 return reference;
|
|
608 }
|
|
609 if (DEBUG) {
|
|
610 System.out.println("ServiceTracker.getServiceReference: " + filter); //$NON-NLS-1$
|
|
611 }
|
|
612 ServiceReference[] references = getServiceReferences();
|
|
613 int length = (references == null) ? 0 : references.length;
|
|
614 if (length == 0) /* if no service is being tracked */
|
|
615 {
|
|
616 return null;
|
|
617 }
|
|
618 int index = 0;
|
|
619 if (length > 1) /* if more than one service, select highest ranking */
|
|
620 {
|
|
621 int rankings[] = new int[length];
|
|
622 int count = 0;
|
|
623 int maxRanking = Integer.MIN_VALUE;
|
|
624 for (int i = 0; i < length; i++) {
|
|
625 Object property = references[i]
|
|
626 .getProperty(Constants.SERVICE_RANKING);
|
|
627 int ranking = (property instanceof Integer) ? ((Integer) property)
|
|
628 .intValue()
|
|
629 : 0;
|
|
630 rankings[i] = ranking;
|
|
631 if (ranking > maxRanking) {
|
|
632 index = i;
|
|
633 maxRanking = ranking;
|
|
634 count = 1;
|
|
635 }
|
|
636 else {
|
|
637 if (ranking == maxRanking) {
|
|
638 count++;
|
|
639 }
|
|
640 }
|
|
641 }
|
|
642 if (count > 1) /* if still more than one service, select lowest id */
|
|
643 {
|
|
644 long minId = Long.MAX_VALUE;
|
|
645 for (int i = 0; i < length; i++) {
|
|
646 if (rankings[i] == maxRanking) {
|
|
647 long id = ((Long) (references[i]
|
|
648 .getProperty(Constants.SERVICE_ID)))
|
|
649 .longValue();
|
|
650 if (id < minId) {
|
|
651 index = i;
|
|
652 minId = id;
|
|
653 }
|
|
654 }
|
|
655 }
|
|
656 }
|
|
657 }
|
|
658 return cachedReference = references[index];
|
|
659 }
|
|
660
|
|
661 /**
|
|
662 * Returns the service object for the specified
|
|
663 * <code>ServiceReference</code> object if the referenced service is being
|
|
664 * tracked by this <code>ServiceTracker</code> object.
|
|
665 *
|
|
666 * @param reference Reference to the desired service.
|
|
667 * @return Service object or <code>null</code> if the service referenced
|
|
668 * by the specified <code>ServiceReference</code> object is not
|
|
669 * being tracked.
|
|
670 */
|
|
671 public Object getService(ServiceReference reference) {
|
|
672 Tracked tracked = this.tracked; /*
|
|
673 * use local var since we are not
|
|
674 * synchronized
|
|
675 */
|
|
676 if (tracked == null) { /* if ServiceTracker is not open */
|
|
677 return null;
|
|
678 }
|
|
679 synchronized (tracked) {
|
|
680 return tracked.get(reference);
|
|
681 }
|
|
682 }
|
|
683
|
|
684 /**
|
|
685 * Return an array of service objects for all services being tracked by this
|
|
686 * <code>ServiceTracker</code> object.
|
|
687 *
|
|
688 * @return Array of service objects or <code>null</code> if no service are
|
|
689 * being tracked.
|
|
690 */
|
|
691 public Object[] getServices() {
|
|
692 Tracked tracked = this.tracked; /*
|
|
693 * use local var since we are not
|
|
694 * synchronized
|
|
695 */
|
|
696 if (tracked == null) { /* if ServiceTracker is not open */
|
|
697 return null;
|
|
698 }
|
|
699 synchronized (tracked) {
|
|
700 ServiceReference[] references = getServiceReferences();
|
|
701 int length = (references == null) ? 0 : references.length;
|
|
702 if (length == 0) {
|
|
703 return null;
|
|
704 }
|
|
705 Object[] objects = new Object[length];
|
|
706 for (int i = 0; i < length; i++) {
|
|
707 objects[i] = getService(references[i]);
|
|
708 }
|
|
709 return objects;
|
|
710 }
|
|
711 }
|
|
712
|
|
713 /**
|
|
714 * Returns a service object for one of the services being tracked by this
|
|
715 * <code>ServiceTracker</code> object.
|
|
716 *
|
|
717 * <p>
|
|
718 * If any services are being tracked, this method returns the result of
|
|
719 * calling <code>getService(getServiceReference())</code>.
|
|
720 *
|
|
721 * @return Service object or <code>null</code> if no service is being
|
|
722 * tracked.
|
|
723 */
|
|
724 public Object getService() {
|
|
725 Object service = cachedService;
|
|
726 if (service != null) {
|
|
727 if (DEBUG) {
|
|
728 System.out
|
|
729 .println("ServiceTracker.getService[cached]: " + filter); //$NON-NLS-1$
|
|
730 }
|
|
731 return service;
|
|
732 }
|
|
733 if (DEBUG) {
|
|
734 System.out.println("ServiceTracker.getService: " + filter); //$NON-NLS-1$
|
|
735 }
|
|
736 ServiceReference reference = getServiceReference();
|
|
737 if (reference == null) {
|
|
738 return null;
|
|
739 }
|
|
740 return cachedService = getService(reference);
|
|
741 }
|
|
742
|
|
743 /**
|
|
744 * Remove a service from this <code>ServiceTracker</code> object.
|
|
745 *
|
|
746 * The specified service will be removed from this
|
|
747 * <code>ServiceTracker</code> object. If the specified service was being
|
|
748 * tracked then the <code>ServiceTrackerCustomizer.removedService</code>
|
|
749 * method will be called for that service.
|
|
750 *
|
|
751 * @param reference Reference to the service to be removed.
|
|
752 */
|
|
753 public void remove(ServiceReference reference) {
|
|
754 Tracked tracked = this.tracked; /*
|
|
755 * use local var since we are not
|
|
756 * synchronized
|
|
757 */
|
|
758 if (tracked == null) { /* if ServiceTracker is not open */
|
|
759 return;
|
|
760 }
|
|
761 tracked.untrack(reference);
|
|
762 }
|
|
763
|
|
764 /**
|
|
765 * Return the number of services being tracked by this
|
|
766 * <code>ServiceTracker</code> object.
|
|
767 *
|
|
768 * @return Number of services being tracked.
|
|
769 */
|
|
770 public int size() {
|
|
771 Tracked tracked = this.tracked; /*
|
|
772 * use local var since we are not
|
|
773 * synchronized
|
|
774 */
|
|
775 if (tracked == null) { /* if ServiceTracker is not open */
|
|
776 return 0;
|
|
777 }
|
|
778 return tracked.size();
|
|
779 }
|
|
780
|
|
781 /**
|
|
782 * Returns the tracking count for this <code>ServiceTracker</code> object.
|
|
783 *
|
|
784 * The tracking count is initialized to 0 when this
|
|
785 * <code>ServiceTracker</code> object is opened. Every time a service is
|
|
786 * added, modified or removed from this <code>ServiceTracker</code> object
|
|
787 * the tracking count is incremented.
|
|
788 *
|
|
789 * <p>
|
|
790 * The tracking count can be used to determine if this
|
|
791 * <code>ServiceTracker</code> object has added, modified or removed a
|
|
792 * service by comparing a tracking count value previously collected with the
|
|
793 * current tracking count value. If the value has not changed, then no
|
|
794 * service has been added, modified or removed from this
|
|
795 * <code>ServiceTracker</code> object since the previous tracking count
|
|
796 * was collected.
|
|
797 *
|
|
798 * @since 1.2
|
|
799 * @return The tracking count for this <code>ServiceTracker</code> object
|
|
800 * or -1 if this <code>ServiceTracker</code> object is not open.
|
|
801 */
|
|
802 public int getTrackingCount() {
|
|
803 return trackingCount;
|
|
804 }
|
|
805
|
|
806 /**
|
|
807 * Called by the Tracked object whenever the set of tracked services is
|
|
808 * modified. Increments the tracking count and clears the cache.
|
|
809 *
|
|
810 * @GuardedBy tracked
|
|
811 */
|
|
812 /*
|
|
813 * This method must not be synchronized since it is called by Tracked while
|
|
814 * Tracked is synchronized. We don't want synchronization interactions
|
|
815 * between the ServiceListener thread and the user thread.
|
|
816 */
|
|
817 void modified() {
|
|
818 trackingCount++; /* increment modification count */
|
|
819 cachedReference = null; /* clear cached value */
|
|
820 cachedService = null; /* clear cached value */
|
|
821 if (DEBUG) {
|
|
822 System.out.println("ServiceTracker.modified: " + filter); //$NON-NLS-1$
|
|
823 }
|
|
824 }
|
|
825
|
|
826
|
|
827 /**
|
|
828 * Inner class to track services. If a <code>ServiceTracker</code> object
|
|
829 * is reused (closed then reopened), then a new Tracked object is used. This
|
|
830 * class is a hashtable mapping <code>ServiceReference</code> object ->
|
|
831 * customized Object. This class is the <code>ServiceListener</code>
|
|
832 * object for the tracker. This class is used to synchronize access to the
|
|
833 * tracked services. This is not a public class. It is only for use by the
|
|
834 * implementation of the <code>ServiceTracker</code> class.
|
|
835 *
|
|
836 * @ThreadSafe
|
|
837 */
|
|
838 class Tracked extends Hashtable implements ServiceListener {
|
|
839 static final long serialVersionUID = -7420065199791006079L;
|
|
840 /**
|
|
841 * List of ServiceReferences in the process of being added. This is used
|
|
842 * to deal with nesting of ServiceEvents. Since ServiceEvents are
|
|
843 * synchronously delivered, ServiceEvents can be nested. For example,
|
|
844 * when processing the adding of a service and the customizer causes the
|
|
845 * service to be unregistered, notification to the nested call to
|
|
846 * untrack that the service was unregistered can be made to the track
|
|
847 * method.
|
|
848 *
|
|
849 * Since the ArrayList implementation is not synchronized, all access to
|
|
850 * this list must be protected by the same synchronized object for
|
|
851 * thread-safety.
|
|
852 *
|
|
853 * @GuardedBy this
|
|
854 */
|
|
855 private final ArrayList adding;
|
|
856
|
|
857 /**
|
|
858 * true if the tracked object is closed.
|
|
859 *
|
|
860 * This field is volatile because it is set by one thread and read by
|
|
861 * another.
|
|
862 */
|
|
863 private volatile bool closed;
|
|
864
|
|
865 /**
|
|
866 * Initial list of ServiceReferences for the tracker. This is used to
|
|
867 * correctly process the initial services which could become
|
|
868 * unregistered before they are tracked. This is necessary since the
|
|
869 * initial set of tracked services are not "announced" by ServiceEvents
|
|
870 * and therefore the ServiceEvent for unregistration could be delivered
|
|
871 * before we track the service.
|
|
872 *
|
|
873 * A service must not be in both the initial and adding lists at the
|
|
874 * same time. A service must be moved from the initial list to the
|
|
875 * adding list "atomically" before we begin tracking it.
|
|
876 *
|
|
877 * Since the LinkedList implementation is not synchronized, all access
|
|
878 * to this list must be protected by the same synchronized object for
|
|
879 * thread-safety.
|
|
880 *
|
|
881 * @GuardedBy this
|
|
882 */
|
|
883 private final LinkedList initial;
|
|
884
|
|
885 /**
|
|
886 * Tracked constructor.
|
|
887 */
|
|
888 protected Tracked() {
|
|
889 super();
|
|
890 closed = false;
|
|
891 adding = new ArrayList(6);
|
|
892 initial = new LinkedList();
|
|
893 }
|
|
894
|
|
895 /**
|
|
896 * Set initial list of services into tracker before ServiceEvents begin
|
|
897 * to be received.
|
|
898 *
|
|
899 * This method must be called from ServiceTracker.open while
|
|
900 * synchronized on this object in the same synchronized block as the
|
|
901 * addServiceListener call.
|
|
902 *
|
|
903 * @param references The initial list of services to be tracked.
|
|
904 * @GuardedBy this
|
|
905 */
|
|
906 protected void setInitialServices(ServiceReference[] references) {
|
|
907 if (references == null) {
|
|
908 return;
|
|
909 }
|
|
910 int size = references.length;
|
|
911 for (int i = 0; i < size; i++) {
|
|
912 if (DEBUG) {
|
|
913 System.out
|
|
914 .println("ServiceTracker.Tracked.setInitialServices: " + references[i]); //$NON-NLS-1$
|
|
915 }
|
|
916 initial.add(references[i]);
|
|
917 }
|
|
918 }
|
|
919
|
|
920 /**
|
|
921 * Track the initial list of services. This is called after
|
|
922 * ServiceEvents can begin to be received.
|
|
923 *
|
|
924 * This method must be called from ServiceTracker.open while not
|
|
925 * synchronized on this object after the addServiceListener call.
|
|
926 *
|
|
927 */
|
|
928 protected void trackInitialServices() {
|
|
929 while (true) {
|
|
930 ServiceReference reference;
|
|
931 synchronized (this) {
|
|
932 if (initial.size() == 0) {
|
|
933 /*
|
|
934 * if there are no more inital services
|
|
935 */
|
|
936 return; /* we are done */
|
|
937 }
|
|
938 /*
|
|
939 * move the first service from the initial list to the
|
|
940 * adding list within this synchronized block.
|
|
941 */
|
|
942 reference = (ServiceReference) initial.removeFirst();
|
|
943 if (this.get(reference) != null) {
|
|
944 /* if we are already tracking this service */
|
|
945 if (DEBUG) {
|
|
946 System.out
|
|
947 .println("ServiceTracker.Tracked.trackInitialServices[already tracked]: " + reference); //$NON-NLS-1$
|
|
948 }
|
|
949 continue; /* skip this service */
|
|
950 }
|
|
951 if (adding.contains(reference)) {
|
|
952 /*
|
|
953 * if this service is already in the process of being
|
|
954 * added.
|
|
955 */
|
|
956 if (DEBUG) {
|
|
957 System.out
|
|
958 .println("ServiceTracker.Tracked.trackInitialServices[already adding]: " + reference); //$NON-NLS-1$
|
|
959 }
|
|
960 continue; /* skip this service */
|
|
961 }
|
|
962 adding.add(reference);
|
|
963 }
|
|
964 if (DEBUG) {
|
|
965 System.out
|
|
966 .println("ServiceTracker.Tracked.trackInitialServices: " + reference); //$NON-NLS-1$
|
|
967 }
|
|
968 trackAdding(reference); /*
|
|
969 * Begin tracking it. We call
|
|
970 * trackAdding since we have already put
|
|
971 * the reference in the adding list.
|
|
972 */
|
|
973 }
|
|
974 }
|
|
975
|
|
976 /**
|
|
977 * Called by the owning <code>ServiceTracker</code> object when it is
|
|
978 * closed.
|
|
979 */
|
|
980 protected void close() {
|
|
981 closed = true;
|
|
982 }
|
|
983
|
|
984 /**
|
|
985 * <code>ServiceListener</code> method for the
|
|
986 * <code>ServiceTracker</code> class. This method must NOT be
|
|
987 * synchronized to avoid deadlock potential.
|
|
988 *
|
|
989 * @param event <code>ServiceEvent</code> object from the framework.
|
|
990 */
|
|
991 public void serviceChanged(ServiceEvent event) {
|
|
992 /*
|
|
993 * Check if we had a delayed call (which could happen when we
|
|
994 * close).
|
|
995 */
|
|
996 if (closed) {
|
|
997 return;
|
|
998 }
|
|
999 ServiceReference reference = event.getServiceReference();
|
|
1000 if (DEBUG) {
|
|
1001 System.out
|
|
1002 .println("ServiceTracker.Tracked.serviceChanged[" + event.getType() + "]: " + reference); //$NON-NLS-1$ //$NON-NLS-2$
|
|
1003 }
|
|
1004
|
|
1005 switch (event.getType()) {
|
|
1006 case ServiceEvent.REGISTERED :
|
|
1007 case ServiceEvent.MODIFIED :
|
|
1008 if (noUserFilter) { // no user supplied filter to be checked
|
|
1009 track(reference);
|
|
1010 /*
|
|
1011 * If the customizer throws an unchecked exception, it
|
|
1012 * is safe to let it propagate
|
|
1013 */
|
|
1014 }
|
|
1015 else { // filter supplied by user must be checked
|
|
1016 if (filter.match(reference)) {
|
|
1017 track(reference);
|
|
1018 /*
|
|
1019 * If the customizer throws an unchecked exception,
|
|
1020 * it is safe to let it propagate
|
|
1021 */
|
|
1022 }
|
|
1023 else {
|
|
1024 untrack(reference);
|
|
1025 /*
|
|
1026 * If the customizer throws an unchecked exception,
|
|
1027 * it is safe to let it propagate
|
|
1028 */
|
|
1029 }
|
|
1030 }
|
|
1031 break;
|
|
1032 case ServiceEvent.UNREGISTERING :
|
|
1033 untrack(reference);
|
|
1034 /*
|
|
1035 * If the customizer throws an unchecked exception, it is
|
|
1036 * safe to let it propagate
|
|
1037 */
|
|
1038 break;
|
|
1039 }
|
|
1040 }
|
|
1041
|
|
1042 /**
|
|
1043 * Begin to track the referenced service.
|
|
1044 *
|
|
1045 * @param reference Reference to a service to be tracked.
|
|
1046 */
|
|
1047 private void track(ServiceReference reference) {
|
|
1048 Object object;
|
|
1049 synchronized (this) {
|
|
1050 object = this.get(reference);
|
|
1051 }
|
|
1052 if (object != null) /* we are already tracking the service */
|
|
1053 {
|
|
1054 if (DEBUG) {
|
|
1055 System.out
|
|
1056 .println("ServiceTracker.Tracked.track[modified]: " + reference); //$NON-NLS-1$
|
|
1057 }
|
|
1058 synchronized (this) {
|
|
1059 modified(); /* increment modification count */
|
|
1060 }
|
|
1061 /* Call customizer outside of synchronized region */
|
|
1062 customizer.modifiedService(reference, object);
|
|
1063 /*
|
|
1064 * If the customizer throws an unchecked exception, it is safe
|
|
1065 * to let it propagate
|
|
1066 */
|
|
1067 return;
|
|
1068 }
|
|
1069 synchronized (this) {
|
|
1070 if (adding.contains(reference)) { /*
|
|
1071 * if this service is
|
|
1072 * already in the process of
|
|
1073 * being added.
|
|
1074 */
|
|
1075 if (DEBUG) {
|
|
1076 System.out
|
|
1077 .println("ServiceTracker.Tracked.track[already adding]: " + reference); //$NON-NLS-1$
|
|
1078 }
|
|
1079 return;
|
|
1080 }
|
|
1081 adding.add(reference); /* mark this service is being added */
|
|
1082 }
|
|
1083
|
|
1084 trackAdding(reference); /*
|
|
1085 * call trackAdding now that we have put the
|
|
1086 * reference in the adding list
|
|
1087 */
|
|
1088 }
|
|
1089
|
|
1090 /**
|
|
1091 * Common logic to add a service to the tracker used by track and
|
|
1092 * trackInitialServices. The specified reference must have been placed
|
|
1093 * in the adding list before calling this method.
|
|
1094 *
|
|
1095 * @param reference Reference to a service to be tracked.
|
|
1096 */
|
|
1097 private void trackAdding(ServiceReference reference) {
|
|
1098 if (DEBUG) {
|
|
1099 System.out
|
|
1100 .println("ServiceTracker.Tracked.trackAdding: " + reference); //$NON-NLS-1$
|
|
1101 }
|
|
1102 Object object = null;
|
|
1103 bool becameUntracked = false;
|
|
1104 /* Call customizer outside of synchronized region */
|
|
1105 try {
|
|
1106 object = customizer.addingService(reference);
|
|
1107 /*
|
|
1108 * If the customizer throws an unchecked exception, it will
|
|
1109 * propagate after the finally
|
|
1110 */
|
|
1111 }
|
|
1112 finally {
|
|
1113 synchronized (this) {
|
|
1114 if (adding.remove(reference)) { /*
|
|
1115 * if the service was not
|
|
1116 * untracked during the
|
|
1117 * customizer callback
|
|
1118 */
|
|
1119 if (object != null) {
|
|
1120 this.put(reference, object);
|
|
1121 modified(); /* increment modification count */
|
|
1122 notifyAll(); /*
|
|
1123 * notify any waiters in
|
|
1124 * waitForService
|
|
1125 */
|
|
1126 }
|
|
1127 }
|
|
1128 else {
|
|
1129 becameUntracked = true;
|
|
1130 }
|
|
1131 }
|
|
1132 }
|
|
1133 /*
|
|
1134 * The service became untracked during the customizer callback.
|
|
1135 */
|
|
1136 if (becameUntracked) {
|
|
1137 if (DEBUG) {
|
|
1138 System.out
|
|
1139 .println("ServiceTracker.Tracked.trackAdding[removed]: " + reference); //$NON-NLS-1$
|
|
1140 }
|
|
1141 /* Call customizer outside of synchronized region */
|
|
1142 customizer.removedService(reference, object);
|
|
1143 /*
|
|
1144 * If the customizer throws an unchecked exception, it is safe
|
|
1145 * to let it propagate
|
|
1146 */
|
|
1147 }
|
|
1148 }
|
|
1149
|
|
1150 /**
|
|
1151 * Discontinue tracking the referenced service.
|
|
1152 *
|
|
1153 * @param reference Reference to the tracked service.
|
|
1154 */
|
|
1155 protected void untrack(ServiceReference reference) {
|
|
1156 Object object;
|
|
1157 synchronized (this) {
|
|
1158 if (initial.remove(reference)) { /*
|
|
1159 * if this service is
|
|
1160 * already in the list of
|
|
1161 * initial references to
|
|
1162 * process
|
|
1163 */
|
|
1164 if (DEBUG) {
|
|
1165 System.out
|
|
1166 .println("ServiceTracker.Tracked.untrack[removed from initial]: " + reference); //$NON-NLS-1$
|
|
1167 }
|
|
1168 return; /*
|
|
1169 * we have removed it from the list and it will not
|
|
1170 * be processed
|
|
1171 */
|
|
1172 }
|
|
1173
|
|
1174 if (adding.remove(reference)) { /*
|
|
1175 * if the service is in the
|
|
1176 * process of being added
|
|
1177 */
|
|
1178 if (DEBUG) {
|
|
1179 System.out
|
|
1180 .println("ServiceTracker.Tracked.untrack[being added]: " + reference); //$NON-NLS-1$
|
|
1181 }
|
|
1182 return; /*
|
|
1183 * in case the service is untracked while in the
|
|
1184 * process of adding
|
|
1185 */
|
|
1186 }
|
|
1187 object = this.remove(reference); /*
|
|
1188 * must remove from tracker
|
|
1189 * before calling customizer
|
|
1190 * callback
|
|
1191 */
|
|
1192 if (object == null) { /* are we actually tracking the service */
|
|
1193 return;
|
|
1194 }
|
|
1195 modified(); /* increment modification count */
|
|
1196 }
|
|
1197 if (DEBUG) {
|
|
1198 System.out
|
|
1199 .println("ServiceTracker.Tracked.untrack[removed]: " + reference); //$NON-NLS-1$
|
|
1200 }
|
|
1201 /* Call customizer outside of synchronized region */
|
|
1202 customizer.removedService(reference, object);
|
|
1203 /*
|
|
1204 * If the customizer throws an unchecked exception, it is safe to
|
|
1205 * let it propagate
|
|
1206 */
|
|
1207 }
|
|
1208 }
|
|
1209
|
|
1210 /**
|
|
1211 * Subclass of Tracked which implements the AllServiceListener interface.
|
|
1212 * This class is used by the ServiceTracker if open is called with true.
|
|
1213 *
|
|
1214 * @since 1.3
|
|
1215 * @ThreadSafe
|
|
1216 */
|
|
1217 class AllTracked extends Tracked implements AllServiceListener {
|
|
1218 static final long serialVersionUID = 4050764875305137716L;
|
|
1219
|
|
1220 /**
|
|
1221 * AllTracked constructor.
|
|
1222 */
|
|
1223 protected AllTracked() {
|
|
1224 super();
|
|
1225 }
|
|
1226 }
|
|
1227 }
|
|
1228 +++/
|
|
1229
|
|
1230
|