You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by dk...@apache.org on 2012/10/26 20:19:16 UTC

svn commit: r1402606 - in /aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container: AbstractServiceReferenceRecipe.java BlueprintContainerImpl.java

Author: dkulp
Date: Fri Oct 26 18:19:16 2012
New Revision: 1402606

URL: http://svn.apache.org/viewvc?rev=1402606&view=rev
Log:
Attempt to fix some hard to debug blueprint "grace period" hangs.
If a bundle has multiple processors, only stop and restart the services references once.

Modified:
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java?rev=1402606&r1=1402605&r2=1402606&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java Fri Oct 26 18:19:16 2012
@@ -87,7 +87,7 @@ public abstract class AbstractServiceRef
     private final AtomicBoolean satisfied = new AtomicBoolean();
     private SatisfactionListener satisfactionListener;
 
-	private final AccessControlContext accessControlContext;
+    private final AccessControlContext accessControlContext;
 
     protected AbstractServiceReferenceRecipe(String name,
                                              ExtendedBlueprintContainer blueprintContainer,
@@ -111,7 +111,6 @@ public abstract class AbstractServiceRef
         {
         	accessControlContext = null;
         }
-
     }
 
 
@@ -120,6 +119,7 @@ public abstract class AbstractServiceRef
         return listenersRecipe;
     }
 
+    static boolean waited = false;
     public void start(SatisfactionListener listener) {
         if (listener == null) throw new NullPointerException("satisfactionListener is null");
         if (started.compareAndSet(false, true)) {
@@ -158,6 +158,7 @@ public abstract class AbstractServiceRef
                 }
                 satisfied.set(false);
             }
+            satisfactionListener = null;
         }
     }
 
@@ -301,10 +302,10 @@ public abstract class AbstractServiceRef
     }
 
     public void serviceChanged(final ServiceEvent event) {
+        final int eventType = event.getType();
+        final ServiceReference ref = event.getServiceReference();
         blueprintContainer.getExecutors().submit(new Runnable() {
             public void run() {
-                int eventType = event.getType();
-                ServiceReference ref = event.getServiceReference();
                 switch (eventType) {
                     case ServiceEvent.REGISTERED:
                         serviceAdded(ref);
@@ -322,33 +323,43 @@ public abstract class AbstractServiceRef
 
     private void serviceAdded(ServiceReference ref) {
         LOGGER.debug("Tracking reference {} for OSGi service {}", ref, getOsgiFilter());
-        synchronized (references) {
-            if (references.contains(ref)) {
-                return;
+        if (isStarted()) {
+            synchronized (references) {
+                if (references.contains(ref)) {
+                    return;
+                }
+                references.add(ref);
             }
-            references.add(ref);
+            track(ref);
+            setSatisfied(true);
         }
-        track(ref);
-        setSatisfied(true);
     }
 
     private void serviceModified(ServiceReference ref) {
         // ref must be in references and must be satisfied
-        track(ref);
+        if (isStarted()) {
+            synchronized (references) {
+                if (references.contains(ref)) {
+                    track(ref);
+                }
+            }
+        }
     }
 
     private void serviceRemoved(ServiceReference ref) {
-        LOGGER.debug("Untracking reference {} for OSGi service {}", ref, getOsgiFilter());
-        boolean removed;
-        boolean satisfied;
-        synchronized (references) {
-            removed = references.remove(ref);
-            satisfied = optional || !references.isEmpty();
-        }
-        if (removed) {
-            untrack(ref);
+        if (isStarted()) {
+            LOGGER.debug("Untracking reference {} for OSGi service {}", ref, getOsgiFilter());
+            boolean removed;
+            boolean satisfied;
+            synchronized (references) {
+                removed = references.remove(ref);
+                satisfied = optional || !references.isEmpty();
+            }
+            if (removed) {
+                untrack(ref);
+            }
+            setSatisfied(satisfied);
         }
-        setSatisfied(satisfied);
     }
     
     protected Class getInterfaceClass() {

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1402606&r1=1402605&r2=1402606&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java (original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java Fri Oct 26 18:19:16 2012
@@ -475,6 +475,7 @@ public class BlueprintContainerImpl 
     }
 
     private void processProcessors() throws Exception {
+        boolean changed = false;
         // Instanciate ComponentDefinitionRegistryProcessor and BeanProcessor
         for (BeanMetadata bean : getMetadata(BeanMetadata.class)) {
             if (bean instanceof ExtendedBeanMetadata && !((ExtendedBeanMetadata) bean).isProcessor()) {
@@ -495,12 +496,16 @@ public class BlueprintContainerImpl 
             if (ComponentDefinitionRegistryProcessor.class.isAssignableFrom(clazz)) {
                 Object obj = repository.create(bean.getId(), ProxyUtils.asList(ComponentDefinitionRegistryProcessor.class));
                 ((ComponentDefinitionRegistryProcessor) obj).process(componentDefinitionRegistry);
+                changed = true;
             } else if (Processor.class.isAssignableFrom(clazz)) {
                 Object obj = repository.create(bean.getId(), ProxyUtils.asList(Processor.class));
                 this.processors.add((Processor) obj);
+                changed = true;
             } else {
                 continue;
             }
+        }
+        if (changed) {
             // Update repository with recipes processed by the processors
             untrackServiceReferences();
             Repository tmpRepo = new RecipeBuilder(this, tempRecipeIdSpace).createRepository();
@@ -527,7 +532,6 @@ public class BlueprintContainerImpl 
                     LOGGER.debug("Recipe {} is already instantiated and cannot be updated", new Object[] { name });
                 }
             }
-            
             getSatisfiableDependenciesMap(true);
             trackServiceReferences();
         }



Re: svn commit: r1402606 - in /aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container: AbstractServiceReferenceRecipe.java BlueprintContainerImpl.java

Posted by Daniel Kulp <dk...@apache.org>.
I added a test for this and managed to see the problem.   I've gone ahead and reverted the functionality change, but it's something I'd like to revisit at some point, just no time right now.

For every single processor, it's causing a stop/start of each of the service references.   If you have 10 processors, that's 10 stop/start cycles for every reference.   Keep in mind, each start involves a bunch of lookups, possible recreations of the proxies, etc..  Not cheap.

Dan



On Nov 16, 2012, at 5:59 AM, Guillaume Nodet <gn...@gmail.com> wrote:

> The following change actually breaks the way processor works.
> In karaf we do use layered property placeholders and this does not work
> anymore.
> For example, the following does not work anymore
> 
>    <ext:property-placeholder placeholder-prefix="$("
> placeholder-suffix=")"/>
> 
>    <ext:property-placeholder placeholder-prefix="$["
> placeholder-suffix="]" ignore-missing-locations="true">
>        <ext:default-properties>
>            <ext:property name="featuresRepositories" value=""/>
>            <ext:property name="featuresBoot" value=""/>
>            <ext:property name="resolverTimeout" value="5000"/>
>        </ext:default-properties>
> 
> <ext:location>file:$(karaf.base)/etc/org.apache.karaf.features.cfg</ext:location>
>    </ext:property-placeholder>
> 
> 
> On Fri, Oct 26, 2012 at 8:19 PM, <dk...@apache.org> wrote:
> 
>> Author: dkulp
>> Date: Fri Oct 26 18:19:16 2012
>> New Revision: 1402606
>> 
>> URL: http://svn.apache.org/viewvc?rev=1402606&view=rev
>> Log:
>> Attempt to fix some hard to debug blueprint "grace period" hangs.
>> If a bundle has multiple processors, only stop and restart the services
>> references once.
>> 
>> Modified:
>> 
>> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
>> 
>> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
>> 
>> Modified:
>> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1402606&r1=1402605&r2=1402606&view=diff
>> 
>> ==============================================================================
>> ---
>> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
>> (original)
>> +++
>> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
>> Fri Oct 26 18:19:16 2012
>> @@ -475,6 +475,7 @@ public class BlueprintContainerImpl
>>     }
>> 
>>     private void processProcessors() throws Exception {
>> +        boolean changed = false;
>>         // Instanciate ComponentDefinitionRegistryProcessor and
>> BeanProcessor
>>         for (BeanMetadata bean : getMetadata(BeanMetadata.class)) {
>>             if (bean instanceof ExtendedBeanMetadata &&
>> !((ExtendedBeanMetadata) bean).isProcessor()) {
>> @@ -495,12 +496,16 @@ public class BlueprintContainerImpl
>>             if
>> (ComponentDefinitionRegistryProcessor.class.isAssignableFrom(clazz)) {
>>                 Object obj = repository.create(bean.getId(),
>> ProxyUtils.asList(ComponentDefinitionRegistryProcessor.class));
>>                 ((ComponentDefinitionRegistryProcessor)
>> obj).process(componentDefinitionRegistry);
>> +                changed = true;
>>             } else if (Processor.class.isAssignableFrom(clazz)) {
>>                 Object obj = repository.create(bean.getId(),
>> ProxyUtils.asList(Processor.class));
>>                 this.processors.add((Processor) obj);
>> +                changed = true;
>>             } else {
>>                 continue;
>>             }
>> +        }
>> +        if (changed) {
>>             // Update repository with recipes processed by the processors
>>             untrackServiceReferences();
>>             Repository tmpRepo = new RecipeBuilder(this,
>> tempRecipeIdSpace).createRepository();
>> @@ -527,7 +532,6 @@ public class BlueprintContainerImpl
>>                     LOGGER.debug("Recipe {} is already instantiated and
>> cannot be updated", new Object[] { name });
>>                 }
>>             }
>> -
>>             getSatisfiableDependenciesMap(true);
>>             trackServiceReferences();
>>         }
>> 
>> 
>> 
> 
> 
> -- 
> ------------------------
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> ------------------------
> FuseSource, Integration everywhere
> http://fusesource.com

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: svn commit: r1402606 - in /aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container: AbstractServiceReferenceRecipe.java BlueprintContainerImpl.java

Posted by Guillaume Nodet <gn...@gmail.com>.
The following change actually breaks the way processor works.
In karaf we do use layered property placeholders and this does not work
anymore.
For example, the following does not work anymore

    <ext:property-placeholder placeholder-prefix="$("
placeholder-suffix=")"/>

    <ext:property-placeholder placeholder-prefix="$["
placeholder-suffix="]" ignore-missing-locations="true">
        <ext:default-properties>
            <ext:property name="featuresRepositories" value=""/>
            <ext:property name="featuresBoot" value=""/>
            <ext:property name="resolverTimeout" value="5000"/>
        </ext:default-properties>

<ext:location>file:$(karaf.base)/etc/org.apache.karaf.features.cfg</ext:location>
    </ext:property-placeholder>


On Fri, Oct 26, 2012 at 8:19 PM, <dk...@apache.org> wrote:

> Author: dkulp
> Date: Fri Oct 26 18:19:16 2012
> New Revision: 1402606
>
> URL: http://svn.apache.org/viewvc?rev=1402606&view=rev
> Log:
> Attempt to fix some hard to debug blueprint "grace period" hangs.
> If a bundle has multiple processors, only stop and restart the services
> references once.
>
> Modified:
>
> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
>
> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
>
> Modified:
> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
> URL:
> http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1402606&r1=1402605&r2=1402606&view=diff
>
> ==============================================================================
> ---
> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
> (original)
> +++
> aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
> Fri Oct 26 18:19:16 2012
> @@ -475,6 +475,7 @@ public class BlueprintContainerImpl
>      }
>
>      private void processProcessors() throws Exception {
> +        boolean changed = false;
>          // Instanciate ComponentDefinitionRegistryProcessor and
> BeanProcessor
>          for (BeanMetadata bean : getMetadata(BeanMetadata.class)) {
>              if (bean instanceof ExtendedBeanMetadata &&
> !((ExtendedBeanMetadata) bean).isProcessor()) {
> @@ -495,12 +496,16 @@ public class BlueprintContainerImpl
>              if
> (ComponentDefinitionRegistryProcessor.class.isAssignableFrom(clazz)) {
>                  Object obj = repository.create(bean.getId(),
> ProxyUtils.asList(ComponentDefinitionRegistryProcessor.class));
>                  ((ComponentDefinitionRegistryProcessor)
> obj).process(componentDefinitionRegistry);
> +                changed = true;
>              } else if (Processor.class.isAssignableFrom(clazz)) {
>                  Object obj = repository.create(bean.getId(),
> ProxyUtils.asList(Processor.class));
>                  this.processors.add((Processor) obj);
> +                changed = true;
>              } else {
>                  continue;
>              }
> +        }
> +        if (changed) {
>              // Update repository with recipes processed by the processors
>              untrackServiceReferences();
>              Repository tmpRepo = new RecipeBuilder(this,
> tempRecipeIdSpace).createRepository();
> @@ -527,7 +532,6 @@ public class BlueprintContainerImpl
>                      LOGGER.debug("Recipe {} is already instantiated and
> cannot be updated", new Object[] { name });
>                  }
>              }
> -
>              getSatisfiableDependenciesMap(true);
>              trackServiceReferences();
>          }
>
>
>


-- 
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com