From: <jbo...@li...> - 2006-04-19 21:13:44
|
Author: arvinder Date: 2006-04-19 17:13:40 -0400 (Wed, 19 Apr 2006) New Revision: 3811 Added: labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBKernel.java labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBKernelConstants.java labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBServiceMBean.java Log: Initial version Added: labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBKernel.java =================================================================== --- labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBKernel.java 2006-04-19 21:08:57 UTC (rev 3810) +++ labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBKernel.java 2006-04-19 21:13:40 UTC (rev 3811) @@ -0,0 +1,202 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2006, JBoss Inc., and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * (C) 2005-2006, + */ +package org.jboss.soa.esbcore.deploy.bootstrap.container; + +import org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer; +import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap; +import org.jboss.kernel.spi.deployment.KernelDeployment; +import org.jboss.util.CollectionsFactory; + +import java.util.List; +import java.util.Enumeration; +import java.util.ListIterator; +import java.net.URL; + +/** + * This class follows a standard bootstrapping mechanism of the microkernel + * by first looking for the core configuration file called jboss-esb-core.xml + * and then jboss-esb-services.xml, both contain pojo deployments. + * + * @see org.jboss.kernel.plugins.bootstrap.standalone.StandaloneBootstrap + * + * @version <tt>$Revision$</tt> + * @author <a href="mailto:asi...@ho...">Arvinder Singh</a>. + */ +public class JBossESBKernel extends BasicBootstrap +{ + /** The deployer */ + protected BeanXMLDeployer deployer; + + /** The core deployments, ideally we want to separate + * this into core & services */ + protected List deployments = CollectionsFactory.createCopyOnWriteList(); + + /** The arguments */ + protected String[] args; + + /** + * Bootstrap the kernel from the command line + * + * @param args the command line arguments + * @throws Exception for any error + */ + public static void main(String[] args) throws Exception + { + JBossESBKernel bootstrap = new JBossESBKernel(args); + bootstrap.run(); + } + + /** + * Default class constructor. + * @throws Exception + */ + public JBossESBKernel() throws Exception + { + super(); + } + + /** + * Create a new bootstrap + * + * @param args the arguments + * @throws Exception for any error + */ + public JBossESBKernel(String[] args) throws Exception + { + super(); + this.args = args; + } + + /** + * Start the bootstrap process. + * @throws Throwable + */ + public void bootstrap() throws Throwable + { + super.bootstrap(); + + deployer = new BeanXMLDeployer(getKernel()); + + Runtime.getRuntime().addShutdownHook(new Shutdown(this)); + + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + + // + // Core + // + for (Enumeration e = cl.getResources(JBossESBKernelConstants.ESB_CORE_CONFIGURATION_DEPLOYMENT); e.hasMoreElements(); ) + { + URL url = (URL) e.nextElement(); + deploy(url); + } + // + // Core Services + // + for (Enumeration e = cl.getResources(JBossESBKernelConstants.ESB_SERVICE_CONFIGURATION_DEPLOYMENT); e.hasMoreElements(); ) + { + URL url = (URL) e.nextElement(); + deploy(url); + } + + // Validate that everything is ok + deployer.validate(); + } + + + /** + * Deploy a url, this may later separate into a deploy core then + * deploy services. + * + * @param url the deployment url + * @throws Throwable for any error + */ + protected void deploy(URL url) throws Throwable + { + log.info("Deploying " + url); + KernelDeployment deployment = deployer.deploy(url); + if(log.isTraceEnabled()) { + log.trace("KernelDeployment:BeanFactories=" + deployment.getBeanFactories()); + log.trace("KernelDeployment:Bean =" + deployment.getBeans()); + log.trace("KernelDeployment:ClassLoader =" + deployment.getClassLoader()); + log.trace("KernelDeployment:InstalledCtxs=" + deployment.getInstalledContexts()); + log.trace("KernelDeployment:Name =" + deployment.getName()); + } + deployments.add(deployment); + log.info("Deployed " + url); + } + + /** + * Undeploy a deployment + * + * @param deployment the deployment + */ + protected void undeploy(KernelDeployment deployment) + { + log.info("Undeploying " + deployment.getName()); + deployments.remove(deployment); + try + { + deployer.undeploy(deployment); + log.info("Undeployed " + deployment.getName()); + } + catch (Throwable t) + { + log.warn("Error during undeployment: " + deployment.getName(), t); + } + } + + /** + * Utility method used to undeploy and shutdown the kernel. + */ + protected void shutdown() { + log.info("Shutting down"); + // We should actually shut down services first so first deregister + // them from the registry and then shutdown core services like the + // registry. + ListIterator iterator = deployments.listIterator(deployments.size()); + while (iterator.hasPrevious()) + { + KernelDeployment deployment = (KernelDeployment) iterator.previous(); + undeploy(deployment); + } + } + + /** + * Bind this Hook into the runtime + */ + protected class Shutdown extends Thread + { + /** + * The kernel we are watching, ie us. + */ + private JBossESBKernel kernel = null; + + public Shutdown(JBossESBKernel watch) + { + this.kernel = watch; + } + + public void run() + { + log.info("Shutdown hook running"); + kernel.shutdown(); + } + } +} Added: labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBKernelConstants.java =================================================================== --- labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBKernelConstants.java 2006-04-19 21:08:57 UTC (rev 3810) +++ labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBKernelConstants.java 2006-04-19 21:13:40 UTC (rev 3811) @@ -0,0 +1,35 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2006, JBoss Inc., and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * (C) 2005-2006, + */ +package org.jboss.soa.esbcore.deploy.bootstrap.container; + +/** + * An interface defining kernel level constants for the esb. + * + * @version <tt>$Revision$</tt> + * @author <a href="mailto:asi...@ho...">Arvinder Singh</a>. + */ +public interface JBossESBKernelConstants +{ + /** The core xml configuration file name */ + static final String ESB_CORE_CONFIGURATION_DEPLOYMENT = "jboss-esb-core.xml"; + + /** The services xml configuration file name */ + static final String ESB_SERVICE_CONFIGURATION_DEPLOYMENT = "jboss-esb-services.xml"; +} Added: labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBServiceMBean.java =================================================================== --- labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBServiceMBean.java 2006-04-19 21:08:57 UTC (rev 3810) +++ labs/jbossesb/branches/JBESB-13/ESBCore/classes/org/jboss/soa/esbcore/deploy/bootstrap/container/JBossESBServiceMBean.java 2006-04-19 21:13:40 UTC (rev 3811) @@ -0,0 +1,80 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2006, JBoss Inc., and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * (C) 2005-2006, + */ +package org.jboss.soa.esbcore.deploy.bootstrap.container; + +import org.jboss.system.ServiceMBeanSupport; + +/** + * A JBoss ServiceMBean wrapper for the kernel bootstrap class. This will + * enable sar deployment for now, until a move to the pure pojo microkernel. + * See the <a href="http://wiki.jboss.org/wiki/Wiki.jsp?page=ServiceMBeanSupport"> + * wiki for more details</href> + * + * @see org.jboss.system.ServiceMBeanSupport + * + * @version <tt>$Revision$</tt> + * @author <a href="mailto:asi...@ho...">Arvinder Singh</a>. + */ +public class JBossESBServiceMBean extends ServiceMBeanSupport +{ + + /** The kernel we are wrapping **/ + private JBossESBKernel bootstrap = null; + + /** + * Default class constructor. + */ + public JBossESBServiceMBean() + { + super(); + } + + /** + * Override to start our kernel + * @throws Exception + */ + public synchronized void startService() throws Exception + { + log.info("Starting JBossESB."); + bootstrap = new JBossESBKernel(); + bootstrap.run(); + } + + /** + * Override to stop our kernel + * @throws Exception + */ + public void stopService() throws Exception + { + log.info("Stopping JBossESB."); + // undeploy all, deregister all services nicely. + bootstrap.shutdown(); + } + + /** + * Override to return our service name. + * @return String The name of this service. + */ + public String getName() + { + return "JBossESB Kernel MBean Service Wrapper"; + } + +} |