1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.osgi.service.importer.support.internal.collection;
17
18 import java.util.Comparator;
19 import java.util.SortedSet;
20
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.Filter;
23 import org.springframework.osgi.service.importer.support.internal.aop.ServiceProxyCreator;
24
25
26 /**
27 * OSGi service dynamic collection - allows iterating while the underlying
28 * storage is being shrunk/expanded. This collection is read-only - its content
29 * is being retrieved dynamically from the OSGi platform.
30 *
31 * <p/> This collection and its iterators are thread-safe. That is, multiple
32 * threads can access the collection. However, since the collection is
33 * read-only, it cannot be modified by the client.
34 *
35 * @author Costin Leau
36 *
37 */
38 public class OsgiServiceSortedSet extends OsgiServiceSet implements SortedSet {
39
40 /**
41 * cast the collection to a specialized collection
42 */
43 private SortedSet storage;
44
45 private final Comparator comparator;
46
47 public OsgiServiceSortedSet(Filter filter, BundleContext context, ClassLoader classLoader,
48 ServiceProxyCreator proxyCreator) {
49 this(filter, context, classLoader, null, proxyCreator);
50 }
51
52 public OsgiServiceSortedSet(Filter filter, BundleContext context, ClassLoader classLoader, Comparator comparator,
53 ServiceProxyCreator proxyCreator) {
54 super(filter, context, classLoader, proxyCreator);
55 this.comparator = comparator;
56 }
57
58 protected DynamicCollection createInternalDynamicStorage() {
59 storage = new DynamicSortedSet(comparator);
60 return (DynamicCollection) storage;
61 }
62
63 public Comparator comparator() {
64 return storage.comparator();
65 }
66
67 public Object first() {
68 mandatoryServiceCheck();
69 return storage.first();
70 }
71
72 public Object last() {
73 mandatoryServiceCheck();
74 return storage.last();
75 }
76
77 public SortedSet tailSet(Object fromElement) {
78 mandatoryServiceCheck();
79 return storage.tailSet(fromElement);
80 }
81
82 public SortedSet headSet(Object toElement) {
83 mandatoryServiceCheck();
84 return storage.headSet(toElement);
85 }
86
87 public SortedSet subSet(Object fromElement, Object toElement) {
88 mandatoryServiceCheck();
89 return storage.subSet(fromElement, toElement);
90 }
91
92 }