geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r773782 - in /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint: context/CollectionBasedServiceReferenceRecipe.java utils/DynamicSet.java
Date Tue, 12 May 2009 05:00:19 GMT
Author: gawor
Date: Tue May 12 05:00:19 2009
New Revision: 773782

URL: http://svn.apache.org/viewvc?rev=773782&view=rev
Log:
fix Set semantics for ManagedSet

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicSet.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java?rev=773782&r1=773781&r2=773782&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
Tue May 12 05:00:19 2009
@@ -153,7 +153,7 @@
 
     protected void track(ServiceReference reference) {
         try {
-            ServiceDispatcher dispatcher = new ServiceDispatcher(reference);
+            ServiceDispatcher dispatcher = new ServiceDispatcher(reference, collection.isMemberReferences());
             dispatcher.proxy = createProxy(dispatcher, Arrays.asList((String[]) reference.getProperty(Constants.OBJECTCLASS)));
             synchronized (collection) {
                 collection.addDispatcher(dispatcher);
@@ -193,12 +193,19 @@
         public ServiceReference reference;
         public Object service;
         public Object proxy;
+        
+        private final boolean memberReference;
 
-        public ServiceDispatcher(ServiceReference reference) throws Exception {
+        public ServiceDispatcher(ServiceReference reference, boolean memberReference) throws
Exception {
             this.reference = reference;
+            this.memberReference = memberReference;
             this.service = reference.getBundle().getBundleContext().getService(reference);
         }
 
+        public Object getMember() {
+            return (memberReference) ? reference : service;
+        }
+        
         public void destroy() {
             if (reference != null) {
                 reference.getBundle().getBundleContext().ungetService(reference);
@@ -213,6 +220,7 @@
             }
             return service;
         }
+        
     }
 
     public static class DispatcherComparator implements Comparator<ServiceDispatcher>
{
@@ -245,6 +253,10 @@
             this.dispatchers = dispatchers;
         }
 
+        public boolean isMemberReferences() {
+            return references;
+        }
+        
         public boolean addDispatcher(ServiceDispatcher dispatcher) {
             return dispatchers.add(dispatcher);
         }
@@ -274,10 +286,6 @@
             return dispatchers.size();
         }
 
-        protected Object getMember(ServiceDispatcher d) {
-            return references ? d.reference : d.proxy;
-        }
-
         @Override
         public boolean add(Object o) {
             throw new UnsupportedOperationException("This collection is read only");
@@ -321,7 +329,7 @@
             }
 
             public Object next() {
-                return getMember(iterator.next());
+                return iterator.next().getMember();
             }
 
             public void remove() {
@@ -351,7 +359,7 @@
         }
 
         public Object get(int index) {
-            return getMember(dispatchers.get(index));
+            return dispatchers.get(index).getMember();
         }
 
         public int indexOf(Object o) {
@@ -421,7 +429,7 @@
             }
 
             public Object next() {
-                return getMember(iterator.next());
+                return iterator.next().getMember();
             }
 
             public boolean hasPrevious() {
@@ -429,7 +437,7 @@
             }
 
             public Object previous() {
-                return getMember(iterator.previous());
+                return iterator.previous().getMember();
             }
 
             public int nextIndex() {
@@ -466,15 +474,29 @@
     public static class ManagedSet extends ManagedCollection implements Set {
 
         public ManagedSet(boolean references) {
-            this(references, new DynamicSet<ServiceDispatcher>());
+            super(references, new DynamicServiceDispatcherSet());
         }
-
+        
         protected ManagedSet(boolean references, DynamicSet<ServiceDispatcher> dispatchers)
{
             super(references, dispatchers);
         }
-
+        
     }
-
+    
+    private static class DynamicServiceDispatcherSet extends DynamicSet<ServiceDispatcher>
{
+        public boolean add(ServiceDispatcher newDispatcher) {
+            synchronized (lock) {
+                for (ServiceDispatcher dispatcher : storage) {
+                    if (dispatcher.getMember().equals(newDispatcher.getMember())) {
+                        return false;
+                    }
+                }
+                storage.add(newDispatcher);
+                return true;
+            }
+        }
+    }
+    
     public static class ManagedSortedSet extends ManagedSet implements SortedSet {
 
         protected final DynamicSortedSet<ServiceDispatcher> dispatchers;
@@ -503,11 +525,11 @@
         }
 
         public Object first() {
-            return getMember(dispatchers.first());
+            return dispatchers.first().getMember();
         }
 
         public Object last() {
-            return getMember(dispatchers.last());
+            return dispatchers.last().getMember();
         }
 
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicSet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicSet.java?rev=773782&r1=773781&r2=773782&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicSet.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicSet.java
Tue May 12 05:00:19 2009
@@ -19,8 +19,6 @@
 package org.apache.geronimo.blueprint.utils;
 
 import java.util.Set;
-import java.util.Iterator;
-import java.lang.ref.WeakReference;
 
 /**
  * Same as DynamicCollection but implementing the Set interface, thus not allowing



Mime
View raw message