geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r773052 - in /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint: ./ context/
Date Fri, 08 May 2009 18:07:45 GMT
Author: gawor
Date: Fri May  8 18:07:44 2009
New Revision: 773052

URL: http://svn.apache.org/viewvc?rev=773052&view=rev
Log:
make sure we stop tracking services at shutdown

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/SatisfiableRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectInstantiator.java
    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/context/ServiceReferenceTracker.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/SatisfiableRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/SatisfiableRecipe.java?rev=773052&r1=773051&r2=773052&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/SatisfiableRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/SatisfiableRecipe.java
Fri May  8 18:07:44 2009
@@ -45,8 +45,12 @@
 
     void start();
     
+    void stop();
+    
     boolean isSatisfied();
 
     void registerListener(SatisfactionListener listener);
+    
+    void unregisterListener(SatisfactionListener listener);
 
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java?rev=773052&r1=773051&r2=773052&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java
Fri May  8 18:07:44 2009
@@ -33,7 +33,6 @@
 
 import org.apache.geronimo.blueprint.BlueprintConstants;
 import org.apache.geronimo.blueprint.BlueprintContextEventSender;
-import org.apache.geronimo.blueprint.Destroyable;
 import org.apache.geronimo.blueprint.SatisfiableRecipe;
 import org.apache.geronimo.blueprint.utils.BundleDelegatingClassLoader;
 import org.apache.geronimo.blueprint.utils.ReflectionUtils;
@@ -54,7 +53,7 @@
  * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
  * @version $Rev: 760378 $, $Date: 2009-03-31 11:31:38 +0200 (Tue, 31 Mar 2009) $
  */
-public abstract class AbstractServiceReferenceRecipe extends AbstractRecipe implements ServiceListener,
Destroyable, SatisfiableRecipe {
+public abstract class AbstractServiceReferenceRecipe extends AbstractRecipe implements ServiceListener,
SatisfiableRecipe {
 
     protected final BlueprintContext blueprintContext;
     protected final BlueprintContextEventSender sender;
@@ -78,7 +77,7 @@
         this.proxyClassLoader = new BundleDelegatingClassLoader(blueprintContext.getBundleContext().getBundle(),
                                                                 getClass().getClassLoader());
         
-        boolean optional = (metadata.getAvailability() == ReferenceMetadata.OPTIONAL_AVAILABILITY);
+        boolean optional = (metadata.getAvailability() == ReferenceMetadata.AVAILABILITY_OPTIONAL);
         this.tracker = new ServiceReferenceTracker(blueprintContext.getBundleContext(), getOsgiFilter(),
optional);
     }
 
@@ -90,13 +89,16 @@
         }
     }
     
-    public void destroy() {
-        tracker.close();
+    public void stop() {
+        tracker.stop();
     }
     
     public void registerListener(SatisfactionListener listener) {
         tracker.registerListener(new SatisfactionListenerWrapper(this, listener));
     }
+    
+    public void unregisterListener(SatisfactionListener listener) {        
+    }
 
     public boolean isSatisfied() {
         return tracker.isSatisfied();

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java?rev=773052&r1=773051&r2=773052&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
Fri May  8 18:07:44 2009
@@ -364,6 +364,16 @@
         }
         LOGGER.debug("Tracking service references: {}", satisfiables);
     }
+    
+    private void untrackServiceReferences() {
+        Map<String, List<SatisfiableRecipe>> dependencies = getSatisfiableDependenciesMap();
+        for (String name : dependencies.keySet()) {
+            for (SatisfiableRecipe satisfiable : dependencies.get(name)) {
+                satisfiable.unregisterListener(this);
+                satisfiable.stop();
+            }
+        }
+    }
 
     private boolean checkAllSatisfiables() {
         Map<String, List<SatisfiableRecipe>> dependencies = getSatisfiableDependenciesMap();
@@ -559,17 +569,19 @@
     }
     
     public void destroy() {
+        sender.sendDestroying(this);
+        
         if (registration != null) {
             registration.unregister();
         }
-        handlers.removeListener(this);
-        sender.sendDestroying(this);
+        handlers.removeListener(this);        
+        untrackServiceReferences();
         unregisterServices();  
         unregisterTriggerServices();
         destroyComponents();
-        // TODO: stop all reference / collections
-        System.out.println("Module context destroyed: " + this.bundleContext);
+        
         sender.sendDestroyed(this);
+        LOGGER.debug("Module context destroyed: " + this.bundleContext);
     }
 
     public synchronized void namespaceHandlerRegistered(URI uri) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectInstantiator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectInstantiator.java?rev=773052&r1=773051&r2=773052&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectInstantiator.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectInstantiator.java
Fri May  8 18:07:44 2009
@@ -20,9 +20,7 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.xbean.recipe.ConstructionException;
 import org.apache.xbean.recipe.DefaultExecutionContext;

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=773052&r1=773051&r2=773052&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
Fri May  8 18:07:44 2009
@@ -74,6 +74,7 @@
         return true;
     }
 
+    @Override
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
         Comparator comparator = null;
         try {
@@ -82,7 +83,7 @@
             } else if (metadata.getOrderingBasis() != 0) {
                 comparator = new NaturalOrderComparator();
             }
-            boolean orderReferences = metadata.getOrderingBasis() == RefCollectionMetadata.ORDER_BASIS_SERVICE_REFERENCE;
+            boolean orderReferences = metadata.getOrderingBasis() == RefCollectionMetadata.ORDERING_BASIS_SERVICE_REFERENCE;
             boolean memberReferences = metadata.getMemberType() == RefCollectionMetadata.MEMBER_TYPE_SERVICE_REFERENCE;
             if (metadata.getCollectionType() == List.class) {
                 if (comparator != null) {
@@ -109,7 +110,7 @@
             }
 
             // Start tracking the service
-            tracker.registerListener(this);
+            tracker.registerServiceListener(this);
             retrack();
             
             return collection;
@@ -118,8 +119,8 @@
         }
     }
     
-    public void destroy() {
-        super.destroy();
+    public void stop() {
+        super.stop();
         List<ServiceDispatcher> dispatchers = new ArrayList<ServiceDispatcher>(collection.getDispatchers());
         for (ServiceDispatcher dispatcher : dispatchers) {
             untrack(dispatcher.reference);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java?rev=773052&r1=773051&r2=773052&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
Fri May  8 18:07:44 2009
@@ -74,13 +74,17 @@
         started = true;
     }
     
-    public synchronized void close() {
+    public synchronized void stop() {
         context.removeServiceListener(this);
         referenceSet.clear();
         satisfactionListeners.clear();
         started = false;
     }
     
+    public synchronized boolean isStarted() {
+        return started;
+    }
+    
     public boolean isSatisfied() {
         return satisfied;
     }
@@ -187,11 +191,11 @@
         return referenceSet.get(index);
     }
     
-    public void registerListener(ServiceListener listener) {
+    public void registerServiceListener(ServiceListener listener) {
         serviceListeners.add(listener);
     }
     
-    public void unregisterListener(ServiceListener listener) {
+    public void unregisterServiceListener(ServiceListener listener) {
         serviceListeners.remove(listener);
     }
     

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java?rev=773052&r1=773051&r2=773052&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java
Fri May  8 18:07:44 2009
@@ -61,6 +61,7 @@
         this.metadata = metadata;
     }
 
+    @Override
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
         try {
             // Create the proxy
@@ -74,7 +75,7 @@
             }
 
             // Start tracking the service
-            tracker.registerListener(this);
+            tracker.registerServiceListener(this);
             retrack();
             
             // Return the object
@@ -88,9 +89,13 @@
         return true;
     }
     
-    public void destroy() {
-        super.destroy();
+    @Override
+    public void stop() {
+        super.stop();
         unbind();
+        synchronized(monitor) {
+            monitor.notifyAll();
+        }
     }
 
     private void retrack() {
@@ -143,13 +148,17 @@
 
         public Object loadObject() throws Exception {
             synchronized (monitor) {
-                if (trackedService == null && metadata.getTimeout() > 0) {
+                if (tracker.isStarted() && trackedService == null && metadata.getTimeout()
> 0) {
                     Set<String> interfaces = new HashSet<String>(metadata.getInterfaceNames());
                     sender.sendWaiting(blueprintContext, interfaces.toArray(new String[interfaces.size()]),
getOsgiFilter());
                     monitor.wait(metadata.getTimeout());
                 }
                 if (trackedService == null) {
-                    throw new ServiceUnavailableException("Timeout expired when waiting for
OSGi service", proxyClass.getSuperclass(), getOsgiFilter());
+                    if (tracker.isStarted()) {
+                        throw new ServiceUnavailableException("Timeout expired when waiting
for OSGi service", proxyClass.getSuperclass(), getOsgiFilter());
+                    } else {
+                        throw new ServiceUnavailableException("Service tracker is stopped",
proxyClass.getSuperclass(), getOsgiFilter());
+                    }
                 }
                 return trackedService;
             }



Mime
View raw message