You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2012/01/04 08:18:34 UTC

svn commit: r1227059 - in /geronimo/server/trunk/framework: buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/ modules/geronimo-kernel/src/main/jav...

Author: djencks
Date: Wed Jan  4 07:18:33 2012
New Revision: 1227059

URL: http://svn.apache.org/viewvc?rev=1227059&view=rev
Log:
GERONIMO-6249 use extender pattern (in DependencyManager) instead of ConfigurationActivator

Removed:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/ConfigurationActivator.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/KernelActivator.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/osgi/BootActivator.java
Modified:
    geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java
    geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java

Modified: geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java?rev=1227059&r1=1227058&r2=1227059&view=diff
==============================================================================
--- geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java (original)
+++ geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java Wed Jan  4 07:18:33 2012
@@ -29,7 +29,6 @@ import java.util.Map;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 
-import org.apache.geronimo.kernel.osgi.ConfigurationActivator;
 import org.apache.maven.archiver.MavenArchiveConfiguration;
 import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.artifact.Artifact;
@@ -287,12 +286,6 @@ public class ArchiveCarMojo
                     ZipEntry importTxtEntry = includedJarFile.getEntry("META-INF/imports.txt");
                     if (importTxtEntry != null) {
                         StringBuilder imports = new StringBuilder("org.apache.geronimo.kernel.osgi,");
-//                        if (boot) {
-//                            archive.addManifestEntry(Constants.BUNDLE_ACTIVATOR, BootActivator.class.getName());
-//                            imports.append("org.apache.geronimo.system.osgi,");
-//                        } else {
-                            archive.addManifestEntry(Constants.BUNDLE_ACTIVATOR, ConfigurationActivator.class.getName());
-//                        }
                         archive.addManifestEntry(Constants.BUNDLE_NAME, project.getName());
                         archive.addManifestEntry(Constants.BUNDLE_VENDOR, project.getOrganization().getName());
                         ArtifactVersion version = project.getArtifact().getSelectedVersion();

Modified: geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java?rev=1227059&r1=1227058&r2=1227059&view=diff
==============================================================================
--- geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java (original)
+++ geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java Wed Jan  4 07:18:33 2012
@@ -177,9 +177,6 @@ public class PlanProcessorMojo
         Environment newEnvironment = new Environment();
         newEnvironment.setConfigId(configId);
         newEnvironment.setDependencies(dependencies);
-//        if (boot) {
-//            newEnvironment.setBundleActivator(BootActivator.class.getName());
-//        }
 
         EnvironmentBuilder.mergeEnvironments(oldEnvironment, newEnvironment);
         EnvironmentType environmentType = EnvironmentBuilder.buildEnvironmentType(oldEnvironment);

Modified: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java?rev=1227059&r1=1227058&r2=1227059&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java Wed Jan  4 07:18:33 2012
@@ -41,7 +41,6 @@ import java.util.zip.ZipFile;
 
 import javax.xml.bind.JAXBException;
 import javax.xml.stream.XMLStreamException;
-
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.common.IllegalConfigurationException;
 import org.apache.geronimo.deployment.util.osgi.DummyExportPackagesSelector;
@@ -63,7 +62,6 @@ import org.apache.geronimo.kernel.config
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
 import org.apache.geronimo.kernel.config.Manifest;
 import org.apache.geronimo.kernel.config.ManifestException;
-import org.apache.geronimo.kernel.osgi.ConfigurationActivator;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Dependency;
 import org.apache.geronimo.kernel.repository.Environment;
@@ -552,11 +550,7 @@ public class DeploymentContext {
 
         // TODO OSGI figure out exports
         environment.addToBundleClassPath(bundleClassPath);
-        // TODO OSGI leave out if we use a extender mechanism
-        if (environment.getBundleActivator() == null) {
-            environment.setBundleActivator(ConfigurationActivator.class.getName());
-            environment.addImportPackage(getImportPackageName(ConfigurationActivator.class.getName()));
-        }
+
         List<GBeanData> gbeans = new ArrayList<GBeanData>(configuration.getGBeans().values());
         Collections.sort(gbeans, new GBeanData.PriorityComparator());
 
@@ -570,7 +564,9 @@ public class DeploymentContext {
             }
         } else {
             LinkedHashSet<String> imports = getImports(gbeans);
-            addImport(imports, environment.getBundleActivator());
+            if (environment.getBundleActivator() != null) {
+                addImport(imports, environment.getBundleActivator());
+            }
             environment.addImportPackages(imports);
             environment.addDynamicImportPackage("*");
             osgiMetaDataBuilder = new OSGiMetaDataBuilder(bundleContext, new DummyExportPackagesSelector());

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java?rev=1227059&r1=1227058&r2=1227059&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java Wed Jan  4 07:18:33 2012
@@ -380,7 +380,7 @@ public class SimpleConfigurationManager 
                 bundle.start(Bundle.START_TRANSIENT);
                 if (bundle.getState() != 32) {
 //                    throw new IllegalStateException("Cant start bundle " + configurationId);
-                    bundle.start();   //should throw an exception if bundle won't start. start triggers ConfigurationActivator which does most of the load work.
+                    bundle.start();   //should throw an exception if bundle won't start. start triggers loading in DependencyManager.
                 }
             }
             bundles.put(configurationId, bundle);

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java?rev=1227059&r1=1227058&r2=1227059&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java Wed Jan  4 07:18:33 2012
@@ -44,6 +44,14 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.ConfigurationData;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.repository.AbstractRepository;
@@ -104,6 +112,13 @@ public class DependencyManager {
 
     private final Map<Long, Artifact> bundleIdArtifactMap = new ConcurrentHashMap<Long, Artifact>();
 
+    //configuration activator
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private Kernel kernel;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private ConfigurationManager configurationManager;
+
     private RecursiveBundleTracker bt;
 
     //used in tests
@@ -146,6 +161,26 @@ public class DependencyManager {
         repositories.remove(repository);
     }
 
+    public void setKernel(Kernel kernel) {
+        this.kernel = kernel;
+    }
+
+    public void unsetKernel(Kernel kernel) {
+        if (this.kernel == kernel) {
+            this.kernel = null;
+        }
+    }
+
+    public void setConfigurationManager(ConfigurationManager configurationManager) {
+        this.configurationManager = configurationManager;
+    }
+
+    public void unsetConfigurationManager(ConfigurationManager configurationManager) {
+        if (this.configurationManager == configurationManager) {
+            this.configurationManager = null;
+        }
+    }
+
 
     @Activate
     public void doStart(BundleContext bundleContext) throws Exception {
@@ -157,6 +192,7 @@ public class DependencyManager {
                 if (bundleEvent == null) {
                     // existing bundles first added to the tracker with no event change
                     installed(bundle);
+                    start(bundle);
                 } else {
                     bundleChanged(bundleEvent);
                 }
@@ -206,6 +242,9 @@ public class DependencyManager {
             installed(bundleEvent.getBundle());
         } else if (eventType == BundleEvent.STARTING) {
             starting(bundleEvent.getBundle());
+            start(bundleEvent.getBundle());
+        } else if (eventType == BundleEvent.STOPPING) {
+            stop(bundleEvent.getBundle());
         } else if (eventType == BundleEvent.UNINSTALLED) {
             uninstall(bundleEvent.getBundle());
         }
@@ -653,4 +692,61 @@ public class DependencyManager {
 //        throw new NoSuchConfigException(configurationId);
     }
 
+    //Activator replacement
+
+    public void start(Bundle bundle) {
+        InputStream in = null;
+        try {
+            in = bundle.getEntry("META-INF/config.ser").openStream();
+            //TODO there are additional consistency checks in RepositoryConfigurationStore that we should use.
+            ConfigurationData data = ConfigurationUtil.readConfigurationData(in);
+            data.setBundleContext(bundle.getBundleContext());
+            configurationManager.loadConfiguration(data);
+//            Artifact id = data.getId();
+            //            manager.startConfiguration(id);
+        } catch (Exception e) {
+            log.warn("Exception trying to load configuration bundle " + bundle, e);
+//            throw e;
+        } finally {
+            if (in != null)
+                try {
+                    in.close();
+                } catch (Exception e) {
+                }
+        }
+    }
+
+    public void stop(Bundle bundle) {
+        try {
+            Artifact id = bundleIdArtifactMap.get(bundle.getBundleId());
+            if (id == null) {
+                return;
+            }
+            AbstractName name = Configuration.getConfigurationAbstractName(id);
+            //TODO investigate how this is called and whether just stopping/unloading the configuration gbean will
+            //leave the configuration model in a consistent state.  We might need a shutdown flag set elsewhere to avoid
+            //overwriting the load attribute in config.xml. This code mimics the shutdown hook in KernelConfigurationManager
+            //see https://issues.apache.org/jira/browse/GERONIMO-4909
+            try {
+                kernel.stopGBean(name);
+            } catch (GBeanNotFoundException e) {
+            } catch (InternalKernelException e) {
+            } catch (IllegalStateException e) {
+            }
+            try {
+                kernel.unloadGBean(name);
+            } catch (GBeanNotFoundException e) {
+            } catch (InternalKernelException e) {
+            } catch (IllegalStateException e) {
+            }
+            //TODO this code is more symmetrical with start, but currently sets the load attribute to false in config.xml,
+            //which prevents restarting the server.
+            //            ConfigurationManager manager = ConfigurationUtil.getConfigurationManager(kernel);
+            //            manager.unloadConfiguration(id);
+        } catch (InvalidConfigException e) {
+            log.warn("cannot stop Configuration for bundle " + bundle.getBundleId());
+        }
+    }
+
+
 }