felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r959632 - in /felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm: dependencies/ impl/ impl/dependencies/
Date Thu, 01 Jul 2010 12:23:51 GMT
Author: marrs
Date: Thu Jul  1 12:23:51 2010
New Revision: 959632

URL: http://svn.apache.org/viewvc?rev=959632&view=rev
Log:
Fixed an issue with adapters and extra dependencies that had callbacks. Callbacks were not
always invoked correctly for each new adapter instance. This has now been fixed and while
at it, I also improved the shell output of several types of dependencies.

Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AspectServiceImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/BundleAdapterServiceImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyBase.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java
Thu Jul  1 12:23:51 2010
@@ -109,4 +109,9 @@ public interface Dependency {
     
     public boolean isPropagated();
     public Dictionary getProperties();
+    
+    /**
+     * Creates a copy of this dependency, cloning all declared state, but not the runtime
state.
+     */
+    public Dependency createCopy();
 }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
Thu Jul  1 12:23:51 2010
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Properties;
 
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.service.Service;
 import org.apache.felix.dm.service.ServiceStateListener;
 import org.osgi.framework.ServiceReference;
@@ -79,10 +80,15 @@ public class AdapterServiceImpl extends 
                 .setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect
                 .setComposition(m_compositionInstance, m_compositionMethod) // if not set,
no effect
                 .setCallbacks(m_callbackObject, m_init, m_start, m_stop, m_destroy) // if
not set, no effect
-                .add(dependencies)
+//                .add(dependencies)
                 .add(m_manager.createServiceDependency()
                      .setService(m_adapteeInterface, ref)
                      .setRequired(true));
+            
+            for (Object d : dependencies) {
+                service.add(((Dependency) d).createCopy());
+            }
+            
             for (int i = 0; i < m_stateListeners.size(); i ++) {
                 service.addStateListener((ServiceStateListener) m_stateListeners.get(i));
             }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AspectServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AspectServiceImpl.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AspectServiceImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AspectServiceImpl.java
Thu Jul  1 12:23:51 2010
@@ -86,8 +86,12 @@ public class AspectServiceImpl extends F
                 .setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect
                 .setComposition(m_compositionInstance, m_compositionMethod) // if not set,
no effect
                 .setCallbacks(m_callbackObject, m_init, m_start, m_stop, m_destroy) // if
not set, no effect
-                .add(dependencies)
                 .add(getAspectDependency());
+            
+            for (Object d : dependencies) {
+                service.add(((Dependency) d).createCopy());
+            }
+
             for (int i = 0; i < m_stateListeners.size(); i ++) {
                 service.addStateListener((ServiceStateListener) m_stateListeners.get(i));
             }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/BundleAdapterServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/BundleAdapterServiceImpl.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/BundleAdapterServiceImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/BundleAdapterServiceImpl.java
Thu Jul  1 12:23:51 2010
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Properties;
 
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.service.Service;
 import org.apache.felix.dm.service.ServiceStateListener;
 import org.osgi.framework.Bundle;
@@ -77,13 +78,18 @@ public class BundleAdapterServiceImpl ex
                 .setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect
                 .setComposition(m_compositionInstance, m_compositionMethod) // if not set,
no effect
                 .setCallbacks(m_callbackObject, m_init, m_start, m_stop, m_destroy) // if
not set, no effect
-                .add(dependencies)
                 .add(m_manager.createBundleDependency()
                     .setBundle(bundle)
+                    .setStateMask(m_bundleStateMask)
                     .setPropagate(m_propagate)
                     .setCallbacks(null, "changed", null)
                     .setAutoConfig(true)
                     .setRequired(true));
+
+            for (Object d : dependencies) {
+                service.add(((Dependency) d).createCopy());
+            }
+
             for (int i = 0; i < m_stateListeners.size(); i ++) {
                 service.addStateListener((ServiceStateListener) m_stateListeners.get(i));
             }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
Thu Jul  1 12:23:51 2010
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Properties;
 
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.service.Service;
 import org.apache.felix.dm.service.ServiceStateListener;
@@ -75,13 +76,17 @@ public class ResourceAdapterServiceImpl 
                 .setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect
                 .setComposition(m_compositionInstance, m_compositionMethod) // if not set,
no effect
                 .setCallbacks(m_callbackObject, m_init, m_start, m_stop, m_destroy) // if
not set, no effect
-                .add(dependencies)
                 .add(m_manager.createResourceDependency()
                      .setResource(resource)
                      .setPropagate(m_propagate)
                      .setCallbacks(null, "changed", null)
                      .setAutoConfig(true)
-                     .setRequired(true));         
+                     .setRequired(true));
+            
+            for (Object d : dependencies) {
+                service.add(((Dependency) d).createCopy());
+            }
+
             for (int i = 0; i < m_stateListeners.size(); i ++) {
                 service.addStateListener((ServiceStateListener) m_stateListeners.get(i));
             }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java
Thu Jul  1 12:23:51 2010
@@ -24,6 +24,7 @@ import java.util.Dictionary;
 import java.util.List;
 
 import org.apache.felix.dm.dependencies.BundleDependency;
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.impl.DefaultNullObject;
 import org.apache.felix.dm.impl.Logger;
 import org.apache.felix.dm.impl.tracker.BundleTracker;
@@ -62,6 +63,27 @@ public class BundleDependencyImpl extend
 		m_context = context;
 		m_autoConfig = true;
 	}
+    
+    public BundleDependencyImpl(BundleDependencyImpl prototype) {
+        super(prototype);
+        m_context = prototype.m_context;
+        m_autoConfig = prototype.m_autoConfig;
+        m_stateMask = prototype.m_stateMask;
+        m_nullObject = prototype.m_nullObject;
+        m_bundleInstance = prototype.m_bundleInstance;
+        m_filter = prototype.m_filter;
+        m_bundleId = prototype.m_bundleId;
+        m_propagate = prototype.m_propagate;
+        m_callbackInstance = prototype.m_callbackInstance;
+        m_callbackAdded = prototype.m_callbackAdded;
+        m_callbackChanged = prototype.m_callbackChanged;
+        m_callbackRemoved = prototype.m_callbackRemoved;
+        m_autoConfigInstance = prototype.m_autoConfigInstance;
+    }
+    
+    public Dependency createCopy() {
+        return new BundleDependencyImpl(this);
+    }
 
     public BundleDependency setInstanceBound(boolean isInstanceBound) {
         setIsInstanceBound(isInstanceBound);
@@ -104,23 +126,26 @@ public class BundleDependencyImpl extend
 
 	public String getName() {
         StringBuilder sb = new StringBuilder();
-        if (m_bundleInstance != null) {
-            sb.append(m_bundleInstance.getSymbolicName());
-            sb.append(' ');
-            sb.append(m_bundleInstance.getHeaders().get("Bundle-Version"));
-            sb.append(' ');
+        if ((m_stateMask & Bundle.ACTIVE) != 0) {
+            sb.append("active ");
+        }
+        if ((m_stateMask & Bundle.INSTALLED) != 0) {
+            sb.append("installed ");
+        }
+        if ((m_stateMask & Bundle.RESOLVED) != 0) {
+            sb.append("resolved ");
         }
-        sb.append(Integer.toString(m_stateMask, 2));
         if (m_filter != null) {
-            sb.append(' ');
             sb.append(m_filter.toString());
         }
+        if (m_bundleId != -1) {
+            sb.append("bundle.id=" + m_bundleId);
+        }
         return sb.toString();
 	}
 
 	public int getState() {
-		// TODO Auto-generated method stub
-		return 0;
+        return (isAvailable() ? 1 : 0) + (isRequired() ? 2 : 0);
 	}
 
 	public String getType() {

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java
Thu Jul  1 12:23:51 2010
@@ -27,6 +27,7 @@ import java.util.Properties;
 import java.util.Set;
 
 import org.apache.felix.dm.dependencies.ConfigurationDependency;
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.dependencies.PropertyMetaData;
 import org.apache.felix.dm.impl.InvocationUtil;
 import org.apache.felix.dm.impl.Logger;
@@ -75,6 +76,18 @@ public class ConfigurationDependencyImpl
 		m_context = context;
 	}
 	
+	public ConfigurationDependencyImpl(ConfigurationDependencyImpl prototype) {
+	    super(prototype);
+	    m_context = prototype.m_context;
+	    m_pid = prototype.m_pid;
+	    m_propagate = prototype.m_propagate;
+	    m_callback = prototype.m_callback;
+	}
+	
+	public Dependency createCopy() {
+	    return new ConfigurationDependencyImpl(this);
+	}
+	
 	public synchronized boolean isAvailable() {
 		return m_settings != null;
 	}

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyBase.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyBase.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/DependencyBase.java
Thu Jul  1 12:23:51 2010
@@ -11,6 +11,12 @@ public abstract class DependencyBase imp
     public DependencyBase(Logger logger) {
         m_logger = logger;
     }
+    
+    public DependencyBase(DependencyBase prototype) {
+        m_logger = prototype.m_logger;
+        m_isRequired = prototype.isRequired();
+        m_isInstanceBound = prototype.m_isInstanceBound;
+    }
 
     public synchronized boolean isRequired() {
         return m_isRequired;

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
Thu Jul  1 12:23:51 2010
@@ -23,15 +23,17 @@ import java.util.Dictionary;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.dependencies.ResourceDependency;
 import org.apache.felix.dm.impl.Logger;
+import org.apache.felix.dm.management.ServiceComponentDependency;
 import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.resources.ResourceHandler;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
-public class ResourceDependencyImpl extends DependencyBase implements ResourceDependency,
ResourceHandler, DependencyActivation {
+public class ResourceDependencyImpl extends DependencyBase implements ResourceDependency,
ResourceHandler, DependencyActivation, ServiceComponentDependency {
 	private volatile BundleContext m_context;
 	private volatile ServiceRegistration m_registration;
 //	private long m_resourceCounter;
@@ -43,7 +45,6 @@ public class ResourceDependencyImpl exte
     private boolean m_autoConfig;
     private String m_autoConfigInstance;
     protected List m_services = new ArrayList();
-	private boolean m_isRequired;
 	private String m_resourceFilter;
 	private Resource m_trackedResource;
     private boolean m_isStarted;
@@ -57,6 +58,24 @@ public class ResourceDependencyImpl exte
     	m_autoConfig = true;
     }
     
+    public ResourceDependencyImpl(ResourceDependencyImpl prototype) {
+        super(prototype);
+        m_context = prototype.m_context;
+        m_autoConfig = prototype.m_autoConfig;
+        m_callbackInstance = prototype.m_callbackInstance;
+        m_callbackAdded = prototype.m_callbackAdded;
+        m_callbackChanged = prototype.m_callbackChanged;
+        m_callbackRemoved = prototype.m_callbackRemoved;
+        m_autoConfigInstance = prototype.m_autoConfigInstance;
+        m_resourceFilter = prototype.m_resourceFilter;
+        m_trackedResource = prototype.m_trackedResource;
+        m_propagate = prototype.m_propagate;
+    }
+    
+    public Dependency createCopy() {
+        return new ResourceDependencyImpl(this);
+    }
+    
 	public synchronized boolean isAvailable() {
 		return m_resources.size() > 0;
 	}
@@ -433,4 +452,23 @@ public class ResourceDependencyImpl exte
         setIsInstanceBound(isInstanceBound);
         return this;
     }
+
+    public String getName() {
+        StringBuilder sb = new StringBuilder();
+        if (m_resourceFilter != null) {
+            sb.append(m_resourceFilter);
+        }
+        if (m_trackedResource != null) {
+            sb.append(m_trackedResource.getID());
+        }
+        return sb.toString();
+    }
+
+    public int getState() {
+        return (isAvailable() ? 1 : 0) + (isRequired() ? 2 : 0);
+    }
+
+    public String getType() {
+        return "resource";
+    }
 }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java?rev=959632&r1=959631&r2=959632&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
Thu Jul  1 12:23:51 2010
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.dependencies.ServiceDependency;
 import org.apache.felix.dm.impl.DefaultNullObject;
 import org.apache.felix.dm.impl.Logger;
@@ -179,6 +180,28 @@ public class ServiceDependencyImpl exten
         m_autoConfig = true;
     }
     
+    /** Copying constructor that clones an existing instance. */
+    public ServiceDependencyImpl(ServiceDependencyImpl prototype) {
+        super(prototype);
+        m_context = prototype.m_context;
+        m_autoConfig = prototype.m_autoConfig;
+        m_trackedServiceName = prototype.m_trackedServiceName;
+        m_nullObject = prototype.m_nullObject;
+        m_trackedServiceFilter = prototype.m_trackedServiceFilter;
+        m_trackedServiceFilterUnmodified = prototype.m_trackedServiceFilterUnmodified;
+        m_trackedServiceReference = prototype.m_trackedServiceReference;
+        m_callbackInstance = prototype.m_callbackInstance;
+        m_callbackAdded = prototype.m_callbackAdded;
+        m_callbackChanged = prototype.m_callbackChanged;
+        m_callbackRemoved = prototype.m_callbackRemoved;
+        m_autoConfigInstance = prototype.m_autoConfigInstance;
+        m_defaultImplementation = prototype.m_defaultImplementation;
+    }
+    
+    public Dependency createCopy() {
+        return new ServiceDependencyImpl(this);
+    }
+    
     public synchronized boolean isAutoConfig() {
         return m_autoConfig;
     }
@@ -244,7 +267,7 @@ public class ServiceDependencyImpl exten
         }
         return service;
     }
-    
+
     // TODO lots of duplication in lookupService()
     public ServiceReference lookupServiceReference() {
         ServiceReference service = null;
@@ -348,6 +371,7 @@ public class ServiceDependencyImpl exten
                 m_isStarted = true;
                 needsStarting = true;
             }
+            else { System.out.println("ALREADY STARTED..."); } // TODO REMOVE, FOR DEBUGGING
         }
         if (needsStarting) {
             m_tracker.open();
@@ -736,10 +760,15 @@ public class ServiceDependencyImpl exten
 
     public String getName() {
         StringBuilder sb = new StringBuilder();
-        sb.append(m_trackedServiceName.getName());
-        if (m_trackedServiceFilterUnmodified != null) {
-            sb.append(' ');
-            sb.append(m_trackedServiceFilterUnmodified);
+        if (m_trackedServiceName != null) {
+            sb.append(m_trackedServiceName.getName());
+            if (m_trackedServiceFilterUnmodified != null) {
+                sb.append(' ');
+                sb.append(m_trackedServiceFilterUnmodified);
+            }
+        }
+        if (m_trackedServiceReference != null) {
+            sb.append("service.id=" + m_trackedServiceReference.getProperty(Constants.SERVICE_ID));
         }
         return sb.toString();
     }



Mime
View raw message