geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1221390 [3/8] - in /geronimo/server/trunk: ./ framework/buildsupport/car-maven-plugin/ framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ framework/buildsupport/car-maven-plugin/src/main/resources/M...
Date Tue, 20 Dec 2011 18:05:05 GMT
Modified: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java?rev=1221390&r1=1221389&r2=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java Tue Dec 20 18:04:59 2011
@@ -1,654 +1,51 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *  http://www.apache.org/licenses/LICENSE-2.0
  *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 
+
 package org.apache.geronimo.deployment;
 
 import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
-import javax.management.ObjectName;
 
 import org.apache.geronimo.common.DeploymentException;
-import org.apache.geronimo.gbean.AbstractName;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.gbean.GBeanLifecycle;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
-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.ConfigurationStore;
-import org.apache.geronimo.kernel.config.ConfigurationUtil;
-import org.apache.geronimo.kernel.config.DeploymentWatcher;
-import org.apache.geronimo.kernel.config.InvalidConfigException;
-import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
-import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.repository.ArtifactResolver;
-import org.apache.geronimo.kernel.util.FileUtils;
-import org.apache.geronimo.kernel.util.JarUtils;
-import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
-import org.apache.geronimo.system.main.CommandLineManifest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
- * GBean that knows how to deploy modules (by consulting available module builders)
- *
- * @version $Rev$ $Date$
+ * @version $Rev:$ $Date:$
  */
-public class Deployer implements GBeanLifecycle {
-    private static final Logger log = LoggerFactory.getLogger(Deployer.class);
-
-    private final int REAPER_INTERVAL = 60 * 1000;
-    public static final String CLEAN_UP_ON_START_KEY = "org.apache.geronimo.deployer.cleanupOnStart";
-    private final boolean CLEAN_UP_ON_START = System.getProperty(CLEAN_UP_ON_START_KEY) == null ? true : Boolean.getBoolean(CLEAN_UP_ON_START_KEY);
-    private DeployerReaper reaper;
-    private final String remoteDeployAddress;
-    private final Collection builders;
-    private final Collection stores;
-    private final Collection watchers;
-    private final ArtifactResolver artifactResolver;
-    private final Kernel kernel;
-    private static final URI PLAN_LOCATION = URI.create("META-INF/plan.xml");
-
-    public Deployer(String remoteDeployAddress, Collection builders, Collection stores, Collection watchers, Kernel kernel) throws GBeanNotFoundException {
-        this(remoteDeployAddress, builders, stores, watchers, getArtifactResolver(kernel), kernel);
-    }
-
-    private static ArtifactResolver getArtifactResolver(Kernel kernel) throws GBeanNotFoundException {
-        ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
-        return configurationManager.getArtifactResolver();
-    }
-
-    public Deployer(String remoteDeployAddress, Collection builders, Collection stores, Collection watchers, ArtifactResolver artifactResolver, Kernel kernel) {
-        this.remoteDeployAddress = remoteDeployAddress;
-        this.builders = builders;
-        this.stores = stores;
-        this.watchers = watchers;
-        this.artifactResolver = artifactResolver;
-        this.kernel = kernel;
-
-        // Create and start the reaper...
-        this.reaper = new DeployerReaper(REAPER_INTERVAL);
-
-    }
-
-    public List deploy(boolean inPlace, File moduleFile, File planFile) throws DeploymentException {
-        return deploy(inPlace, moduleFile, planFile, null);
-    }
-
-    public List deploy(boolean inPlace, File moduleFile, File planFile, String targetConfigStore) throws DeploymentException {
-        File originalModuleFile = moduleFile;
-        File tmpDir = null;
-        if (moduleFile != null && !moduleFile.isDirectory()) {
-            // todo jar url handling with Sun's VM on Windows leaves a lock on the module file preventing rebuilds
-            // to address this we use a gross hack and copy the file to a temporary directory
-            // the lock on the file will prevent that being deleted properly until the URLJarFile has
-            // been GC'ed.
-            boolean cleanup = true;
-            try {
-                tmpDir = File.createTempFile("geronimo-deployer", ".tmpdir");
-                tmpDir.delete();
-                tmpDir.mkdir();
-                File tmpFile = new File(tmpDir, moduleFile.getName());
-                FileUtils.copyFile(moduleFile, tmpFile);
-                moduleFile = tmpFile;
-                cleanup = false;
-            } catch (IOException e) {
-                throw new DeploymentException(e);
-            } finally {
-                // If an Exception is thrown in the try block above, we will need to cleanup here.
-                if(cleanup && tmpDir != null && !FileUtils.recursiveDelete(tmpDir)) {
-                    reaper.delete(tmpDir.getAbsolutePath(), "delete");
-                }
-            }
-        }
-
-        try {
-            return deploy(inPlace, moduleFile, planFile, null, true, null, null, null, null, null, null, null, targetConfigStore);
-        } catch (DeploymentException e) {
-            log.debug("Deployment failed: plan=" + planFile + ", module=" + originalModuleFile, e);
-            throw e.cleanse();
-        } finally {
-            if (tmpDir != null) {
-                if (!FileUtils.recursiveDelete(tmpDir)) {
-                    reaper.delete(tmpDir.getAbsolutePath(), "delete");
-                }
-            }
-        }
-    }
-
-    /**
-     * Gets a URL that a remote deploy client can use to upload files to the
-     * server. Looks up a remote deploy web application by searching for a
-     * particular GBean and figuring out a reference to the web application
-     * based on that.  Then constructs a URL pointing to that web application
-     * based on available connectors for the web container and the context
-     * root for the web application.
-     *
-     * @return The URL that clients should use for deployment file uploads.
-     */
-    public String getRemoteDeployUploadURL() {
-        // Get the token GBean from the remote deployment configuration
-        Set set = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.deployment.remote.RemoteDeployToken"));
-        if (set.size() == 0) {
-            return null;
-        }
-        AbstractName token = (AbstractName) set.iterator().next();
-        // Identify the parent configuration for that GBean
-        set = kernel.getDependencyManager().getParents(token);
-        ObjectName config = null;
-        for (Iterator it = set.iterator(); it.hasNext();) {
-            AbstractName name = (AbstractName) it.next();
-            if (Configuration.isConfigurationObjectName(name.getObjectName())) {
-                config = name.getObjectName();
-                break;
-            }
-        }
-        if (config == null) {
-            log.warn("Unable to find remote deployment configuration; is the remote deploy web application running?");
-            return null;
-        }
-        // Generate the URL based on the remote deployment configuration
-        Map<String, String> hash = new HashMap<String, String>();
-        hash.put("J2EEApplication", token.getObjectName().getKeyProperty("J2EEApplication"));
-        hash.put("j2eeType", "WebModule");
-        try {
-            hash.put("name", Configuration.getConfigurationID(config).toString());
-            Set<AbstractName> names = kernel.listGBeans(new AbstractNameQuery(null, hash));
-            if (names.size() != 1) {
-                log.error("Unable to look up remote deploy upload URL");
-                return null;
-            }
-            AbstractName module = names.iterator().next();
-            String contextPath = (String) kernel.getAttribute(module, "contextPath");
-            if (null == contextPath) {
-                throw new IllegalStateException("Cannot find contextPath attribute for [" + module + "]");
-            }
-            String temp = remoteDeployAddress + "/" + contextPath + "/upload";
-            return URI.create(temp).normalize().toString();
-        } catch (Exception e) {
-            log.error("Unable to look up remote deploy upload URL", e);
-            return null;
-        }
-    }
-
-    public List deploy(boolean inPlace,
-            File moduleFile,
-            File planFile,
-            File targetFile,
-            boolean install,
-            String mainClass,
-            String mainGBean, String mainMethod, String manifestConfigurations, String classPath,
-            String endorsedDirs,
-            String extensionDirs,
-            String targetConfigurationStore) throws DeploymentException {
-        if (planFile == null && moduleFile == null) {
-            throw new DeploymentException("No plan or module specified");
-        } else if (stores.isEmpty()) {
-            throw new DeploymentException("No ConfigurationStores!");
-        }
-        validatePlanFile(planFile);
-
-        JarFile module = getModule(inPlace, moduleFile);
-
-        ModuleIDBuilder idBuilder = new ModuleIDBuilder();
-
-        DeploymentContext context = null;
-        try {
-            FileUtils.beginRecordTempFiles();
-            Object plan = null;
-            ConfigurationBuilder builder = null;
-            for (Iterator i = builders.iterator(); i.hasNext();) {
-                ConfigurationBuilder candidate = (ConfigurationBuilder) i.next();
-                plan = candidate.getDeploymentPlan(planFile, module, idBuilder);
-                if (plan != null) {
-                    builder = candidate;
-                    break;
-                }
-            }
-            if (builder == null) {
-                throw new DeploymentException("Cannot deploy the requested application module because no deployer is able to handle it. " +
-                        " This can happen if you have omitted the J2EE deployment descriptor, disabled a deployer module, or if, for example, you are trying to deploy an" +
-                        " EJB module on a minimal Geronimo server that does not have EJB support installed.  (" +
-                        (planFile == null ? "" : "planFile=" + planFile.getAbsolutePath()) +
-                        (moduleFile == null ? "" : (planFile == null ? "" : ", ") + "moduleFile=" + moduleFile.getAbsolutePath()) + ")");
-            }
-
-            Artifact configID = getConfigID(module, idBuilder, plan, builder);
-
-            ConfigurationStore store = getConfigurationStore(targetConfigurationStore);
-
-            // It's our responsibility to close this context, once we're done with it...
-            context = builder.buildConfiguration(inPlace, configID, plan, module, stores, artifactResolver, store);
-            // Copy the external plan to the META-INF folder with the uniform name plan.xml if there is nothing there already
-            if (planFile != null && !context.getTargetFile(PLAN_LOCATION).exists()) {
-                context.addFile(PLAN_LOCATION, planFile);
-            }
-            // install the configuration
-            // create the manifest
-            Manifest manifest = createManifest(mainClass,
-                mainGBean,
-                mainMethod,
-                manifestConfigurations,
-                classPath,
-                endorsedDirs,
-                extensionDirs);
-
-            return install(targetFile, install, manifest, store, context);
-        } catch (Throwable e) {
-            if (e instanceof Error) {
-                log.error("Deployment failed due to ", e);
-                throw (Error) e;
-            } else if (e instanceof DeploymentException) {
-                throw (DeploymentException) e;
-            } else if (e instanceof Exception) {
-                log.error("Deployment failed due to ", e);
-                throw new DeploymentException(e);
-            }
-            throw new Error(e);
-        } finally {
-            JarUtils.close(module);            
-            if (context != null) {               
-                try {
-                    context.close();
-                } catch (Exception e) {
-                }                
-            }
-            List<File> tempFiles = FileUtils.endRecordTempFiles();
-            if (tempFiles != null) {
-                cleanUpTemporaryDirectories(tempFiles);
-            }
-        }
-    }
-
-    private ConfigurationStore getConfigurationStore(String targetConfigurationStore)
-            throws URISyntaxException, GBeanNotFoundException {
-        if (targetConfigurationStore != null) {
-            AbstractName targetStoreName = new AbstractName(new URI(targetConfigurationStore));
-            return (ConfigurationStore) kernel.getGBean(targetStoreName);
-        } else {
-            return (ConfigurationStore) stores.iterator().next();
-        }
-    }
-
-    private Artifact getConfigID(JarFile module,
-            ModuleIDBuilder idBuilder,
-            Object plan,
-            ConfigurationBuilder builder) throws IOException, DeploymentException, InvalidConfigException {
-        Artifact configID = builder.getConfigurationID(plan, module, idBuilder);
-        // If the Config ID isn't fully resolved, populate it with defaults
-        if (!configID.isResolved()) {
-            configID = idBuilder.resolve(configID, "car");
-        }
-
-        // Make sure this configuration doesn't already exist
-        try {
-            kernel.getGBeanState(Configuration.getConfigurationAbstractName(configID));
-            throw new DeploymentException("Module " + configID + " already exists in the server.  Try to undeploy it first or use the redeploy command.");
-        } catch (GBeanNotFoundException e) {
-            // this is good
-        }
-        return configID;
-    }
-
-    private List<String> install(File targetFile,
-            boolean install,
-            Manifest manifest,
-            ConfigurationStore store,
-            DeploymentContext context) throws DeploymentException {
-        List<ConfigurationData> configurationDatas = new ArrayList<ConfigurationData>();
-
-        boolean configsCleanupRequired = false;
-
-        // Set TCCL to the classloader for the configuration being deployed
-        // so that any static blocks invoked during the loading of classes
-        // during serialization of the configuration have the correct TCCL
-        // ( a TCCL that is consistent with what is set when the same
-        // classes are loaded when the configuration is started.
-        Thread thread = Thread.currentThread();
-        ClassLoader oldCl = thread.getContextClassLoader();
-        //TODO OSGI fixme
-        thread.setContextClassLoader(new BundleClassLoader(context.getConfiguration().getBundle()));
-        try {
-            try {
-                configurationDatas.add(context.getConfigurationData());
-            } catch (DeploymentException e) {
-                Configuration configuration = context.getConfiguration();
-                if (configuration != null) {
-                    ConfigurationData dumbConfigurationData = new ConfigurationData(null, null, null,
-                            configuration.getEnvironment(), context.getBaseDir(), null, context.getNaming());
-                    configurationDatas.add(dumbConfigurationData);
-                }
-                configurationDatas.addAll(context.getAdditionalDeployment());
-                throw e;
-            }
-
-            configurationDatas.addAll(context.getAdditionalDeployment());
-
-            if (configurationDatas.isEmpty()) {
-                throw new DeploymentException("Deployer did not create any configurations");
-            }
-
-            if (targetFile != null) {
-                if (configurationDatas.size() > 1) {
-                    throw new DeploymentException("Deployer created more than one configuration");
-                }
-                ConfigurationData configurationData = configurationDatas.get(0);
-                ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, manifest, targetFile);
-            }
-            if (install) {
-                List<String> deployedURIs = new ArrayList<String>();
-                for (ConfigurationData configurationData : configurationDatas) {
-                    store.install(configurationData);
-                    deployedURIs.add(configurationData.getId().toString());
-                }
-                notifyWatchers(deployedURIs);
-                return deployedURIs;
-            } else {
-                configsCleanupRequired = true;
-                return Collections.<String>emptyList();
-            }
-        } catch (DeploymentException e) {
-            configsCleanupRequired = true;
-            throw e;
-        } catch (Throwable e) {
-            // Could get here if serialization of the configuration failed (GERONIMO-1996)
-            configsCleanupRequired = true;
-            throw new DeploymentException(e);
-        } finally {
-            thread.setContextClassLoader(oldCl);
-            if (configsCleanupRequired) {
-                // We do this after context is closed so the module jar isn't open
-                cleanupConfigurations(configurationDatas);
-            }
-        }
-    }
-
-    private Manifest createManifest(String mainClass,
-            String mainGBean,
-            String mainMethod,
-            String manifestConfigurations,
-            String classPath,
-            String endorsedDirs,
-            String extensionDirs) {
-        if (mainClass == null) {
-            return null;
-        }
-        Manifest manifest = new Manifest();
-        Attributes mainAttributes = manifest.getMainAttributes();
-        mainAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
-        if (mainClass != null) {
-            mainAttributes.putValue(Attributes.Name.MAIN_CLASS.toString(), mainClass);
-        }
-        if (mainGBean != null) {
-            mainAttributes.putValue(CommandLineManifest.MAIN_GBEAN.toString(), mainGBean);
-        }
-        if (mainMethod != null) {
-            mainAttributes.putValue(CommandLineManifest.MAIN_METHOD.toString(), mainMethod);
-        }
-        if (manifestConfigurations != null) {
-            mainAttributes.putValue(CommandLineManifest.CONFIGURATIONS.toString(), manifestConfigurations);
-        }
-        if (classPath != null) {
-            mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(), classPath);
-        }
-        if (endorsedDirs != null) {
-            mainAttributes.putValue(CommandLineManifest.ENDORSED_DIRS.toString(), endorsedDirs);
-        }
-        if (extensionDirs != null) {
-            mainAttributes.putValue(CommandLineManifest.EXTENSION_DIRS.toString(), extensionDirs);
-        }
-        return manifest;
-    }
-
-    private JarFile getModule(boolean inPlace, File moduleFile) throws DeploymentException {
-        JarFile module = null;
-        if (moduleFile != null) {
-            if (inPlace && !moduleFile.isDirectory()) {
-                throw new DeploymentException("In place deployment is not allowed for packed module");
-            }
-            if (!moduleFile.exists()) {
-                throw new DeploymentException("Module file does not exist: " + moduleFile.getAbsolutePath());
-            }
-            try {
-                module = JarUtils.createJarFile(moduleFile);
-            } catch (IOException e) {
-                throw new DeploymentException("Cound not open module file: " + moduleFile.getAbsolutePath(), e);
-            }
-        }
-        return module;
-    }
-
-    private void validatePlanFile(File planFile) throws DeploymentException {
-        if (planFile != null) {
-            if (!planFile.exists()) {
-                throw new DeploymentException("Plan file does not exist: " + planFile.getAbsolutePath());
-            }
-            if (!planFile.isFile()) {
-                throw new DeploymentException("Plan file is not a regular file: " + planFile.getAbsolutePath());
-            }
-        }
-    }
-
-    private void cleanUpTemporaryDirectories(List<File> temporaryDirectories) {
-        for (File temporaryDirectory : temporaryDirectories) {
-            reaper.delete(temporaryDirectory.getAbsolutePath(), "delete");
-        }
-    }
-
-    private void notifyWatchers(List list) {
-        Artifact[] arts = new Artifact[list.size()];
-        for (int i = 0; i < list.size(); i++) {
-            String s = (String) list.get(i);
-            arts[i] = Artifact.create(s);
-        }
-        for (Iterator it = watchers.iterator(); it.hasNext();) {
-            DeploymentWatcher watcher = (DeploymentWatcher) it.next();
-            for (int i = 0; i < arts.length; i++) {
-                Artifact art = arts[i];
-                watcher.deployed(art);
-            }
-        }
-    }
-
-    private void cleanupConfigurations(List<ConfigurationData> configurations) {
-        for (ConfigurationData configurationData : configurations) {
-            File configurationDir = configurationData.getConfigurationDir();
-            if (!FileUtils.recursiveDelete(configurationDir)) {
-                reaper.delete(configurationDir.getAbsolutePath(), "delete");
-            }
-        }
-    }
-
-    public void doStart() throws Exception {
-    }
-
-    public void doFail() {
-        try {
-            doStop();
-        } catch (Exception e) {
-        }
-    }
-
-    public void doStop() throws Exception {
-        if (reaper != null) {
-            reaper.close();
-        }
-    }
-
-    /**
-     * Thread to cleanup unused temporary Deployer directories (and files).
-     * On Windows, open files can't be deleted. Until MultiParentClassLoaders
-     * are GC'ed, we won't be able to delete Config Store directories/files.
-     */
-    class DeployerReaper implements Runnable {
-        private final int reaperInterval;
-        private final Properties pendingDeletionIndex = new Properties();
-        private volatile boolean done = false;
-        private Thread thread;
-
-        public DeployerReaper(int reaperInterval) {
-            this.reaperInterval = reaperInterval;
-            this.thread = new Thread(this, "Geronimo Config Store Reaper");
-            this.thread.setDaemon(true);
-            this.thread.start();
-        }
-
-        public void delete(String dir, String type) {
-            pendingDeletionIndex.setProperty(dir, type);
-            if (log.isDebugEnabled()) {
-                log.debug("Queued deployment directory to be reaped " + dir);
-            }
-        }
-
-        public void close() {
-            this.done = true;
-        }
-
-        public void run() {
-            log.debug("ConfigStoreReaper started");
-
-            // DeployerReaper in offline deployment does not get a chance to reap the temporary
-            // directories. Reap any temporary directories left behind by previous runs here.
-            reapBacklog();
-
-            while (!done) {
-                try {
-                    Thread.sleep(reaperInterval);
-                } catch (InterruptedException e) {
-                    continue;
-                }
-                reap();
-            }
-        }
-
-        /**
-         * Reap any temporary directories left behind by previous runs.
-         */
-        private void reapBacklog() {
-            if (!CLEAN_UP_ON_START) {
-                return;
-            }
-            try {
-                File tempFile = File.createTempFile("geronimo-deployer", ".tmpdir");
-                File tempDir = tempFile.getParentFile();
-                tempFile.delete();
-                String[] backlog = tempDir.list(new FilenameFilter(){
-                    public boolean accept(File dir, String name) {
-                        return name.startsWith("geronimo-deployer") && name.endsWith(".tmpdir") && new File(dir, name).isDirectory();
-                    }});
-                for(String dir: backlog) {
-                    File deleteDir = new File(tempDir, dir);
-                    FileUtils.recursiveDelete(deleteDir);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Reaped deployment directory from previous runs " + deleteDir);
-                    }
-                }
-            } catch (IOException ignored) {
-            }
-            try {
-                File tempFile = FileUtils.createTempFile();
-                File tempDir = tempFile.getParentFile();
-                tempFile.delete();
-                String[] backlog = tempDir.list(new FilenameFilter(){
-                    public boolean accept(File dir, String name) {
-                        File file = new File(dir, name);
-                        boolean validTempFile = name.startsWith(FileUtils.DEFAULT_TEMP_PREFIX) && ((file.isDirectory() && name.endsWith(FileUtils.DEFAULT_TEMP_DIRECTORY_SUFFIX)) || file.isFile());
-                        return validTempFile && (file.lastModified() < FileUtils.FILE_UTILS_INITIALIZATION_TIME_MILL);
-                    }});
-                for(String dir: backlog) {
-                    File deleteDir = new File(tempDir, dir);
-                    FileUtils.recursiveDelete(deleteDir);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Reaped deployment directory from previous runs " + deleteDir);
-                    }
-                }
-            } catch (IOException ignored) {
-            }
-        }
-
-        /**
-         * For every directory in the pendingDeletionIndex, attempt to delete all
-         * sub-directories and files.
-         */
-        public void reap() {
-            // return, if there's nothing to do
-            if (pendingDeletionIndex.size() == 0)
-                return;
-            // Otherwise, attempt to delete all of the directories
-            Enumeration list = pendingDeletionIndex.propertyNames();
-            while (list.hasMoreElements()) {
-                String dirName = (String) list.nextElement();
-                File deleteDir = new File(dirName);
-
-                if (FileUtils.recursiveDelete(deleteDir)) {
-                    pendingDeletionIndex.remove(dirName);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Reaped deployment directory " + deleteDir);
-                    }
-                }
-            }
-        }
-    }
-
-    public static final GBeanInfo GBEAN_INFO;
-
-    private static final String DEPLOYER = "Deployer";
-
-    static {
-        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(Deployer.class, DEPLOYER);
-
-        infoFactory.addAttribute("kernel", Kernel.class, false);
-        infoFactory.addAttribute("remoteDeployAddress", String.class, true, true);
-        infoFactory.addAttribute("remoteDeployUploadURL", String.class, false);
-//        infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class});
-//        infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class, String.class});
-//        infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class, File.class, boolean.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class});
-
-        infoFactory.addReference("Builders", ConfigurationBuilder.class, "ConfigBuilder");
-        infoFactory.addReference("Store", ConfigurationStore.class, "ConfigurationStore");
-        infoFactory.addReference("Watchers", DeploymentWatcher.class);
-
-        infoFactory.setConstructor(new String[]{"remoteDeployAddress", "Builders", "Store", "Watchers", "kernel"});
+public interface Deployer {
+    List<String> deploy(boolean inPlace, File moduleFile, File planFile) throws DeploymentException;
 
-        GBEAN_INFO = infoFactory.getBeanInfo();
-    }
+    List<String> deploy(boolean inPlace, File moduleFile, File planFile, String targetConfigStore) throws DeploymentException;
 
-    public static GBeanInfo getGBeanInfo() {
-        return GBEAN_INFO;
-    }
+    String getRemoteDeployUploadURL();
 
+    List<String> deploy(boolean inPlace,
+                File moduleFile,
+                File planFile,
+                File targetFile,
+                boolean install,
+                String mainClass,
+                String mainGBean,
+                String mainMethod,
+                String manifestConfigurations,
+                String classPath,
+                String endorsedDirs,
+                String extensionDirs,
+                String targetConfigurationStore) throws DeploymentException;
 }

Copied: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeployerImpl.java (from r1221389, geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java)
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeployerImpl.java?p2=geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeployerImpl.java&p1=geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java&r1=1221389&r2=1221390&rev=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeployerImpl.java Tue Dec 20 18:04:59 2011
@@ -26,40 +26,36 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
-import javax.management.ObjectName;
-
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.geronimo.common.DeploymentException;
-import org.apache.geronimo.gbean.AbstractName;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
-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.ConfigurationStore;
-import org.apache.geronimo.kernel.config.ConfigurationUtil;
 import org.apache.geronimo.kernel.config.DeploymentWatcher;
 import org.apache.geronimo.kernel.config.InvalidConfigException;
-import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.ArtifactResolver;
 import org.apache.geronimo.kernel.util.FileUtils;
 import org.apache.geronimo.kernel.util.JarUtils;
 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
 import org.apache.geronimo.system.main.CommandLineManifest;
+import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,48 +64,116 @@ import org.slf4j.LoggerFactory;
  *
  * @version $Rev$ $Date$
  */
-public class Deployer implements GBeanLifecycle {
-    private static final Logger log = LoggerFactory.getLogger(Deployer.class);
+@Component(immediate = true, metatype = true)
+@Service
+public class DeployerImpl implements Deployer {
+    private static final Logger log = LoggerFactory.getLogger(DeployerImpl.class);
+    private static final URI PLAN_LOCATION = URI.create("META-INF/plan.xml");
 
     private final int REAPER_INTERVAL = 60 * 1000;
-    public static final String CLEAN_UP_ON_START_KEY = "org.apache.geronimo.deployer.cleanupOnStart";
-    private final boolean CLEAN_UP_ON_START = System.getProperty(CLEAN_UP_ON_START_KEY) == null ? true : Boolean.getBoolean(CLEAN_UP_ON_START_KEY);
-    private DeployerReaper reaper;
-    private final String remoteDeployAddress;
-    private final Collection builders;
-    private final Collection stores;
-    private final Collection watchers;
-    private final ArtifactResolver artifactResolver;
-    private final Kernel kernel;
-    private static final URI PLAN_LOCATION = URI.create("META-INF/plan.xml");
+    private final DeployerReaper reaper = new DeployerReaper(REAPER_INTERVAL) ;
+
+    @Property(value = "localhost:8080")
+    private static final String REMOTE_DEPLOY_ADDRESS = "remoteDeployAddress";
 
-    public Deployer(String remoteDeployAddress, Collection builders, Collection stores, Collection watchers, Kernel kernel) throws GBeanNotFoundException {
-        this(remoteDeployAddress, builders, stores, watchers, getArtifactResolver(kernel), kernel);
+    private String remoteDeployAddress;
+    
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, referenceInterface = ConfigurationBuilder.class, policy = ReferencePolicy.DYNAMIC)
+    private final Collection<ConfigurationBuilder> configurationBuilders = new ArrayList<ConfigurationBuilder>();
+
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, referenceInterface = ConfigurationStore.class, policy = ReferencePolicy.DYNAMIC)
+    private final Collection<ConfigurationStore> configurationStores = new ArrayList<ConfigurationStore>();
+
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, referenceInterface = DeploymentWatcher.class, policy = ReferencePolicy.DYNAMIC)
+    private final Collection<DeploymentWatcher> deploymentWatchers = new ArrayList<DeploymentWatcher>();
+
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC)
+    private ArtifactResolver artifactResolver;
+//    private final Kernel kernel;
+
+
+//    public Deployer(String remoteDeployAddress, Collection builders, Collection stores, Collection watchers, Kernel kernel) throws GBeanNotFoundException {
+//        this(remoteDeployAddress, builders, stores, watchers, getArtifactResolver(kernel), kernel);
+//    }
+//
+//    private static ArtifactResolver getArtifactResolver(Kernel kernel) throws GBeanNotFoundException {
+//        ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
+//        return configurationManager.getArtifactResolver();
+//    }
+//
+//    public Deployer(String remoteDeployAddress, Collection builders, Collection stores, Collection watchers, ArtifactResolver artifactResolver, Kernel kernel) {
+//        this.remoteDeployAddress = remoteDeployAddress;
+//        this.builders = builders;
+//        this.stores = stores;
+//        this.watchers = watchers;
+//        this.artifactResolver = artifactResolver;
+////        this.kernel = kernel;
+//
+//        // Create and start the reaper...
+//        this.reaper = new DeployerReaper(REAPER_INTERVAL);
+//
+//    }
+
+    public DeployerImpl() {
+    }
+
+    @Activate
+    public void activate(Map context) {
+        String remoteDeployAddress = (String) context.get(REMOTE_DEPLOY_ADDRESS);
+        if (remoteDeployAddress != null) {
+            this.remoteDeployAddress = remoteDeployAddress;
+        }
     }
 
-    private static ArtifactResolver getArtifactResolver(Kernel kernel) throws GBeanNotFoundException {
-        ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
-        return configurationManager.getArtifactResolver();
+    @Deactivate
+    public void doStop() throws Exception {
+        reaper.close();
     }
 
-    public Deployer(String remoteDeployAddress, Collection builders, Collection stores, Collection watchers, ArtifactResolver artifactResolver, Kernel kernel) {
-        this.remoteDeployAddress = remoteDeployAddress;
-        this.builders = builders;
-        this.stores = stores;
-        this.watchers = watchers;
+    public void bindConfigurationStore(ConfigurationStore store) {
+        configurationStores.add(store);
+    }
+    
+    public void unbindConfigurationStore(ConfigurationStore store) {
+        configurationStores.remove(store);
+    }
+    
+    public void bindConfigurationBuilder(ConfigurationBuilder builder) {
+        configurationBuilders.add(builder);
+    }
+    
+    public void unbindConfigurationBuilder(ConfigurationBuilder builder) {
+        configurationBuilders.remove(builder);
+    }
+    
+    public void bindDeploymentWatcher(DeploymentWatcher watcher) {
+        deploymentWatchers.add(watcher);
+    }
+    
+    public void unbindDeploymentWatcher(DeploymentWatcher watcher) {
+        deploymentWatchers.remove(watcher);
+    }
+    
+    public void setArtifactResolver(ArtifactResolver artifactResolver) {
         this.artifactResolver = artifactResolver;
-        this.kernel = kernel;
-
-        // Create and start the reaper...
-        this.reaper = new DeployerReaper(REAPER_INTERVAL);
+    }
+    public void unsetArtifactResolver(ArtifactResolver artifactResolver) {
+        if (this.artifactResolver == artifactResolver) {
+            this.artifactResolver = null;
+        }
+    }
 
+    public void setRemoteDeployAddress(String remoteDeployAddress) {
+        this.remoteDeployAddress = remoteDeployAddress;
     }
 
-    public List deploy(boolean inPlace, File moduleFile, File planFile) throws DeploymentException {
+    @Override
+    public List<String> deploy(boolean inPlace, File moduleFile, File planFile) throws DeploymentException {
         return deploy(inPlace, moduleFile, planFile, null);
     }
 
-    public List deploy(boolean inPlace, File moduleFile, File planFile, String targetConfigStore) throws DeploymentException {
+    @Override
+    public List<String> deploy(boolean inPlace, File moduleFile, File planFile, String targetConfigStore) throws DeploymentException {
         File originalModuleFile = moduleFile;
         File tmpDir = null;
         if (moduleFile != null && !moduleFile.isDirectory()) {
@@ -160,64 +224,68 @@ public class Deployer implements GBeanLi
      *
      * @return The URL that clients should use for deployment file uploads.
      */
+    @Override
     public String getRemoteDeployUploadURL() {
         // Get the token GBean from the remote deployment configuration
-        Set set = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.deployment.remote.RemoteDeployToken"));
-        if (set.size() == 0) {
-            return null;
-        }
-        AbstractName token = (AbstractName) set.iterator().next();
-        // Identify the parent configuration for that GBean
-        set = kernel.getDependencyManager().getParents(token);
-        ObjectName config = null;
-        for (Iterator it = set.iterator(); it.hasNext();) {
-            AbstractName name = (AbstractName) it.next();
-            if (Configuration.isConfigurationObjectName(name.getObjectName())) {
-                config = name.getObjectName();
-                break;
-            }
-        }
-        if (config == null) {
-            log.warn("Unable to find remote deployment configuration; is the remote deploy web application running?");
-            return null;
-        }
-        // Generate the URL based on the remote deployment configuration
-        Map<String, String> hash = new HashMap<String, String>();
-        hash.put("J2EEApplication", token.getObjectName().getKeyProperty("J2EEApplication"));
-        hash.put("j2eeType", "WebModule");
-        try {
-            hash.put("name", Configuration.getConfigurationID(config).toString());
-            Set<AbstractName> names = kernel.listGBeans(new AbstractNameQuery(null, hash));
-            if (names.size() != 1) {
-                log.error("Unable to look up remote deploy upload URL");
-                return null;
-            }
-            AbstractName module = names.iterator().next();
-            String contextPath = (String) kernel.getAttribute(module, "contextPath");
-            if (null == contextPath) {
-                throw new IllegalStateException("Cannot find contextPath attribute for [" + module + "]");
-            }
-            String temp = remoteDeployAddress + "/" + contextPath + "/upload";
-            return URI.create(temp).normalize().toString();
-        } catch (Exception e) {
-            log.error("Unable to look up remote deploy upload URL", e);
-            return null;
-        }
-    }
-
-    public List deploy(boolean inPlace,
-            File moduleFile,
-            File planFile,
-            File targetFile,
-            boolean install,
-            String mainClass,
-            String mainGBean, String mainMethod, String manifestConfigurations, String classPath,
-            String endorsedDirs,
-            String extensionDirs,
-            String targetConfigurationStore) throws DeploymentException {
+        //TODO osgi-gbean
+        return null;
+//        Set set = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.deployment.remote.RemoteDeployToken"));
+//        if (set.size() == 0) {
+//            return null;
+//        }
+//        AbstractName token = (AbstractName) set.iterator().next();
+//        // Identify the parent configuration for that GBean
+//        set = kernel.getDependencyManager().getParents(token);
+//        ObjectName config = null;
+//        for (Iterator it = set.iterator(); it.hasNext();) {
+//            AbstractName name = (AbstractName) it.next();
+//            if (Configuration.isConfigurationObjectName(name.getObjectName())) {
+//                config = name.getObjectName();
+//                break;
+//            }
+//        }
+//        if (config == null) {
+//            log.warn("Unable to find remote deployment configuration; is the remote deploy web application running?");
+//            return null;
+//        }
+//        // Generate the URL based on the remote deployment configuration
+//        Map<String, String> hash = new HashMap<String, String>();
+//        hash.put("J2EEApplication", token.getObjectName().getKeyProperty("J2EEApplication"));
+//        hash.put("j2eeType", "WebModule");
+//        try {
+//            hash.put("name", Configuration.getConfigurationID(config).toString());
+//            Set<AbstractName> names = kernel.listGBeans(new AbstractNameQuery(null, hash));
+//            if (names.size() != 1) {
+//                log.error("Unable to look up remote deploy upload URL");
+//                return null;
+//            }
+//            AbstractName module = names.iterator().next();
+//            String contextPath = (String) kernel.getAttribute(module, "contextPath");
+//            if (null == contextPath) {
+//                throw new IllegalStateException("Cannot find contextPath attribute for [" + module + "]");
+//            }
+//            String temp = remoteDeployAddress + "/" + contextPath + "/upload";
+//            return URI.create(temp).normalize().toString();
+//        } catch (Exception e) {
+//            log.error("Unable to look up remote deploy upload URL", e);
+//            return null;
+//        }
+    }
+
+    @Override
+    public List<String> deploy(boolean inPlace,
+                       File moduleFile,
+                       File planFile,
+                       File targetFile,
+                       boolean install,
+                       String mainClass,
+                       String mainGBean, String mainMethod, String manifestConfigurations, String classPath,
+                       String endorsedDirs,
+                       String extensionDirs,
+                       String targetConfigurationStore) throws DeploymentException {
         if (planFile == null && moduleFile == null) {
             throw new DeploymentException("No plan or module specified");
-        } else if (stores.isEmpty()) {
+        } else if (configurationStores.isEmpty()) {
             throw new DeploymentException("No ConfigurationStores!");
         }
         validatePlanFile(planFile);
@@ -228,10 +296,9 @@ public class Deployer implements GBeanLi
 
         DeploymentContext context = null;
         try {
-            FileUtils.beginRecordTempFiles();
             Object plan = null;
             ConfigurationBuilder builder = null;
-            for (Iterator i = builders.iterator(); i.hasNext();) {
+            for (Iterator i = configurationBuilders.iterator(); i.hasNext();) {
                 ConfigurationBuilder candidate = (ConfigurationBuilder) i.next();
                 plan = candidate.getDeploymentPlan(planFile, module, idBuilder);
                 if (plan != null) {
@@ -252,7 +319,7 @@ public class Deployer implements GBeanLi
             ConfigurationStore store = getConfigurationStore(targetConfigurationStore);
 
             // It's our responsibility to close this context, once we're done with it...
-            context = builder.buildConfiguration(inPlace, configID, plan, module, stores, artifactResolver, store);
+            context = builder.buildConfiguration(inPlace, configID, plan, module, configurationStores, artifactResolver, store);
             // Copy the external plan to the META-INF folder with the uniform name plan.xml if there is nothing there already
             if (planFile != null && !context.getTargetFile(PLAN_LOCATION).exists()) {
                 context.addFile(PLAN_LOCATION, planFile);
@@ -269,6 +336,24 @@ public class Deployer implements GBeanLi
 
             return install(targetFile, install, manifest, store, context);
         } catch (Throwable e) {
+            //TODO not clear all errors will result in total cleanup
+//            File configurationDir = configurationData.getConfigurationDir();
+//            if (!DeploymentUtil.recursiveDelete(configurationDir)) {
+//                pendingDeletionIndex.setProperty(configurationDir.getName(), new String("delete"));
+//                log.debug("Queued deployment directory to be reaped " + configurationDir);
+//            }
+//            if (targetFile != null) {
+//                targetFile.delete();
+//            }
+
+            //Clean Up the created deploymentContext, as some initial work might be done in the buildConfiguration invocation
+            if (context != null) {
+                try {
+                    context.close();
+                } catch (Exception ingore) {
+                }
+            }
+
             if (e instanceof Error) {
                 log.error("Deployment failed due to ", e);
                 throw (Error) e;
@@ -280,28 +365,30 @@ public class Deployer implements GBeanLi
             }
             throw new Error(e);
         } finally {
-            JarUtils.close(module);            
-            if (context != null) {               
-                try {
-                    context.close();
-                } catch (Exception e) {
-                }                
-            }
-            List<File> tempFiles = FileUtils.endRecordTempFiles();
-            if (tempFiles != null) {
-                cleanUpTemporaryDirectories(tempFiles);
-            }
+            JarUtils.close(module);
         }
     }
 
     private ConfigurationStore getConfigurationStore(String targetConfigurationStore)
             throws URISyntaxException, GBeanNotFoundException {
-        if (targetConfigurationStore != null) {
-            AbstractName targetStoreName = new AbstractName(new URI(targetConfigurationStore));
-            return (ConfigurationStore) kernel.getGBean(targetStoreName);
-        } else {
-            return (ConfigurationStore) stores.iterator().next();
+//        if (targetConfigurationStore != null) {
+//            AbstractName targetStoreName = new AbstractName(new URI(targetConfigurationStore));
+//            return (ConfigurationStore) kernel.getGBean(targetStoreName);
+//        } else {
+        long timeout = 1000l;
+        while (timeout > 1) {
+            if (!configurationStores.isEmpty()) {
+                break;
+            }
+            try {
+                Thread.sleep(100l);
+            } catch (InterruptedException e) {
+
+            }
+            timeout =- 100l;
         }
+        return configurationStores.iterator().next();
+//        }
     }
 
     private Artifact getConfigID(JarFile module,
@@ -315,12 +402,13 @@ public class Deployer implements GBeanLi
         }
 
         // Make sure this configuration doesn't already exist
-        try {
-            kernel.getGBeanState(Configuration.getConfigurationAbstractName(configID));
-            throw new DeploymentException("Module " + configID + " already exists in the server.  Try to undeploy it first or use the redeploy command.");
-        } catch (GBeanNotFoundException e) {
-            // this is good
-        }
+        //TODO osgi-gbean
+//        try {
+//            kernel.getGBeanState(Configuration.getConfigurationAbstractName(configID));
+//            throw new DeploymentException("Module " + configID + " already exists in the server.  Try to undeploy it first or use the redeploy command.");
+//        } catch (GBeanNotFoundException e) {
+//            // this is good
+//        }
         return configID;
     }
 
@@ -328,7 +416,7 @@ public class Deployer implements GBeanLi
             boolean install,
             Manifest manifest,
             ConfigurationStore store,
-            DeploymentContext context) throws DeploymentException {
+            DeploymentContext context) throws DeploymentException, IOException, Throwable {
         List<ConfigurationData> configurationDatas = new ArrayList<ConfigurationData>();
 
         boolean configsCleanupRequired = false;
@@ -341,7 +429,7 @@ public class Deployer implements GBeanLi
         Thread thread = Thread.currentThread();
         ClassLoader oldCl = thread.getContextClassLoader();
         //TODO OSGI fixme
-        thread.setContextClassLoader(new BundleClassLoader(context.getConfiguration().getBundle()));
+        thread.setContextClassLoader( new BundleClassLoader(context.getConfiguration().getBundle()));
         try {
             try {
                 configurationDatas.add(context.getConfigurationData());
@@ -379,17 +467,25 @@ public class Deployer implements GBeanLi
                 return deployedURIs;
             } else {
                 configsCleanupRequired = true;
-                return Collections.<String>emptyList();
+                return Collections.emptyList();
             }
         } catch (DeploymentException e) {
             configsCleanupRequired = true;
             throw e;
+        } catch (IOException e) {
+            configsCleanupRequired = true;
+            throw e;
+        } catch (InvalidConfigException e) {
+            configsCleanupRequired = true;
+            // unlikely as we just built this
+            throw new DeploymentException(e);
         } catch (Throwable e) {
             // Could get here if serialization of the configuration failed (GERONIMO-1996)
             configsCleanupRequired = true;
-            throw new DeploymentException(e);
+            throw e;
         } finally {
             thread.setContextClassLoader(oldCl);
+            context.close();
             if (configsCleanupRequired) {
                 // We do this after context is closed so the module jar isn't open
                 cleanupConfigurations(configurationDatas);
@@ -463,19 +559,13 @@ public class Deployer implements GBeanLi
         }
     }
 
-    private void cleanUpTemporaryDirectories(List<File> temporaryDirectories) {
-        for (File temporaryDirectory : temporaryDirectories) {
-            reaper.delete(temporaryDirectory.getAbsolutePath(), "delete");
-        }
-    }
-
     private void notifyWatchers(List list) {
         Artifact[] arts = new Artifact[list.size()];
         for (int i = 0; i < list.size(); i++) {
             String s = (String) list.get(i);
             arts[i] = Artifact.create(s);
         }
-        for (Iterator it = watchers.iterator(); it.hasNext();) {
+        for (Iterator it = deploymentWatchers.iterator(); it.hasNext();) {
             DeploymentWatcher watcher = (DeploymentWatcher) it.next();
             for (int i = 0; i < arts.length; i++) {
                 Artifact art = arts[i];
@@ -484,8 +574,9 @@ public class Deployer implements GBeanLi
         }
     }
 
-    private void cleanupConfigurations(List<ConfigurationData> configurations) {
-        for (ConfigurationData configurationData : configurations) {
+    private void cleanupConfigurations(List configurations) {
+        for (Iterator iterator = configurations.iterator(); iterator.hasNext();) {
+            ConfigurationData configurationData = (ConfigurationData) iterator.next();
             File configurationDir = configurationData.getConfigurationDir();
             if (!FileUtils.recursiveDelete(configurationDir)) {
                 reaper.delete(configurationDir.getAbsolutePath(), "delete");
@@ -493,22 +584,6 @@ public class Deployer implements GBeanLi
         }
     }
 
-    public void doStart() throws Exception {
-    }
-
-    public void doFail() {
-        try {
-            doStop();
-        } catch (Exception e) {
-        }
-    }
-
-    public void doStop() throws Exception {
-        if (reaper != null) {
-            reaper.close();
-        }
-    }
-
     /**
      * Thread to cleanup unused temporary Deployer directories (and files).
      * On Windows, open files can't be deleted. Until MultiParentClassLoaders
@@ -522,15 +597,19 @@ public class Deployer implements GBeanLi
 
         public DeployerReaper(int reaperInterval) {
             this.reaperInterval = reaperInterval;
-            this.thread = new Thread(this, "Geronimo Config Store Reaper");
-            this.thread.setDaemon(true);
-            this.thread.start();
         }
 
         public void delete(String dir, String type) {
             pendingDeletionIndex.setProperty(dir, type);
-            if (log.isDebugEnabled()) {
-                log.debug("Queued deployment directory to be reaped " + dir);
+            log.debug("Queued deployment directory to be reaped " + dir);
+            startThread();
+        }
+
+        private synchronized void startThread() {
+            if (this.thread == null) {
+                this.thread = new Thread(this, "Geronimo Config Store Reaper");
+                this.thread.setDaemon(true);
+                this.thread.start();
             }
         }
 
@@ -559,9 +638,6 @@ public class Deployer implements GBeanLi
          * Reap any temporary directories left behind by previous runs.
          */
         private void reapBacklog() {
-            if (!CLEAN_UP_ON_START) {
-                return;
-            }
             try {
                 File tempFile = File.createTempFile("geronimo-deployer", ".tmpdir");
                 File tempDir = tempFile.getParentFile();
@@ -573,28 +649,7 @@ public class Deployer implements GBeanLi
                 for(String dir: backlog) {
                     File deleteDir = new File(tempDir, dir);
                     FileUtils.recursiveDelete(deleteDir);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Reaped deployment directory from previous runs " + deleteDir);
-                    }
-                }
-            } catch (IOException ignored) {
-            }
-            try {
-                File tempFile = FileUtils.createTempFile();
-                File tempDir = tempFile.getParentFile();
-                tempFile.delete();
-                String[] backlog = tempDir.list(new FilenameFilter(){
-                    public boolean accept(File dir, String name) {
-                        File file = new File(dir, name);
-                        boolean validTempFile = name.startsWith(FileUtils.DEFAULT_TEMP_PREFIX) && ((file.isDirectory() && name.endsWith(FileUtils.DEFAULT_TEMP_DIRECTORY_SUFFIX)) || file.isFile());
-                        return validTempFile && (file.lastModified() < FileUtils.FILE_UTILS_INITIALIZATION_TIME_MILL);
-                    }});
-                for(String dir: backlog) {
-                    File deleteDir = new File(tempDir, dir);
-                    FileUtils.recursiveDelete(deleteDir);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Reaped deployment directory from previous runs " + deleteDir);
-                    }
+                    log.debug("Reaped deployment directory from previous runs " + deleteDir);
                 }
             } catch (IOException ignored) {
             }
@@ -616,39 +671,10 @@ public class Deployer implements GBeanLi
 
                 if (FileUtils.recursiveDelete(deleteDir)) {
                     pendingDeletionIndex.remove(dirName);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Reaped deployment directory " + deleteDir);
-                    }
+                    log.debug("Reaped deployment directory " + deleteDir);
                 }
             }
         }
     }
 
-    public static final GBeanInfo GBEAN_INFO;
-
-    private static final String DEPLOYER = "Deployer";
-
-    static {
-        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(Deployer.class, DEPLOYER);
-
-        infoFactory.addAttribute("kernel", Kernel.class, false);
-        infoFactory.addAttribute("remoteDeployAddress", String.class, true, true);
-        infoFactory.addAttribute("remoteDeployUploadURL", String.class, false);
-//        infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class});
-//        infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class, String.class});
-//        infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class, File.class, boolean.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class});
-
-        infoFactory.addReference("Builders", ConfigurationBuilder.class, "ConfigBuilder");
-        infoFactory.addReference("Store", ConfigurationStore.class, "ConfigurationStore");
-        infoFactory.addReference("Watchers", DeploymentWatcher.class);
-
-        infoFactory.setConstructor(new String[]{"remoteDeployAddress", "Builders", "Store", "Watchers", "kernel"});
-
-        GBEAN_INFO = infoFactory.getBeanInfo();
-    }
-
-    public static GBeanInfo getGBeanInfo() {
-        return GBEAN_INFO;
-    }
-
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml?rev=1221390&r1=1221389&r2=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml Tue Dec 20 18:04:59 2011
@@ -34,6 +34,12 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-osgi-registry</artifactId>
         </dependency>
@@ -69,19 +75,26 @@
             <artifactId>xbean-reflect</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>org.apache.servicemix.bundles</groupId>
-            <artifactId>org.apache.servicemix.bundles.xstream</artifactId>
-        </dependency>
+        <!--<dependency>-->
+            <!--<groupId>org.apache.servicemix.bundles</groupId>-->
+            <!--<artifactId>org.apache.servicemix.bundles.xstream</artifactId>-->
+        <!--</dependency>-->
+
+        <!--<dependency>-->
+            <!--<groupId>org.apache.servicemix.bundles</groupId>-->
+            <!--<artifactId>org.apache.servicemix.bundles.xpp3</artifactId>-->
+        <!--</dependency>-->
+
+        <!--<dependency>-->
+            <!--<groupId>org.apache.geronimo.specs</groupId>-->
+            <!--<artifactId>geronimo-stax-api_1.2_spec</artifactId>-->
+        <!--</dependency>-->
 
+        <!-- commands -->
         <dependency>
-            <groupId>org.apache.servicemix.bundles</groupId>
-            <artifactId>org.apache.servicemix.bundles.xpp3</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-stax-api_1.2_spec</artifactId>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -108,6 +121,10 @@
     <build>
         <plugins>
             <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-antrun-plugin</artifactId>
                 <executions>

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java?rev=1221390&r1=1221389&r2=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java Tue Dec 20 18:04:59 2011
@@ -90,7 +90,9 @@ public class GBeanSingleReference extend
     public synchronized void stop() {
         Object proxy = getProxy();
         if (proxy != null) {
-            getKernel().getProxyManager().destroyProxy(proxy);
+            if (getKernel().getProxyManager() != null) {
+                getKernel().getProxyManager().destroyProxy(proxy);
+            }
             setProxy(null);
         }
     }

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/wrapper/AbstractServiceWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/wrapper/AbstractServiceWrapper.java?rev=1221390&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/wrapper/AbstractServiceWrapper.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/wrapper/AbstractServiceWrapper.java Tue Dec 20 18:04:59 2011
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.gbean.wrapper;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * A GBean that exposes an osgi service as a gbean.  The service has to be a singleton of the supplied interface
+ * @version $Rev:$ $Date:$
+ */
+public class AbstractServiceWrapper<T> {
+
+    private volatile T actual;
+    private volatile CountDownLatch latch = new CountDownLatch(1);
+
+    public AbstractServiceWrapper(final Bundle bundle, Class<T> clazz) {
+        final BundleContext bundleContext = bundle.getBundleContext();
+        ServiceTracker t = new ServiceTracker(bundleContext, clazz.getName(), new ServiceTrackerCustomizer() {
+
+            @Override
+            public Object addingService(ServiceReference serviceReference) {
+                actual = (T) bundleContext.getService(serviceReference);
+                latch.countDown();
+                return actual;
+            }
+
+            @Override
+            public void modifiedService(ServiceReference serviceReference, Object o) {
+            }
+
+            @Override
+            public void removedService(ServiceReference serviceReference, Object o) {
+                latch = new CountDownLatch(1);
+                actual = null;
+            }
+        });
+        t.open();
+    }
+
+    protected T get() {
+        T actual = null;
+        while (actual == null) {
+            try {
+                latch.await();
+            } catch (InterruptedException e) {
+
+            }
+            actual = this.actual;
+        }
+        return actual;
+    }
+
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/wrapper/AbstractServiceWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/wrapper/AbstractServiceWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/wrapper/AbstractServiceWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java?rev=1221390&r1=1221389&r2=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java Tue Dec 20 18:04:59 2011
@@ -313,8 +313,9 @@ public interface Kernel {
     /**
      * Brings the kernel online
      * @throws Exception if the kernel can not boot
+     * @param bundleContext
      */
-    void boot() throws Exception;
+    void boot(BundleContext bundleContext) throws Exception;
 
     /**
      * Returns the time this kernel was last booted.

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java?rev=1221390&r1=1221389&r2=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java Tue Dec 20 18:04:59 2011
@@ -364,8 +364,8 @@ public class KernelGBean implements Kern
         return kernel.getShortNameFor(service);
     }
 
-    public void boot() throws Exception {
-        kernel.boot();
+    public void boot(BundleContext bundleContext) throws Exception {
+//        kernel.boot();
     }
 
     public Date getBootTime() {

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java?rev=1221390&r1=1221389&r2=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java Tue Dec 20 18:04:59 2011
@@ -66,7 +66,7 @@ public class BasicDependencyManager impl
      */
     private final Map parentToChildMap = new HashMap();
 
-    public BasicDependencyManager(LifecycleMonitor lifecycleMonitor) throws Exception {
+    public BasicDependencyManager(LifecycleMonitor lifecycleMonitor) {
         assert lifecycleMonitor != null;
         this.lifecycleMonitor = lifecycleMonitor;
         lifecycleMonitor.addLifecycleListener(lifecycleListener, new AbstractNameQuery(null, Collections.EMPTY_MAP, Collections.EMPTY_SET));

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java?rev=1221390&r1=1221389&r2=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java Tue Dec 20 18:04:59 2011
@@ -19,10 +19,15 @@ package org.apache.geronimo.kernel.basic
 
 import java.util.Date;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.Set;
 import javax.management.ObjectName;
 
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.geronimo.gbean.GBeanData;
@@ -70,6 +75,8 @@ import org.osgi.framework.BundleContext;
  *
  * @version $Rev:386276 $ $Date$
  */
+@Component
+@Service
 public class BasicKernel implements Kernel
 {
     private static final Logger log = LoggerFactory.getLogger(BasicKernel.class);
@@ -83,7 +90,7 @@ public class BasicKernel implements Kern
     /**
      * Name of this kernel
      */
-    private final String kernelName;
+    private String kernelName = "kernel";
 
     private BundleContext bundleContext;
 
@@ -100,49 +107,103 @@ public class BasicKernel implements Kern
     /**
      * The registry
      */
-    private final BasicRegistry registry;
+    private final BasicRegistry registry = new BasicRegistry();
 
     /**
      * Listeners for when the kernel shutdown
      */
     private final LinkedList shutdownHooks = new LinkedList();
 
+
     /**
-     * This manager is used by the kernel to manage dependencies between gbeans
+     * Monitors the lifecycle of all gbeans.
      */
-    private DependencyManager dependencyManager;
+    private BasicLifecycleMonitor lifecycleMonitor = new BasicLifecycleMonitor(this);;
+    private LifecycleMonitor publicLifecycleMonitor = new LifecycleMonitorFlyweight(lifecycleMonitor);;
 
     /**
-     * Monitors the lifecycle of all gbeans.
+     * This manager is used by the kernel to manage dependencies between gbeans
      */
-    private BasicLifecycleMonitor lifecycleMonitor;
-    private LifecycleMonitor publicLifecycleMonitor;
+     private DependencyManager dependencyManager = new BasicDependencyManager(publicLifecycleMonitor);
 
     /**
      * This factory gbean proxies, and tracks all proxies in the system
      */
-    private ProxyManager proxyManager;
+//    private ProxyManager proxyManager = new BasicProxyManager(this);
 
     private static final Naming INSTANCE = new Jsr77Naming();
 
+    public BasicKernel() {
+    }
+
+    public BasicKernel(String name, BundleContext bundleContext) throws Exception {
+        //TODO not clear if usage of this constructor requires boot.
+        boot(bundleContext);
+    }
+
     /**
-     * Construct a Kernel with the specified name.
+     * Boot this Kernel, triggering the instantiation of the MBeanServer and DependencyManager,
+     * and the registration of ConfigurationStore
      *
-     * @param kernelName the name of the kernel
-     * @param bundleContext bundle context kernel is configured in.
+     * @throws java.lang.Exception if the boot fails
+     */
+    @Activate
+    public void boot(BundleContext bundleContext) throws Exception {
+        if (running) {
+            return;
+        }
+        bootTime = new Date();
+        log.debug("Starting boot");
+
+        // todo cleanup when boot fails
+        KernelRegistry.registerKernel(this);
+
+        registry.start(this);
+
+//        lifecycleMonitor = new BasicLifecycleMonitor(this);
+//        publicLifecycleMonitor = new LifecycleMonitorFlyweight(lifecycleMonitor);
+//        dependencyManager = new BasicDependencyManager(publicLifecycleMonitor);
+//        proxyManager = new BasicProxyManager(this);
+
+        // load and start the kernel gbean
+        GBeanData kernelGBeanData = new GBeanData(KERNEL_NAME, KernelGBean.GBEAN_INFO);
+        loadGBean(kernelGBeanData, bundleContext);
+//        loadGBean(kernelGBeanData, bundleContext.getBundle(), bundleContext.getBundle());
+        startGBean(KERNEL_NAME);
+
+        running = true;
+        log.debug("Booted");
+    }
+
+    /**
+     * Shut down this kernel instance, unregistering the MBeans and releasing
+     * the MBeanServer.
      */
-    public BasicKernel(String kernelName, BundleContext bundleContext) {
-        if (kernelName.indexOf(':') >= 0 || kernelName.indexOf('*') >= 0 || kernelName.indexOf('?') >= 0) {
-            throw new IllegalArgumentException("Kernel name may not contain a ':', '*' or '?' character");
-        }
-        if (bundleContext == null) {
-            throw new NullPointerException("bundleContext required");
-        }
-        this.kernelName = kernelName;
-        this.bundleContext = bundleContext;
-        this.registry = new BasicRegistry();
+    @Deactivate
+    public void shutdown() {
+        if (!running) {
+            return;
+        }
+        running = false;
+        log.debug("Starting kernel shutdown");
+
+        notifyShutdownHooks();
+
+        registry.stop();
+
+         dependencyManager.close();
+         dependencyManager = null;
+
+        synchronized (this) {
+            notify();
+        }
+
+        KernelRegistry.unregisterKernel(this);
+
+        log.debug("Kernel shutdown complete");
     }
 
+
     public String getKernelName() {
         return kernelName;
     }
@@ -154,9 +215,9 @@ public class BasicKernel implements Kern
     /**
      * @deprecated this will be removed as when we add generalized dependencies to gbeans... the only current user is Configuration
      */
-    public DependencyManager getDependencyManager() {
-        return dependencyManager;
-    }
+     public DependencyManager getDependencyManager() {
+         return dependencyManager;
+     }
 
     /**
      * Gets the lifecycle monitor.
@@ -171,7 +232,7 @@ public class BasicKernel implements Kern
      * @deprecated don't use this yet... it may change or go away
      */
     public ProxyManager getProxyManager() {
-        return proxyManager;
+        return null;
     }
 
     public Object getAttribute(ObjectName objectName, String attributeName) throws GBeanNotFoundException, NoSuchAttributeException, Exception {
@@ -280,6 +341,15 @@ public class BasicKernel implements Kern
         }
     }
 
+/*
+    //delegated from Configuration
+    @Override
+    public LinkedHashSet<GBeanData> findGBeanDatas(Set<AbstractNameQuery> patterns) {
+        return registry.findGBeanDatas(patterns);
+    }
+*/
+
+
     public Object getGBean(String shortName) throws GBeanNotFoundException, InternalKernelException, IllegalStateException {
         return getGBean(shortName, null);
     }
@@ -362,6 +432,16 @@ public class BasicKernel implements Kern
         registry.register(gbeanInstance);
         lifecycleBroadcaster.fireLoadedEvent();
     }
+/*
+    public void loadGBean(GBeanData gbeanData, Bundle gbeanBundle, Bundle configurationBundle) throws GBeanAlreadyExistsException, InternalKernelException {
+        AbstractName abstractName = gbeanData.getAbstractName();
+        Set interfaces = gbeanData.getGBeanInfo().getInterfaces();
+        LifecycleBroadcaster lifecycleBroadcaster = lifecycleMonitor.createLifecycleBroadcaster(abstractName, interfaces);
+        GBeanInstance gbeanInstance = new GBeanInstance(gbeanData, this, dependencyManager, lifecycleBroadcaster, gbeanBundle, configurationBundle);
+        registry.register(gbeanInstance);
+        lifecycleBroadcaster.fireLoadedEvent();
+    }
+*/
 
     public void startGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException, IllegalStateException {
         GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
@@ -561,19 +641,13 @@ public class BasicKernel implements Kern
             return null;
         }
 
-        // check if service is a proxy
-        AbstractName name = proxyManager.getProxyTarget(service);
-        if (name != null) {
-            return name;
-        }
-
         // try the registry
         GBeanInstance gbeanInstance = registry.getGBeanInstanceByInstance(service);
         if (gbeanInstance != null) {
             return gbeanInstance.getAbstractName();
         }
 
-        // didn't fing the name
+        // didn't find the name
         return null;
     }
 
@@ -585,38 +659,6 @@ public class BasicKernel implements Kern
         return null;
     }
 
-    /**
-     * Boot this Kernel, triggering the instantiation of the MBeanServer and DependencyManager,
-     * and the registration of ConfigurationStore
-     *
-     * @throws java.lang.Exception if the boot fails
-     */
-    public void boot() throws Exception {
-        if (running) {
-            return;
-        }
-        bootTime = new Date();
-        log.debug("Starting boot");
-
-        // todo cleanup when boot fails
-        KernelRegistry.registerKernel(this);
-
-        registry.start(this);
-
-        lifecycleMonitor = new BasicLifecycleMonitor(this);
-        publicLifecycleMonitor = new LifecycleMonitorFlyweight(lifecycleMonitor);
-        dependencyManager = new BasicDependencyManager(publicLifecycleMonitor);
-        proxyManager = new BasicProxyManager(this);
-
-        // load and start the kernel gbean
-        GBeanData kernelGBeanData = new GBeanData(KERNEL_NAME, KernelGBean.GBEAN_INFO);
-        loadGBean(kernelGBeanData, bundleContext);
-        startGBean(KERNEL_NAME);
-
-        running = true;
-        log.debug("Booted");
-    }
-
     public Date getBootTime() {
         return bootTime;
     }
@@ -634,33 +676,6 @@ public class BasicKernel implements Kern
         }
     }
 
-    /**
-     * Shut down this kernel instance, unregistering the MBeans and releasing
-     * the MBeanServer.
-     */
-    public void shutdown() {
-        if (!running) {
-            return;
-        }
-        running = false;
-        log.debug("Starting kernel shutdown");
-
-        notifyShutdownHooks();
-
-        registry.stop();
-
-        dependencyManager.close();
-        dependencyManager = null;
-
-        synchronized (this) {
-            notify();
-        }
-
-        KernelRegistry.unregisterKernel(this);
-
-        log.debug("Kernel shutdown complete");
-    }
-
     private void notifyShutdownHooks() {
         while (!shutdownHooks.isEmpty()) {
             Runnable hook;
@@ -682,6 +697,7 @@ public class BasicKernel implements Kern
     public Bundle getBundleFor(AbstractName name) throws GBeanNotFoundException {
         GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
         return gbeanInstance.getBundle();
+//        return gbeanInstance.getGbeanBundle();
     }
 
     public Bundle getBundleFor(String shortName) throws GBeanNotFoundException {
@@ -695,6 +711,7 @@ public class BasicKernel implements Kern
     public Bundle getBundleFor(String shortName, Class type) throws GBeanNotFoundException {
         GBeanInstance gbeanInstance = registry.getGBeanInstance(shortName, type);
         return gbeanInstance.getBundle();
+//        return gbeanInstance.getGbeanBundle();
     }
 
     /**

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernelFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernelFactory.java?rev=1221390&r1=1221389&r2=1221390&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernelFactory.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernelFactory.java Tue Dec 20 18:04:59 2011
@@ -24,6 +24,12 @@ import org.apache.geronimo.kernel.Kernel
  */
 public class BasicKernelFactory extends KernelFactory {
     public Kernel createKernel(String kernelName) {
-        return new BasicKernel(kernelName, getBundleContext());
+        BasicKernel kernel = new BasicKernel();
+//        try {
+//            kernel.boot(getBundleContext());
+//        } catch (Exception e) {
+//            throw new RuntimeException(e);
+//        }
+        return kernel;
     }
 }

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java?rev=1221390&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java Tue Dec 20 18:04:59 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.kernel.command;
+
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public abstract class KernelCommandSupport extends OsgiCommandSupport {
+
+    protected Object doExecute() throws Exception {
+        // Get repository admin service.
+        ServiceReference ref = getBundleContext().getServiceReference(Kernel.class.getName());
+        if (ref == null) {
+            System.out.println("FeaturesService service is unavailable.");
+            return null;
+        }
+        try {
+            Kernel admin = (Kernel) getBundleContext().getService(ref);
+            if (admin == null) {
+                System.out.println("FeaturesService service is unavailable.");
+                return null;
+            }
+
+            doExecute(admin);
+        }
+        finally {
+            getBundleContext().ungetService(ref);
+        }
+        return null;
+    }
+
+
+    protected abstract void doExecute(Kernel kernel) throws Exception;
+
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message