felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1579443 - in /felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm: context/ impl/
Date Wed, 19 Mar 2014 23:06:05 GMT
Author: pderop
Date: Wed Mar 19 23:06:04 2014
New Revision: 1579443

URL: http://svn.apache.org/r1579443
Log:
Added a close method in the Event interface, which is now invoked when a service is removed.
This allows to unget removed service references. (Only the ServiceEventImpl is currently implementing
the close method).

Modified:
    felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/context/Event.java
    felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/BundleDependencyImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/EventImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ResourceDependencyImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceDependencyImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceEventImpl.java

Modified: felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/context/Event.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/context/Event.java?rev=1579443&r1=1579442&r2=1579443&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/context/Event.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/context/Event.java Wed Mar
19 23:06:04 2014
@@ -1,8 +1,15 @@
 package dm.context;
 
+import org.osgi.framework.BundleContext;
+
 /** 
  * An event holds all data that belongs to some external event as it comes in via
  * the 'changed' callback of a dependency.
  */
 public interface Event {
+    /**
+     * Release the resources this event is holding (like service reference for example).
+     * @param m_context the bundle context possibly used to clean some service references.s
+     */
+    public void close(BundleContext context);
 }

Modified: felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/BundleDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/BundleDependencyImpl.java?rev=1579443&r1=1579442&r2=1579443&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/BundleDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/BundleDependencyImpl.java
Wed Mar 19 23:06:04 2014
@@ -22,7 +22,6 @@ import dm.context.Event;
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class BundleDependencyImpl extends DependencyImpl<BundleDependency> implements
BundleDependency, BundleTrackerCustomizer, ComponentDependencyDeclaration {
-    private final BundleContext m_context;
     private BundleTracker m_tracker;
     private int m_stateMask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE;
     private Bundle m_bundleInstance;
@@ -35,15 +34,13 @@ public class BundleDependencyImpl extend
     private final Logger m_logger;
 
     public BundleDependencyImpl(BundleContext context, Logger logger) {
-        super(true /* autoconfig */);
-        m_context = context;
+        super(true /* autoconfig */, context);
         m_logger = logger;
     }
     
     public BundleDependencyImpl(BundleDependencyImpl prototype) {
         super(prototype);
         m_logger = prototype.m_logger;
-        m_context = prototype.m_context;
         m_stateMask = prototype.m_stateMask;
         m_nullObject = prototype.m_nullObject;
         m_bundleInstance = prototype.m_bundleInstance;

Modified: felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java?rev=1579443&r1=1579442&r2=1579443&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java Wed
Mar 19 23:06:04 2014
@@ -2,8 +2,9 @@ package dm.impl;
 
 import java.util.Dictionary;
 
+import org.osgi.framework.BundleContext;
+
 import dm.Dependency;
-import dm.ServiceDependency;
 import dm.admin.ComponentDependencyDeclaration;
 import dm.context.ComponentContext;
 import dm.context.DependencyContext;
@@ -25,13 +26,15 @@ public class DependencyImpl<T extends De
     protected volatile boolean m_propagate;
     protected volatile Object m_propagateCallbackInstance;
     protected volatile String m_propagateCallbackMethod;
+    protected final BundleContext m_context;
 
 	public DependencyImpl() {	
-        this(true);
+        this(true, null);
 	}
 
-	public DependencyImpl(boolean autoConfig) {	
+	public DependencyImpl(boolean autoConfig, BundleContext bc) {	
         m_autoConfig = autoConfig;
+        m_context = bc;
 	}
 	
 	public DependencyImpl(DependencyImpl<T> prototype) {
@@ -48,7 +51,8 @@ public class DependencyImpl<T extends De
 		m_callbackInstance = prototype.m_callbackInstance;
         m_propagate = prototype.m_propagate;
         m_propagateCallbackInstance = prototype.m_propagateCallbackInstance;
-        m_propagateCallbackMethod = prototype.m_propagateCallbackMethod;       
+        m_propagateCallbackMethod = prototype.m_propagateCallbackMethod;
+        m_context = prototype.m_context;
 	}
 	
 	public void add(final Event e) {
@@ -81,7 +85,11 @@ public class DependencyImpl<T extends De
 		m_component.getExecutor().execute(new Runnable() {
 			@Override
 			public void run() {
-                m_component.handleRemoved(DependencyImpl.this, e);
+			    try {
+			        m_component.handleRemoved(DependencyImpl.this, e);	
+			    } finally {
+			        e.close(m_context);
+			    }
 			}
 		});
 	}

Modified: felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/EventImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/EventImpl.java?rev=1579443&r1=1579442&r2=1579443&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/EventImpl.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/EventImpl.java Wed Mar
19 23:06:04 2014
@@ -1,5 +1,7 @@
 package dm.impl;
 
+import org.osgi.framework.BundleContext;
+
 import dm.context.Event;
 
 /* in real life, this event might contain a service reference and service instance
@@ -42,4 +44,8 @@ public class EventImpl implements Event,
             return 1;
         }
     }
+    
+    @Override
+    public void close(BundleContext m_context) {
+    }
 }

Modified: felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ResourceDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ResourceDependencyImpl.java?rev=1579443&r1=1579442&r2=1579443&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ResourceDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ResourceDependencyImpl.java
Wed Mar 19 23:06:04 2014
@@ -21,21 +21,18 @@ import dm.context.Event;
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class ResourceDependencyImpl extends DependencyImpl<ResourceDependency> implements
ResourceDependency, ResourceHandler, ComponentDependencyDeclaration {
-    private volatile BundleContext m_context;
     private volatile ServiceRegistration m_registration;
     private volatile String m_resourceFilter;
     private volatile URL m_trackedResource;
     private final Logger m_logger;
 
     public ResourceDependencyImpl(BundleContext context, Logger logger) {
-        super(true /* autoconfig */);
-        m_context = context;
+        super(true /* autoconfig */, context);
         m_logger = logger;
     }
     
     public ResourceDependencyImpl(ResourceDependencyImpl prototype) {
         super(prototype);
-        m_context = prototype.m_context;
         m_resourceFilter = prototype.m_resourceFilter;
         m_trackedResource = prototype.m_trackedResource;
         m_logger = prototype.m_logger;

Modified: felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceDependencyImpl.java?rev=1579443&r1=1579442&r2=1579443&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceDependencyImpl.java
Wed Mar 19 23:06:04 2014
@@ -24,7 +24,6 @@ import dm.context.Event;
 
 public class ServiceDependencyImpl extends DependencyImpl<ServiceDependency> implements
ServiceDependency, ServiceTrackerCustomizer {
 	protected volatile ServiceTracker m_tracker;
-	protected final BundleContext m_context;
     private final Logger m_logger;
     protected volatile Class<?> m_trackedServiceName;
     private volatile String m_trackedServiceFilter;
@@ -110,15 +109,13 @@ public class ServiceDependencyImpl exten
     }
     
 	public ServiceDependencyImpl(BundleContext ctx, Logger logger) {
-		super(true /* autoconfig */);
-	    m_context = ctx;
+		super(true /* autoconfig */, ctx);
 	    m_logger = logger;
 	}
 	
 	public ServiceDependencyImpl(ServiceDependencyImpl prototype) {
 		super(prototype);
 		m_logger = prototype.m_logger;
-		m_context = prototype.m_context;	
         m_trackedServiceName = prototype.m_trackedServiceName;
         m_nullObject = prototype.m_nullObject;
         m_trackedServiceFilter = prototype.m_trackedServiceFilter;
@@ -211,8 +208,7 @@ public class ServiceDependencyImpl exten
 
 	@Override
 	public Object addingService(ServiceReference reference) {
-		Object service = getBundleContext().getService(reference);
-		return service;
+		return getBundleContext().getService(reference);
 	}
 
 	@Override

Modified: felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceEventImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceEventImpl.java?rev=1579443&r1=1579442&r2=1579443&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceEventImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ServiceEventImpl.java
Wed Mar 19 23:06:04 2014
@@ -1,6 +1,6 @@
 package dm.impl;
 
-import org.osgi.framework.Constants;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
 public class ServiceEventImpl extends EventImpl implements Comparable {
@@ -38,7 +38,15 @@ public class ServiceEventImpl extends Ev
     	return getReference().compareTo(((ServiceEventImpl) b).getReference());
     }
         
+    @Override
     public String toString() {
     	return m_service.toString();
     }
+
+    @Override
+    public void close(BundleContext context) {
+        if (context != null) {
+            context.ungetService(m_reference);
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message