geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r777901 - in /geronimo/sandbox/blueprint: blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ blueprint-itests/src/test/java/org/apache/geronimo/blueprint/ites...
Date Sat, 23 May 2009 12:30:37 GMT
Author: gnodet
Date: Sat May 23 12:30:36 2009
New Revision: 777901

URL: http://svn.apache.org/viewvc?rev=777901&view=rev
Log:
Support full cycles with listeners by creating listeners after all other objects

Removed:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ObjectGraph.java
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/BlueprintObjectInstantiator.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/CollectionBasedServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/UnaryServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Recipe.java
    geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
    geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/BindingListener.java
    geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml

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=777901&r1=777900&r2=777901&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
Sat May 23 12:30:36 2009
@@ -151,14 +151,18 @@
         return filter;
     }
 
-    protected void createListeners() throws ClassNotFoundException {
-        if (listenersRecipe != null) {
-            listeners = (List<Listener>) listenersRecipe.create();
-            for (Listener listener : listeners) {
-                listener.init(getAllClasses(metadata.getInterfaceNames()));
+    protected void createListeners() {
+        try {
+            if (listenersRecipe != null) {
+                listeners = (List<Listener>) listenersRecipe.create();
+                for (Listener listener : listeners) {
+                    listener.init(getAllClasses(metadata.getInterfaceNames()));
+                }
+            } else {
+                listeners = Collections.emptyList();
             }
-        } else {
-            listeners = Collections.emptyList();
+        } catch (ClassNotFoundException e) {
+            throw new ConstructionException(e);
         }
     }
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectInstantiator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectInstantiator.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectInstantiator.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectInstantiator.java
Sat May 23 12:30:36 2009
@@ -22,6 +22,9 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.ArrayList;
 
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
 import org.apache.geronimo.blueprint.di.ConstructionException;
@@ -77,6 +80,18 @@
                     throw new ConstructionException("Unable to convert instance " + name,
e);
                 }
                 instances.put(name, obj);
+                Set<Recipe> processed = new HashSet<Recipe>();
+                boolean modified;
+                do {
+                    modified = false;
+                    List<Recipe> recipes = new ArrayList<Recipe>(ExecutionContext.getContext().getCreatedRecipes());
+                    for (Recipe recipe : recipes) {
+                        if (processed.add(recipe)) {
+                            recipe.postCreate();
+                            modified = true;
+                        }
+                    }
+                } while (modified);
             } finally {
                 if (createNewContext) {
                     ExecutionContext context = ExecutionContext.getContext();

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java
Sat May 23 12:30:36 2009
@@ -25,7 +25,6 @@
 import java.util.Set;
 
 import org.apache.geronimo.blueprint.di.DefaultRepository;
-import org.apache.geronimo.blueprint.di.ObjectGraph;
 import org.apache.geronimo.blueprint.di.Repository;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceFactory;
@@ -81,7 +80,7 @@
         Repository objectRepository = blueprintContainer.getRepository();
         DefaultRepository repository = new DefaultRepository((DefaultRepository)objectRepository);
         repository.set(serviceRecipe.getName(), serviceRecipe);
-        ObjectGraph graph = new ObjectGraph(blueprintContainer, repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(blueprintContainer,
repository);
         return graph.create(serviceRecipe.getName());
     }
     

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/CollectionBasedServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/CollectionBasedServiceReferenceRecipe.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/CollectionBasedServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/CollectionBasedServiceReferenceRecipe.java
Sat May 23 12:30:36 2009
@@ -112,18 +112,8 @@
             }
 
             // Add partially created collection to the container
-            addObject(collection, true);
-            
-            // Create the listeners and initialize them
-            createListeners();
-            
-            // Add fully created collection to the container
             addObject(collection, false);
 
-            // Start tracking the service
-            tracker.registerServiceListener(this);
-            retrack();
-            
             return collection;
         } catch (ConstructionException t) {
             throw t;
@@ -131,7 +121,17 @@
             throw new ConstructionException(t);
         }
     }
-    
+
+    @Override
+    public void postCreate() {
+        // Create the listeners and initialize them
+        createListeners();
+        // Start tracking the service
+        tracker.registerServiceListener(this);
+        // Retrack to inform listeners
+        retrack();
+    }
+
     public void stop() {
         super.stop();
         if (collection != null) {
@@ -158,8 +158,10 @@
             synchronized (collection) {
                 collection.addDispatcher(dispatcher);
             }
-            for (Listener listener : listeners) {
-                listener.bind(dispatcher.reference, dispatcher.proxy);
+            if (listeners != null) {
+                for (Listener listener : listeners) {
+                    listener.bind(dispatcher.reference, dispatcher.proxy);
+                }
             }
         } catch (Throwable t) {
             LOGGER.info("Error tracking new service reference", t);
@@ -169,8 +171,10 @@
     protected void untrack(ServiceReference reference) {
         ServiceDispatcher dispatcher = collection.findDispatcher(reference);
         if (dispatcher != null) {
-            for (Listener listener : listeners) {
-                listener.unbind(dispatcher.reference, dispatcher.proxy);
+            if (listeners != null) {
+                for (Listener listener : listeners) {
+                    listener.unbind(dispatcher.reference, dispatcher.proxy);
+                }
             }
             synchronized (collection) {
                 collection.removeDispatcher(dispatcher);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java
Sat May 23 12:30:36 2009
@@ -133,7 +133,6 @@
                                                                    metadata,
                                                                    listenersRecipe,
                                                                    comparatorRecipe);
-        recipe.setAllowPartial(true);
         recipe.setName(getName(metadata.getId()));
         return recipe;
     }
@@ -150,7 +149,6 @@
                                                                              blueprintContainer.getSender(),
                                                                              metadata,
                                                                              listenersRecipe);
-        recipe.setAllowPartial(true);
         recipe.setName(getName(metadata.getId()));
         return recipe;
     }
@@ -177,7 +175,6 @@
             recipe.setName(getName(serviceExport.getId()));
             recipe.setExplicitDependencies(serviceExport.getExplicitDependencies());
             recipe.setInitMethod("init");
-            recipe.setAllowPartial(true);
             recipe.setProperty("blueprintContainer", blueprintContainer);
             BeanMetadata exportedComponent = getLocalServiceComponent(serviceExport.getServiceComponent());
             if (exportedComponent != null && BeanMetadata.SCOPE_BUNDLE.equals(exportedComponent.getScope()))
{

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/UnaryServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/UnaryServiceReferenceRecipe.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/UnaryServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/UnaryServiceReferenceRecipe.java
Sat May 23 12:30:36 2009
@@ -69,16 +69,11 @@
             proxyClass = proxy.getClass();
 
             // Add partially created proxy to the context
-            addObject(proxy, true);
-
-            // Create the listeners and initialize them
-            createListeners();
-
-            // Add fully created proxy to the context
             addObject(proxy, false);
 
-            // Start tracking the service
+            // Start track the service
             tracker.registerServiceListener(this);
+            // Handle initial references
             retrack();
 
             // Return a ServiceProxy that can injection of references or proxies can be done
correctly
@@ -89,6 +84,14 @@
     }
 
     @Override
+    public void postCreate() {
+        // Create the listeners and initialize them
+        createListeners();
+        // Retrack to inform listeners
+        retrack();
+    }
+
+    @Override
     public void stop() {
         super.stop();
         unbind();
@@ -124,8 +127,10 @@
             trackedServiceReference = ref;
             trackedService = null;
             monitor.notifyAll();
-            for (Listener listener : listeners) {
-                listener.bind(trackedServiceReference, proxy);
+            if (listeners != null) {
+                for (Listener listener : listeners) {
+                    listener.bind(trackedServiceReference, proxy);
+                }
             }
         }
     }
@@ -133,8 +138,10 @@
     private void unbind() {
         synchronized (monitor) {
             if (trackedServiceReference != null) {
-                for (Listener listener : listeners) {
-                    listener.unbind(trackedServiceReference, proxy);
+                if (listeners != null) {
+                    for (Listener listener : listeners) {
+                        listener.unbind(trackedServiceReference, proxy);
+                    }
                 }
                 blueprintContainer.getBundleContext().ungetService(trackedServiceReference);
                 trackedServiceReference = null;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java
Sat May 23 12:30:36 2009
@@ -75,7 +75,10 @@
     }
 
     protected abstract Object internalCreate(boolean lazyRefAllowed) throws ConstructionException;
-    
+
+    public void postCreate() {
+    }
+
     public void setAllowPartial(Boolean allowPartial) {
         this.allowPartial = allowPartial;
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java
Sat May 23 12:30:36 2009
@@ -41,7 +41,9 @@
     /**
      * Contains partial objects.
      */
-    private Map<String, Object> partialObjects = new HashMap<String, Object>();
+    private Map<String, Object> createdObjects = new HashMap<String, Object>();
+
+    private List<Recipe> createdRecipes = new ArrayList<Recipe>();
     
     /**
      * Before each recipe is executed it is pushed on the stack.  The
@@ -85,6 +87,7 @@
             throw new CircularDependencyException(circularity);
         }
         stack.add(recipe);
+        createdRecipes.add(recipe);
     }
 
     public Recipe pop() {
@@ -127,12 +130,10 @@
     }
 
     public void addObject(String name, Object object, boolean partialObject) {
-        if (partialObject) {
-            partialObjects.put(name, object);
-        } else {
+        createdObjects.put(name, object);
+        if (!partialObject) {
             addObject(name, object);
-            partialObjects.remove(name);
-        }        
+        }
     }
     
     public boolean containsCreatedObject(String name) {
@@ -142,7 +143,7 @@
                 return true;
             }
         }
-        return partialObjects.containsKey(name);
+        return createdObjects.containsKey(name);
     }
     
     public Object getCreatedObject(String name) {
@@ -152,9 +153,13 @@
                 return obj;
             }
         }
-        return partialObjects.get(name);
+        return createdObjects.get(name);
     }
-    
+
+    public List<Recipe> getCreatedRecipes() {
+        return createdRecipes;
+    }
+
     public void addReference(Reference reference) {
         Object value = repository.get(reference.getName());
         if (value != null && !(value instanceof Recipe)) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java
Sat May 23 12:30:36 2009
@@ -113,6 +113,8 @@
     
     public abstract Object getCreatedObject(String name);
 
+    public abstract List<Recipe> getCreatedRecipes();
+
     public abstract Object convert(Object value, Type type) throws Exception;
 
     public abstract Class loadClass(String className) throws ClassNotFoundException;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Recipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Recipe.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Recipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Recipe.java
Sat May 23 12:30:36 2009
@@ -35,4 +35,7 @@
     List<Recipe> getConstructorRecipes();
 
     Destroyable getDestroyable(Object instance);
+
+    void postCreate();
+
 }

Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
Sat May 23 12:30:36 2009
@@ -37,6 +37,7 @@
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.OptionUtils;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/BindingListener.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/BindingListener.java?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/BindingListener.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/BindingListener.java
Sat May 23 12:30:36 2009
@@ -17,6 +17,7 @@
 package org.apache.geronimo.blueprint.sample;
 
 import java.util.Map;
+import java.util.List;
 import java.io.Serializable;
 
 import org.osgi.framework.ServiceReference;
@@ -26,6 +27,7 @@
     private InterfaceA a;
     private Map props;
     private ServiceReference reference;
+    private List list;
 
     public InterfaceA getA() {
         return a;
@@ -39,6 +41,17 @@
         return reference;
     }
 
+    public List getList() {
+        return list;
+    }
+
+    public void setList(List list) {
+        this.list = list;
+    }
+
+    public void init() {
+    }
+
     public void bind(InterfaceA a, Map props) {
         this.a = a;
         this.props = props;

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=777901&r1=777900&r2=777901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
Sat May 23 12:30:36 2009
@@ -83,5 +83,12 @@
 
     <bean id="listBindingListener" class="org.apache.geronimo.blueprint.sample.BindingListener"/>
 
+    <bean id="circularReference" class="org.apache.geronimo.blueprint.sample.BindingListener"
init-method="init">
+        <property name="list">
+            <ref-list interface="org.apache.geronimo.blueprint.sample.InterfaceA" availability="optional">
+                <listener bind-method="bind" unbind-method="unbind" ref="circularReference"/>
+            </ref-list>
+        </property>
+    </bean>
 </blueprint>
 



Mime
View raw message