felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1639999 - in /felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm: context/ComponentContext.java impl/ComponentImpl.java impl/FilterComponent.java impl/ServiceDependencyImpl.java
Date Sun, 16 Nov 2014 16:39:07 GMT
Author: pderop
Date: Sun Nov 16 16:39:06 2014
New Revision: 1639999

URL: http://svn.apache.org/r1639999
Log:
Added a isActive method in the ComponentContext interface, in order to check if a component
is enabled or disabled.
We are using the isActive method in ServiceDependencyImpl, when the addingService can't get
a service reference because
the bundle context is invalid. And we don't log an exception if the component is not enabled
at this time.

Modified:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java?rev=1639999&r1=1639998&r2=1639999&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java
Sun Nov 16 16:39:06 2014
@@ -29,6 +29,7 @@ public interface ComponentContext extend
     public Component setThreadPool(Executor threadPool);
     public void start();
     public void stop();
+    public boolean isActive();
     public boolean isAvailable();
     public void handleAdded(DependencyContext dc, Event e);
     public void handleChanged(DependencyContext dc, Event e);

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java?rev=1639999&r1=1639998&r2=1639999&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
Sun Nov 16 16:39:06 2014
@@ -40,6 +40,7 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.ConcurrentSkipListSet;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.felix.dm.Component;
@@ -82,7 +83,7 @@ public class ComponentImpl implements Co
     private static AtomicLong m_idGenerator = new AtomicLong();
     // Holds all the services of a given dependency context. Caution: the last entry in the
skiplist is the highest ranked service.
     private final Map<DependencyContext, ConcurrentSkipListSet<Event>> m_dependencyEvents
= new HashMap<>();
-    private volatile boolean m_active;
+    private final AtomicBoolean m_active = new AtomicBoolean(false);
     
     private boolean debug = false;
     private String debugKey;
@@ -213,25 +214,27 @@ public class ComponentImpl implements Co
 	}
 
 	public void start() {
-	    m_active = true;
-		getExecutor().execute(new Runnable() {
-			@Override
-			public void run() {
-				m_isStarted = true;
-				handleChange();
-			}
-		});
+	    if (m_active.compareAndSet(false, true)) {
+            getExecutor().execute(new Runnable() {
+                @Override
+                public void run() {
+                    m_isStarted = true;
+                    handleChange();
+                }
+            });
+	    }
 	}
 	
 	public void stop() {
-		getExecutor().execute(new Runnable() {
-			@Override
-			public void run() {
-				m_isStarted = false;
-				handleChange();
-				m_active = false;
-			}
-		});
+	    if (m_active.compareAndSet(true, false)) {
+            getExecutor().execute(new Runnable() {
+                @Override
+                public void run() {
+                    m_isStarted = false;
+                    handleChange();
+                }
+            });
+	    }
 	}
 
 	@Override
@@ -667,7 +670,7 @@ public class ComponentImpl implements Co
     private void unregisterService() {
         if (m_serviceName != null && m_registration != null) {
             try {
-                if (m_bundle == null || m_bundle.getState() == Bundle.ACTIVE) {
+                if (m_bundle != null && m_bundle.getState() == Bundle.ACTIVE) {
                     m_registration.unregister();
                 }
             } catch (IllegalStateException e) { /* Should we really log this ? */}
@@ -906,11 +909,17 @@ public class ComponentImpl implements Co
 		}
 	}
 	
+	@Override
 	public boolean isAvailable() {
 		return m_state == TRACKING_OPTIONAL;
 	}
 	
 	@Override
+	public boolean isActive() {
+	    return m_active.get();
+	}
+	
+	@Override
 	public Component add(final ComponentStateListener l) {
 	    m_listeners.add(l);
 	    return this;
@@ -1237,7 +1246,7 @@ public class ComponentImpl implements Co
     }
 
     public void ensureNotActive() {
-        if (m_active) {
+        if (m_active.get()) {
             throw new IllegalStateException("Can't modify an already started component.");
         }
     }

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java?rev=1639999&r1=1639998&r2=1639999&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java
Sun Nov 16 16:39:06 2014
@@ -284,6 +284,11 @@ public class FilterComponent implements 
     }
         
     @Override
+    public boolean isActive() {
+        return m_component.isActive();
+    }
+
+    @Override
     public boolean isAvailable() {
         return m_component.isAvailable();
     }

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java?rev=1639999&r1=1639998&r2=1639999&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ServiceDependencyImpl.java
Sun Nov 16 16:39:06 2014
@@ -36,6 +36,7 @@ import org.apache.felix.dm.context.Depen
 import org.apache.felix.dm.context.Event;
 import org.apache.felix.dm.tracker.ServiceTracker;
 import org.apache.felix.dm.tracker.ServiceTrackerCustomizer;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
@@ -231,7 +232,16 @@ public class ServiceDependencyImpl exten
 
 	@Override
 	public Object addingService(ServiceReference reference) {
-		return getBundleContext().getService(reference);
+		try {
+		    return getBundleContext().getService(reference);
+		} catch (IllegalStateException e) {
+		    // most likely our bundle is being stopped. Only log an exception if our component
is enabled.
+		    if (m_component.isActive()) {
+                m_logger.log(Logger.LOG_WARNING, "could not handle service dependency for
component "
+                    + m_component.getComponentDeclaration().getClassName(), e);
+		    }
+		    return null;		    
+		}
 	}
 
 	@Override



Mime
View raw message