geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r779033 - in /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint: container/ utils/
Date Wed, 27 May 2009 07:14:10 GMT
Author: gnodet
Date: Wed May 27 07:14:09 2009
New Revision: 779033

URL: http://svn.apache.org/viewvc?rev=779033&view=rev
Log:
Fix various problems

Modified:
    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/BlueprintObjectInstantiator.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/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/DynamicCollection.java

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=779033&r1=779032&r2=779033&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
Wed May 27 07:14:09 2009
@@ -500,6 +500,7 @@
                 initMethod.invoke(obj);
             } catch (Throwable t) {
                 LOGGER.info("Error invoking init method", getRealCause(t));
+                throw new ComponentDefinitionException("Unable to intialize bean " + getName(),
getRealCause(t));
             }
         }
         

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=779033&r1=779032&r2=779033&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
Wed May 27 07:14:09 2009
@@ -372,10 +372,7 @@
 
     private Map<String, List<SatisfiableRecipe>> getSatisfiableDependenciesMap()
{
         if (satisfiables == null && instantiator != null) {
-            boolean createNewContext = !ExecutionContext.isContextSet();
-            if (createNewContext) {
-                ExecutionContext.setContext(new DefaultExecutionContext(this, instantiator.getRepository()));
-            }
+            ExecutionContext oldContext = ExecutionContext.setContext(new DefaultExecutionContext(this,
instantiator.getRepository()));
             try {
                 satisfiables = new HashMap<String, List<SatisfiableRecipe>>();
                 for (Recipe r : instantiator.getAllRecipes()) {
@@ -386,9 +383,7 @@
                 }
                 return satisfiables;
             } finally {
-                if (createNewContext) {
-                    ExecutionContext.setContext(null);
-                }
+                ExecutionContext.setContext(oldContext);
             }
         }
         return satisfiables;
@@ -446,7 +441,7 @@
                             break;
                         }
                     }
-                    ServiceRecipe reg = (ServiceRecipe) getComponentInstance(name);
+                    ServiceRecipe reg = (ServiceRecipe) instantiator.getRepository().getRecipe(name);
                     if (satisfied && !reg.isRegistered()) {
                         LOGGER.debug("Registering service {} due to satisfied references",
name);
                         reg.register();

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=779033&r1=779032&r2=779033&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
Wed May 27 07:14:09 2009
@@ -67,11 +67,8 @@
         Map<String, Object> instances = new LinkedHashMap<String, Object>();
         for (String name : names) {
             
-            boolean createNewContext = !ExecutionContext.isContextSet();
-            if (createNewContext) {
-                ExecutionContext.setContext(new DefaultExecutionContext(blueprintContainer,
repository));
-            }
-            
+            ExecutionContext oldContext = ExecutionContext.setContext(new DefaultExecutionContext(blueprintContainer,
repository));
+
             try {
                 Object obj = createInstance(name);
                 try {
@@ -94,9 +91,7 @@
                     }
                 } while (modified);
             } finally {
-                if (createNewContext) {
-                    ExecutionContext.setContext(null);
-                }
+                ExecutionContext.setContext(oldContext);
             }
         }
         return instances;
@@ -113,10 +108,7 @@
     }
 
     public Set<Recipe> getAllRecipes(String... names) {
-        boolean createNewContext = !ExecutionContext.isContextSet();
-        if (createNewContext) {
-            ExecutionContext.setContext(new DefaultExecutionContext(blueprintContainer, repository));
-        }
+        ExecutionContext oldContext = ExecutionContext.setContext(new DefaultExecutionContext(blueprintContainer,
repository));
         try {
             Set<Recipe> recipes = new HashSet<Recipe>();
             Set<String> topLevel = names != null && names.length > 0 ? new
HashSet<String>(Arrays.asList(names)) : repository.getNames();
@@ -125,9 +117,7 @@
             }
             return recipes;
         } finally {
-            if (createNewContext) {
-                ExecutionContext.setContext(null);
-            }
+            ExecutionContext.setContext(oldContext);
         }
     }
 

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=779033&r1=779032&r2=779033&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
Wed May 27 07:14:09 2009
@@ -155,12 +155,17 @@
                 listenersRecipe.add(createRecipe(listener));
             }
         }
+        List<Recipe> deps = new ArrayList<Recipe>();
+        for (String name : serviceExport.getExplicitDependencies()) {
+            deps.add(new RefRecipe(getName(null), name));
+        }
         ServiceRecipe recipe = new ServiceRecipe(getName(serviceExport.getId()),
                                                  blueprintContainer,
                                                  serviceExport,
                                                  getValue(serviceExport.getServiceComponent(),
null),
                                                  listenersRecipe,
-                                                 getServicePropertiesRecipe(serviceExport));
+                                                 getServicePropertiesRecipe(serviceExport),
+                                                 deps);
         return recipe;
     }
 

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=779033&r1=779032&r2=779033&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
Wed May 27 07:14:09 2009
@@ -131,32 +131,40 @@
     }
 
     protected void track(ServiceReference reference) {
-        try {
-            ServiceDispatcher dispatcher = new ServiceDispatcher(reference);
-            dispatcher.proxy = createProxy(dispatcher, Arrays.asList((String[]) reference.getProperty(Constants.OBJECTCLASS)));
-            synchronized (collection) {
-                collection.addDispatcher(dispatcher);
-            }
-            if (listeners != null) {
-                for (Listener listener : listeners) {
-                    listener.bind(dispatcher.reference, dispatcher.proxy);
+        if (collection != null) {
+            try {
+                ServiceDispatcher dispatcher = new ServiceDispatcher(reference);
+                dispatcher.proxy = createProxy(dispatcher, Arrays.asList((String[]) reference.getProperty(Constants.OBJECTCLASS)));
+                synchronized (collection) {
+                    collection.addDispatcher(dispatcher);
                 }
+                if (listeners != null) {
+                    for (Listener listener : listeners) {
+                        if (listener != null) {
+                            listener.bind(dispatcher.reference, dispatcher.proxy);
+                        }
+                    }
+                }
+            } catch (Throwable t) {
+                LOGGER.info("Error tracking new service reference", t);
             }
-        } catch (Throwable t) {
-            LOGGER.info("Error tracking new service reference", t);
         }
     }
 
     protected void untrack(ServiceReference reference) {
-        ServiceDispatcher dispatcher = collection.findDispatcher(reference);
-        if (dispatcher != null) {
-            if (listeners != null) {
-                for (Listener listener : listeners) {
-                    listener.unbind(dispatcher.reference, dispatcher.proxy);
+        if (collection != null) {
+            ServiceDispatcher dispatcher = collection.findDispatcher(reference);
+            if (dispatcher != null) {
+                if (listeners != null) {
+                    for (Listener listener : listeners) {
+                        if (listener != null) {
+                            listener.unbind(dispatcher.reference, dispatcher.proxy);
+                        }
+                    }
+                }
+                synchronized (collection) {
+                    collection.removeDispatcher(dispatcher);
                 }
-            }
-            synchronized (collection) {
-                collection.removeDispatcher(dispatcher);
             }
             dispatcher.destroy();
         }

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=779033&r1=779032&r2=779033&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
Wed May 27 07:14:09 2009
@@ -153,6 +153,9 @@
             if (trackedService == null) {
                 trackedService = blueprintContainer.getBundleContext().getService(trackedServiceReference);
             }
+            if (trackedService == null) {
+                throw new IllegalStateException("getService() returned null for " + trackedServiceReference);
+            }
             return trackedService;
         }
     }

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=779033&r1=779032&r2=779033&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
Wed May 27 07:14:09 2009
@@ -9,6 +9,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.ArrayList;
 
 import org.apache.geronimo.blueprint.BlueprintConstants;
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
@@ -43,7 +44,7 @@
  * @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) $
  */
-public class ServiceRecipe extends AbstractRecipe implements ServiceRegistration {
+public class ServiceRecipe extends AbstractRecipe {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ServiceRecipe.class);
 
@@ -52,6 +53,7 @@
     private Recipe serviceRecipe;
     private CollectionRecipe listenersRecipe;
     private MapRecipe propertiesRecipe;
+    private List<Recipe> explicitDependencies;
 
     private Map properties;
     private ServiceRegistration registration;
@@ -61,11 +63,12 @@
     private boolean bundleScope;
 
     public ServiceRecipe(String name,
-                               ExtendedBlueprintContainer blueprintContainer,
-                               ServiceMetadata metadata,
-                               Recipe serviceRecipe,
-                               CollectionRecipe listenersRecipe,
-                               MapRecipe propertiesRecipe) {
+                         ExtendedBlueprintContainer blueprintContainer,
+                         ServiceMetadata metadata,
+                         Recipe serviceRecipe,
+                         CollectionRecipe listenersRecipe,
+                         MapRecipe propertiesRecipe,
+                         List<Recipe> explicitDependencies) {
         super(name);
         this.prototype = false;
         this.blueprintContainer = blueprintContainer;
@@ -73,10 +76,34 @@
         this.serviceRecipe = serviceRecipe;
         this.listenersRecipe = listenersRecipe;
         this.propertiesRecipe = propertiesRecipe;
+        this.explicitDependencies = explicitDependencies;
+    }
+
+    @Override
+    public List<Recipe> getNestedRecipes() {
+        List<Recipe> recipes = new ArrayList<Recipe>();
+        if (serviceRecipe != null) {
+            recipes.add(serviceRecipe);
+        }
+        if (listenersRecipe != null) {
+            recipes.add(listenersRecipe);
+        }
+        if (propertiesRecipe != null) {
+            recipes.add(propertiesRecipe);
+        }
+        if (explicitDependencies != null) {
+            recipes.addAll(explicitDependencies);
+        }
+        return recipes;
     }
 
     protected Object internalCreate() throws ComponentDefinitionException {
-        return this;
+        if (explicitDependencies != null) {
+            for (Recipe recipe : explicitDependencies) {
+                recipe.create();
+            }
+        }
+        return new ServiceRegistrationProxy();
     }
 
     public synchronized void register() {
@@ -108,7 +135,7 @@
 
     public synchronized ServiceReference getReference() {
         if (registration == null) {
-            throw new IllegalStateException();
+            throw new IllegalStateException("Service is not registered");
         } else {
             return registration.getReference();
         }
@@ -116,7 +143,7 @@
 
     public synchronized void setProperties(Dictionary props) {
         if (registration == null) {
-            throw new IllegalStateException();
+            throw new IllegalStateException("Service is not registered");
         } else {
             registration.setProperties(props);
             // TODO: set serviceProperties? convert somehow? should listeners be notified
of this?
@@ -177,6 +204,9 @@
             service = createInstance(true);
             LOGGER.debug("Created service instance for bundle: " + bundle + " " + service.hashCode());
         }
+        if (service == null) {
+            throw new IllegalStateException("service is null");
+        }
         return service;
     }
 
@@ -254,16 +284,11 @@
             BeanMetadata bean = (BeanMetadata) metadata;
             Class clazz = bean.getRuntimeClass();
             if (clazz == null) {
-                boolean isNewContext = !ExecutionContext.isContextSet();
-                if (isNewContext) {
-                    ExecutionContext.setContext(new DefaultExecutionContext(blueprintContainer,
blueprintContainer.getRepository()));
-                }
+                ExecutionContext oldContext = ExecutionContext.setContext(new DefaultExecutionContext(blueprintContainer,
blueprintContainer.getRepository()));
                 try {
                     clazz = loadClass(bean.getClassName());
                 } finally {
-                    if (isNewContext) {
-                        ExecutionContext.setContext(null);
-                    }
+                    ExecutionContext.setContext(oldContext);
                 }
             }
             if (ServiceFactory.class.isAssignableFrom(clazz)) {
@@ -297,6 +322,21 @@
 
     }
 
+    private class ServiceRegistrationProxy implements ServiceRegistration {
+
+        public ServiceReference getReference() {
+            return ServiceRecipe.this.getReference();
+        }
+
+        public void setProperties(Dictionary properties) {
+            ServiceRecipe.this.setProperties(properties);
+        }
+
+        public void unregister() {
+            ServiceRecipe.this.unregister();
+        }
+    }
+
     public static class Listener {
 
         private Object listener;
@@ -331,11 +371,13 @@
             Class[] paramTypes = new Class[] { service.getClass(), Map.class };
             Class listenerClass = listener.getClass();
 
-            if (metadata.getRegistrationMethodName() != null) {
-                registerMethods = ReflectionUtils.findCompatibleMethods(listenerClass, metadata.getRegistrationMethodName(),
paramTypes);
+            registerMethods = ReflectionUtils.findCompatibleMethods(listenerClass, metadata.getRegistrationMethodName(),
paramTypes);
+            if (registerMethods.size() == 0) {
+                throw new ComponentDefinitionException("No matching methods found for listener
registration method: " + metadata.getRegistrationMethodName());
             }
-            if (metadata.getUnregistrationMethodName() != null) {
-                unregisterMethods = ReflectionUtils.findCompatibleMethods(listenerClass,
metadata.getUnregistrationMethodName(), paramTypes);
+            unregisterMethods = ReflectionUtils.findCompatibleMethods(listenerClass, metadata.getUnregistrationMethodName(),
paramTypes);
+            if (unregisterMethods.size() == 0) {
+                throw new ComponentDefinitionException("No matching methods found for listener
unregistration method: " + metadata.getUnregistrationMethodName());
             }
             initialized = true;
         }

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=779033&r1=779032&r2=779033&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
Wed May 27 07:14:09 2009
@@ -251,17 +251,17 @@
         }
 
         protected synchronized void addedIndex(int index) {
-            if (index < this.index || (index == this.index && (hasNextCalled ||
hasPreviousCalled))) {
+            if (index < this.index || (index == this.index && (next != null ||
previous != null))) {
                 this.index++;
             }
         }
 
         public synchronized boolean hasNext() {
             synchronized (lock) {
-                next = index < storage.size() ? storage.get(index) : null;
                 hasPreviousCalled = false;
-                hasNextCalled = next != null;
-                return hasNextCalled;
+                hasNextCalled = true;
+                next = index < storage.size() ? storage.get(index) : null;
+                return next != null;
             }
         }
 
@@ -289,6 +289,8 @@
             } finally {
                 hasPreviousCalled = false;
                 hasNextCalled = false;
+                next = null;
+                previous = null;
             }
         }
 
@@ -307,6 +309,8 @@
             } finally {
                 hasPreviousCalled = false;
                 hasNextCalled = false;
+                next = null;
+                previous = null;
             }
         }
 



Mime
View raw message