geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r781638 - in /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint: container/ utils/
Date Thu, 04 Jun 2009 02:03:24 GMT
Author: gnodet
Date: Thu Jun  4 02:03:24 2009
New Revision: 781638

URL: http://svn.apache.org/viewvc?rev=781638&view=rev
Log:
Refactor ref-list / ref-set recipe, fix cyclic dependency problem with listeners that are
not called soon enough, fix collections conversions, fix synchronization issue with managed
lists / iterator, fix comparator parsing, fix the grace period, fix the missing dependencies
that can be duplicated in events, make sure the blueprint container destruction waits for
the container to not be running anymore

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicCollection.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
Thu Jun  4 02:03:24 2009
@@ -150,7 +150,7 @@
         return filter;
     }
 
-    private void createListeners() {
+    protected void createListeners() {
         try {
             if (listenersRecipe != null) {
                 listeners = (List<Listener>) listenersRecipe.create();
@@ -268,10 +268,6 @@
 
     @Override
     public void postCreate() {
-        // Create the listeners and initialize them
-        createListeners();
-        // Retrack to inform listeners
-        retrack();
     }
 
     protected abstract void track(ServiceReference reference);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java
Thu Jun  4 02:03:24 2009
@@ -496,9 +496,9 @@
         getDestroyMethod(obj);
         
         // Add partially created object to the container
-        if (initMethod == null) {
+//        if (initMethod == null) {
             addObject(obj, true);
-        }
+//        }
 
         // inject properties
         setProperties(obj);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
Thu Jun  4 02:03:24 2009
@@ -126,6 +126,7 @@
     private boolean xmlValidation = true;
     private ScheduledFuture timeoutFuture;
     private final AtomicBoolean scheduled = new AtomicBoolean();
+    private final AtomicBoolean running = new AtomicBoolean();
 
     public BlueprintContainerImpl(BundleContext bundleContext, Bundle extenderBundle, BlueprintListener
eventDispatcher, NamespaceHandlerRegistry handlers, ScheduledExecutorService executors, List<URL>
urls) {
         this.bundleContext = bundleContext;
@@ -195,7 +196,15 @@
     public void run() {
         scheduled.set(false);
         synchronized (scheduled) {
-            doRun();
+            synchronized (running) {
+                running.set(true);
+                try {
+                    doRun();
+                } finally {
+                    running.set(false);
+                    running.notifyAll();
+                }
+            }
         }
     }
 
@@ -258,7 +267,7 @@
                         state = State.WaitForInitialReferences;
                         break;
                     case WaitForInitialReferences:
-                        if (checkAllSatisfiables()) {
+                        if (!waitForDependencies || checkAllSatisfiables()) {
                             state = State.InitialReferencesSatisfied;
                             break;
                         } else {
@@ -268,15 +277,10 @@
                     case InitialReferencesSatisfied:
                         processTypeConverters();
                         processProcessors();
-                        // Check references
-                        if (!waitForDependencies) {
-                            state = State.Create;
-                        } else {
-                            state = State.WaitForInitialReferences2;
-                        }
+                        state = State.WaitForInitialReferences2;
                         break;
                     case WaitForInitialReferences2:
-                        if (checkAllSatisfiables()) {
+                        if (!waitForDependencies || checkAllSatisfiables()) {
                             state = State.Create;
                             break;
                         } else {
@@ -523,13 +527,17 @@
     private String[] getMissingDependencies() {
         List<String> missing = new ArrayList<String>();
         Map<String, List<SatisfiableRecipe>> dependencies = getSatisfiableDependenciesMap();
+        Set<SatisfiableRecipe> recipes = new HashSet<SatisfiableRecipe>();
         for (String name : dependencies.keySet()) {
             for (SatisfiableRecipe recipe : dependencies.get(name)) {
                 if (!recipe.isSatisfied()) {
-                    missing.add(recipe.getOsgiFilter());
+                    recipes.add(recipe);
                 }
             }
         }
+        for (SatisfiableRecipe recipe : recipes) {
+            missing.add(recipe.getOsgiFilter());
+        }
         return missing.toArray(new String[missing.size()]);
     }
     
@@ -651,6 +659,17 @@
         handlers.removeListener(this);
         unregisterServices();
         untrackServiceReferences();
+
+        synchronized (running) {
+            while (running.get()) {
+                try {
+                    running.wait();
+                } catch (InterruptedException e) {
+                    // Ignore
+                }
+            }
+        }
+
         destroyComponents();
         
         eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.DESTROYED, getBundleContext().getBundle(),
getExtenderBundle()));

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
Thu Jun  4 02:03:24 2009
@@ -416,8 +416,6 @@
         } else if (nodeNameEquals(element, BEAN_ELEMENT)) {
             ComponentMetadata component = parseBeanMetadata(element, true);
             registry.registerComponentDefinition(component);
-        } else if (nodeNameEquals(element, REF_ELEMENT)) {
-            // TODO: what about those top-level refs elements
         } else if (nodeNameEquals(element, SERVICE_ELEMENT)) {
             ComponentMetadata service = parseService(element, true);
             registry.registerComponentDefinition(service);
@@ -936,6 +934,13 @@
 
     private void parseComparator(Element element, RefCollectionMetadataImpl references) {
         Metadata comparator = references.getComparator();
+        // Parse attribute
+        if (element.hasAttribute(REF_ATTRIBUTE)) {
+            if (comparator != null) {
+                throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + "
attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT
+ " or custom element can be set");
+            }
+            comparator = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
+        }
         // Parse elements
         NodeList nl = element.getChildNodes();
         for (int i = 0; i < nl.getLength(); i++) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java
Thu Jun  4 02:03:24 2009
@@ -58,7 +58,8 @@
 
     private final RefCollectionMetadata metadata;
     private final Recipe comparatorRecipe;
-    private ManagedCollection collection;
+    private final List<ManagedCollection> collections = new ArrayList<ManagedCollection>();
+    private DynamicCollection<ServiceDispatcher> storage;
     private final List<ServiceDispatcher> unboundDispatchers = new ArrayList<ServiceDispatcher>();
 
     public RefCollectionRecipe(String name,
@@ -81,34 +82,27 @@
                 comparator = new NaturalOrderComparator();
             }
             boolean orderReferences = metadata.getOrderingBasis() == RefCollectionMetadata.USE_SERVICE_REFERENCE;
-            Boolean memberReferences;
-            if (metadata.getMemberType() == RefCollectionMetadata.USE_SERVICE_REFERENCE)
{
-                memberReferences = true;
-            } else if (metadata.getMemberType() == RefCollectionMetadata.USE_SERVICE_OBJECT)
{
-                memberReferences = false;
-            } else {
-                memberReferences = null;
-            }
             if (metadata.getCollectionType() == List.class) {
                 if (comparator != null) {
-                    collection = new ManagedList(memberReferences, orderReferences, comparator);
+                    storage = new DynamicCollection<ServiceDispatcher>(true, new DispatcherComparator(comparator,
orderReferences));
                 } else {
-                    collection = new ManagedList(memberReferences);
+                    storage = new DynamicCollection<ServiceDispatcher>(true, null);
                 }
             } else if (metadata.getCollectionType() == Set.class) {
                 if (comparator != null) {
-                    collection = new ManagedSet(memberReferences, orderReferences, comparator);
+                    storage = new DynamicCollection<ServiceDispatcher>(false, new DispatcherComparator(comparator,
orderReferences));
                 } else {
-                    collection = new ManagedSet(memberReferences);
+                    storage = new DynamicCollection<ServiceDispatcher>(false, null);
                 }
             } else {
                 throw new IllegalArgumentException("Unsupported collection type " + metadata.getCollectionType().getName());
             }
 
             // Handle initial references
+            createListeners();
             retrack();
 
-            return collection;
+            return new ProvidedObject();
         } catch (ComponentDefinitionException t) {
             throw t;
         } catch (Throwable t) {
@@ -118,8 +112,8 @@
 
     public void stop() {
         super.stop();
-        if (collection != null) {
-            List<ServiceDispatcher> dispatchers = new ArrayList<ServiceDispatcher>(collection.getDispatchers());
+        if (storage != null) {
+            List<ServiceDispatcher> dispatchers = new ArrayList<ServiceDispatcher>(storage);
             for (ServiceDispatcher dispatcher : dispatchers) {
                 untrack(dispatcher.reference);
             }
@@ -136,7 +130,7 @@
     }
 
     protected void track(ServiceReference reference) {
-        if (collection != null) {
+        if (storage != null) {
             try {
                 // ServiceReferences may be tracked at multiple points:
                 //  * first after the collection creation in #internalCreate()
@@ -148,14 +142,14 @@
                 // step, the dispatcher has already been added to the collection
                 // so we just call the listener.
                 //
-                ServiceDispatcher dispatcher = collection.findDispatcher(reference);
+                ServiceDispatcher dispatcher = findDispatcher(reference);
                 if (dispatcher != null) {
                     if (!unboundDispatchers.remove(dispatcher)) {
                         return;
                     }
                 } else {
                     dispatcher = new ServiceDispatcher(reference);
-                    List<String> interfaces = metadata.getInterfaceNames(); 
+                    List<String> interfaces = metadata.getInterfaceNames();
                     if (metadata instanceof ExtendedRefCollectionMetadata) {
                         boolean greedy = (((ExtendedRefCollectionMetadata) metadata).getProxyMethod()
& ExtendedRefCollectionMetadata.PROXY_METHOD_GREEDY) != 0;
                         if (greedy) {
@@ -163,9 +157,7 @@
                         }
                     }
                     dispatcher.proxy = createProxy(dispatcher, interfaces);
-                    synchronized (collection) {
-                        collection.addDispatcher(dispatcher);
-                    }
+                    storage.add(dispatcher);
                 }
                 if (listeners != null) {
                     for (Listener listener : listeners) {
@@ -183,8 +175,8 @@
     }
 
     protected void untrack(ServiceReference reference) {
-        if (collection != null) {
-            ServiceDispatcher dispatcher = collection.findDispatcher(reference);
+        if (storage != null) {
+            ServiceDispatcher dispatcher = findDispatcher(reference);
             if (dispatcher != null) {
                 if (listeners != null) {
                     for (Listener listener : listeners) {
@@ -193,7 +185,7 @@
                         }
                     }
                 }
-                synchronized (collection) {
+                for (ManagedCollection collection : collections) {
                     collection.removeDispatcher(dispatcher);
                 }
             }
@@ -201,6 +193,31 @@
         }
     }
 
+    protected ServiceDispatcher findDispatcher(ServiceReference reference) {
+        for (ServiceDispatcher dispatcher : storage) {
+            if (dispatcher.reference == reference) {
+                return dispatcher;
+            }
+        }
+        return null;
+    }
+
+    protected ManagedCollection getManagedCollection(boolean useReferences) {
+        for (ManagedCollection col : collections) {
+            if (col.references == useReferences) {
+                return col;
+            }
+        }
+        ManagedCollection collection;
+        if (metadata.getCollectionType() == List.class) {
+            collection = new ManagedList(useReferences, storage);
+        } else {
+            collection = new ManagedSet(useReferences, storage);
+        }
+        collections.add(collection);
+        return collection;
+    }
+
     /**
      * The ServiceDispatcher is used when creating the cglib proxy.
      * Thic class is responsible for getting the actual service that will be used.
@@ -215,14 +232,6 @@
             this.reference = reference;
         }
 
-        public Object getMember() {
-            if (collection.isMemberReferences()) {
-                return reference;
-            } else {
-                return proxy;
-            }
-        }
-        
         public synchronized void destroy() {
             if (reference != null) {
                 reference.getBundle().getBundleContext().ungetService(reference);
@@ -247,13 +256,13 @@
             if (this == o) return true;
             if (o == null || getClass() != o.getClass()) return false;
             ServiceDispatcher that = (ServiceDispatcher) o;
-            if (this.getMember() != null ? !this.getMember().equals(that.getMember()) : that.getMember()
!= null) return false;
+            if (this.proxy != null ? !this.proxy.equals(that.proxy) : that.proxy != null)
return false;
             return true;
         }
 
         @Override
         public int hashCode() {
-            return getMember() != null ? getMember().hashCode() : 0;
+            return proxy != null ? proxy.hashCode() : 0;
         }
     }
 
@@ -293,62 +302,50 @@
 
     }
 
+    public class ProvidedObject implements ConversionUtils.Convertible {
+
+        public Object convert(Type type) {
+            LOGGER.debug("Converting ManagedCollection to {}", type);
+            if (!TypeUtils.toClass(type).isAssignableFrom(metadata.getCollectionType()))
{
+                throw new ComponentDefinitionException("<ref-list/> and <ref-set/>
can only be converted respectively to a List or Set, not " + type);
+            }
+            boolean useRef = false;
+            if (type instanceof ParameterizedType) {
+                Type[] args = ((ParameterizedType) type).getActualTypeArguments();
+                if (args != null && args.length == 1) {
+                    useRef = (args[0] == ServiceReference.class);
+                }
+            }
+            boolean references;   // TODO
+            if (metadata.getMemberType() == RefCollectionMetadata.USE_SERVICE_REFERENCE)
{
+                references = true;
+            } else if (metadata.getMemberType() == RefCollectionMetadata.USE_SERVICE_OBJECT)
{
+                references = false;
+            } else {
+                references = useRef;
+            }
+            LOGGER.debug("ManagedCollection references={}", references);
+            return getManagedCollection(references);
+        }
+
+    }
+
     /**
      * Base class for managed collections.
      * This class implemenents the Convertible interface to detect if the collection need
      * to use ServiceReference or proxies.
      */
-    public static class ManagedCollection extends AbstractCollection implements ConversionUtils.Convertible
{
+    public static class ManagedCollection extends AbstractCollection {
 
         protected final DynamicCollection<ServiceDispatcher> dispatchers;
-        protected Boolean references;
+        protected boolean references;
 
-        public ManagedCollection(Boolean references, DynamicCollection<ServiceDispatcher>
dispatchers) {
+        public ManagedCollection(boolean references, DynamicCollection<ServiceDispatcher>
dispatchers) {
             this.references = references;
             this.dispatchers = dispatchers;
             LOGGER.debug("ManagedCollection references={}", references);
         }
 
-        public Object convert(Type type) {
-            LOGGER.debug("Converting ManagedCollection to {}", type);
-            if (Object.class == type) {
-                return this;
-            }
-            if (!Collection.class.isAssignableFrom(TypeUtils.toClass(type))) {
-                throw new ComponentDefinitionException("<ref-list/> and <ref-set/>
can only be converted to other collections, not " + type);
-            }
-            if (TypeUtils.toClass(type).isInstance(this)) {
-                Boolean useRef = null;
-                if (type instanceof ParameterizedType) {
-                    Type[] args = ((ParameterizedType) type).getActualTypeArguments();
-                    if (args != null && args.length == 1) {
-                        useRef = (args[0] == ServiceReference.class);
-                    }
-                }
-                if (references == null) {
-                    references = useRef != null ? useRef : false;
-                    LOGGER.debug("ManagedCollection references={}", references);
-                    return this;
-                } else if (useRef == null || references.booleanValue() == useRef.booleanValue())
{
-                    return this;
-                }
-                // TODO: the current collection can not be converted, so we need to create
a new collection
-                throw new ComponentDefinitionException("The same <ref-list/> or <ref-set/>
can not be " +
-                        "injected as Collection<ServiceReference> and Collection<NotServiceReference>
at the same time");
-            } else {
-                // TODO: the current collection can not be converted, so we need to create
a new collection
-                throw new ComponentDefinitionException("Unsupported conversion to " + type);
-            }
-        }
-
-        public boolean isMemberReferences() {
-            if (references == null) {
-                references = false;
-            }
-            LOGGER.debug("Retrieving member in ManagedCollection references={}", references);
-            return references;
-        }
-        
         public boolean addDispatcher(ServiceDispatcher dispatcher) {
             return dispatchers.add(dispatcher);
         }
@@ -361,15 +358,6 @@
             return dispatchers;
         }
 
-        public ServiceDispatcher findDispatcher(ServiceReference reference) {
-            for (ServiceDispatcher dispatcher : dispatchers) {
-                if (dispatcher.reference == reference) {
-                    return dispatcher;
-                }
-            }
-            return null;
-        }
-
         public Iterator iterator() {
             return new ManagedIterator(dispatchers.iterator());
         }
@@ -421,7 +409,7 @@
             }
 
             public Object next() {
-                return iterator.next().getMember();
+                return references ? iterator.next().reference : iterator.next().proxy;
             }
 
             public void remove() {
@@ -434,12 +422,8 @@
 
     public static class ManagedList extends ManagedCollection implements List, RandomAccess
{
 
-        public ManagedList(Boolean references) {
-            super(references,  new DynamicCollection<ServiceDispatcher>(true, null));
-        }
-
-        public ManagedList(Boolean references, boolean orderingReferences, Comparator comparator)
{
-            super(references, new DynamicCollection<ServiceDispatcher>(true, new DispatcherComparator(comparator,
orderingReferences)));
+        public ManagedList(boolean references, DynamicCollection<ServiceDispatcher>
dispatchers) {
+            super(references, dispatchers);
         }
 
         @Override
@@ -448,7 +432,7 @@
         }
 
         public Object get(int index) {
-            return dispatchers.get(index).getMember();
+            return references ? dispatchers.get(index).reference : dispatchers.get(index).proxy;
         }
 
         public int indexOf(Object o) {
@@ -518,7 +502,7 @@
             }
 
             public Object next() {
-                return iterator.next().getMember();
+                return references ? iterator.next().reference : iterator.next().proxy;
             }
 
             public boolean hasPrevious() {
@@ -526,7 +510,7 @@
             }
 
             public Object previous() {
-                return iterator.previous().getMember();
+                return references ? iterator.previous().reference : iterator.previous().proxy;
             }
 
             public int nextIndex() {
@@ -554,14 +538,10 @@
 
     public static class ManagedSet extends ManagedCollection implements Set {
 
-        public ManagedSet(Boolean references) {
-            super(references, new DynamicCollection<ServiceDispatcher>(false, null));
+        public ManagedSet(boolean references, DynamicCollection<ServiceDispatcher>
dispatchers) {
+            super(references, dispatchers);
         }
         
-        public ManagedSet(Boolean references, boolean orderingReferences, Comparator comparator)
{
-            super(references, new DynamicCollection<ServiceDispatcher>(false, new DispatcherComparator(comparator,
orderingReferences)));
-        }
-
     }
 
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
Thu Jun  4 02:03:24 2009
@@ -69,6 +69,7 @@
             addObject(proxy, true);
 
             // Handle initial references
+            createListeners();
             retrack();
 
             // Return a ServiceProxy that can injection of references or proxies can be done
correctly

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java
Thu Jun  4 02:03:24 2009
@@ -56,6 +56,9 @@
 /**
  * A <code>Recipe</code> to export services into the OSGi registry.
  *
+ * TODO: refactor the bundle scope stuff
+ * TODO: if the bean is a prototype or a ServiceFactory, a null service should be sent to
listeners
+ *
  * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
  * @version $Rev: 776360 $, $Date: 2009-05-19 17:40:47 +0200 (Tue, 19 May 2009) $
  */

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
Thu Jun  4 02:03:24 2009
@@ -33,6 +33,7 @@
 import java.util.SortedSet;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.Arrays;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -74,10 +75,11 @@
         if (obj instanceof Convertible) {
             return ((Convertible) obj).convert(type);
         }
+        Class cl = toClass(type);
         // Handle arrays, collections and generics
         if (obj == null) {
             return null;
-        } else if (type instanceof GenericArrayType || (type instanceof Class &&
((Class) type).isArray())) {
+        } else if (cl.isArray()) {
             if (obj instanceof Collection) {
                 obj = ((Collection) obj).toArray();
             }
@@ -86,7 +88,7 @@
             }
             Type componentType = type instanceof GenericArrayType
                                         ? ((GenericArrayType) type).getGenericComponentType()
-                                        : ((Class) type).getComponentType();
+                                        : cl.getComponentType();
             Object array = Array.newInstance(toClass(componentType), Array.getLength(obj));
             for (int i = 0; i < Array.getLength(obj); i++) {
                 try {
@@ -97,32 +99,39 @@
             }
             return array;
         // TODO: removing the second part of the test will allow conversion between collections,
is this desired?
-        } else if (type instanceof ParameterizedType /*&& toClass(type).isInstance(obj)*/)
{
-            Class cl = toClass(type);
-            if (Map.class.isAssignableFrom(cl) && obj instanceof Map) {
-                Type keyType = Object.class;
-                Type valueType = Object.class;
-                Type[] typeParameters = getTypeParameters(Map.class, type);
-                if (typeParameters != null && typeParameters.length == 2) {
-                    keyType = typeParameters[0];
-                    valueType = typeParameters[1];
+        } else if (Map.class.isAssignableFrom(cl) && obj instanceof Map) {
+            Type keyType = Object.class;
+            Type valueType = Object.class;
+            Type[] typeParameters = getTypeParameters(Map.class, type);
+            if (typeParameters != null && typeParameters.length == 2) {
+                keyType = typeParameters[0];
+                valueType = typeParameters[1];
+            }
+            Map newMap = (Map) getMap(cl).newInstance();
+            for (Map.Entry e : ((Map<Object,Object>) obj).entrySet()) {
+                try {
+                    newMap.put(convert(e.getKey(), keyType, converter), convert(e.getValue(),
valueType, converter));
+                } catch (Exception t) {
+                    throw new Exception("Unable to convert from " + obj + " to " + type +
"(error converting map entry)", t);
                 }
-                Map newMap = (Map) getMap(cl).newInstance();
-                for (Map.Entry e : ((Map<Object,Object>) obj).entrySet()) {
+            }
+            return newMap;
+        } else if (Collection.class.isAssignableFrom(cl) && (obj instanceof Collection
|| obj.getClass().isArray())) {
+            Type valueType = Object.class;
+            Type[] typeParameters = getTypeParameters(Collection.class, type);
+            if (typeParameters != null && typeParameters.length == 1) {
+                valueType = typeParameters[0];
+            }
+            Collection newCol = (Collection) getCollection(cl).newInstance();
+            if (obj.getClass().isArray()) {
+                for (int i = 0; i < Array.getLength(obj); i++) {
                     try {
-                        newMap.put(convert(e.getKey(), keyType, converter), convert(e.getValue(),
valueType, converter));
+                        newCol.add(convert(Array.get(obj, i), valueType, converter));
                     } catch (Exception t) {
-                        throw new Exception("Unable to convert from " + obj + " to " + type
+ "(error converting map entry)", t);
+                        throw new Exception("Unable to convert from " + obj + " to " + type
+ "(error converting array element)", t);
                     }
                 }
-                return newMap;
-            } else if (Collection.class.isAssignableFrom(cl) && obj instanceof Collection)
{
-                Type valueType = Object.class;
-                Type[] typeParameters = getTypeParameters(Collection.class, type);
-                if (typeParameters != null && typeParameters.length == 1) {
-                    valueType = typeParameters[0];
-                }
-                Collection newCol = (Collection) getCollection(cl).newInstance();
+            } else {
                 for (Object item : (Collection) obj) {
                     try {
                         newCol.add(convert(item, valueType, converter));
@@ -130,8 +139,8 @@
                         throw new Exception("Unable to convert from " + obj + " to " + type
+ "(error converting collection entry)", t);
                     }
                 }
-                return newCol;
             }
+            return newCol;
         }
         return converter.convert(obj, toClass(type));
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicCollection.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicCollection.java?rev=781638&r1=781637&r2=781638&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicCollection.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/DynamicCollection.java
Thu Jun  4 02:03:24 2009
@@ -244,19 +244,23 @@
             this.index = index;
         }
 
-        protected synchronized void removedIndex(int index) {
-            if (index < this.index || (index == this.index && (hasNextCalled ||
hasPreviousCalled))) {
-                this.index--;
+        protected void removedIndex(int index) {
+            synchronized (lock) {
+                if (index < this.index || (index == this.index && (hasNextCalled
|| hasPreviousCalled))) {
+                    this.index--;
+                }
             }
         }
 
-        protected synchronized void addedIndex(int index) {
-            if (index < this.index || (index == this.index && (next != null ||
previous != null))) {
-                this.index++;
+        protected void addedIndex(int index) {
+            synchronized (lock) {
+                if (index < this.index || (index == this.index && (next != null
|| previous != null))) {
+                    this.index++;
+                }
             }
         }
 
-        public synchronized boolean hasNext() {
+        public boolean hasNext() {
             synchronized (lock) {
                 hasPreviousCalled = false;
                 hasNextCalled = true;
@@ -265,7 +269,7 @@
             }
         }
 
-        public synchronized boolean hasPrevious() {
+        public boolean hasPrevious() {
             synchronized (lock) {
                 hasPreviousCalled = true;
                 hasNextCalled = false;
@@ -274,52 +278,60 @@
             }
         }
 
-        public synchronized E next() {
-            try {
-                if (!hasNextCalled) {
-                    hasNext();
-                }
-                last = next;
-                if (next != null) {
-                    ++index;
-                    return next;
-                } else {
-                    throw new NoSuchElementException();
+        public E next() {
+            synchronized (lock) {
+                try {
+                    if (!hasNextCalled) {
+                        hasNext();
+                    }
+                    last = next;
+                    if (next != null) {
+                        ++index;
+                        return next;
+                    } else {
+                        throw new NoSuchElementException();
+                    }
+                } finally {
+                    hasPreviousCalled = false;
+                    hasNextCalled = false;
+                    next = null;
+                    previous = null;
                 }
-            } finally {
-                hasPreviousCalled = false;
-                hasNextCalled = false;
-                next = null;
-                previous = null;
             }
         }
 
-        public synchronized E previous() {
-            try {
-                if (!hasPreviousCalled) {
-                    hasPrevious();
-                }
-                last = previous;
-                if (previous != null) {
-                    --index;
-                    return previous;
-                } else {
-                    throw new NoSuchElementException();
+        public E previous() {
+            synchronized (lock) {
+                try {
+                    if (!hasPreviousCalled) {
+                        hasPrevious();
+                    }
+                    last = previous;
+                    if (previous != null) {
+                        --index;
+                        return previous;
+                    } else {
+                        throw new NoSuchElementException();
+                    }
+                } finally {
+                    hasPreviousCalled = false;
+                    hasNextCalled = false;
+                    next = null;
+                    previous = null;
                 }
-            } finally {
-                hasPreviousCalled = false;
-                hasNextCalled = false;
-                next = null;
-                previous = null;
             }
         }
 
-        public synchronized int nextIndex() {
-            return index;
+        public int nextIndex() {
+            synchronized (lock) {
+                return index;
+            }
         }
 
-        public synchronized int previousIndex() {
-            return index - 1;
+        public int previousIndex() {
+            synchronized (lock) {
+                return index - 1;
+            }
         }
 
         public void set(E o) {
@@ -330,7 +342,7 @@
             throw new UnsupportedOperationException();
         }
 
-        public synchronized void remove() {
+        public void remove() {
             throw new UnsupportedOperationException();
         }
 



Mime
View raw message