[jboss-cvs] JBossAS SVN: r87120 - in projects/bootstrap/trunk: impl-mc/src/main/java and 26 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Apr 10 07:07:18 EDT 2009
Author: ALRubinger
Date: 2009-04-10 07:07:18 -0400 (Fri, 10 Apr 2009)
New Revision: 87120
Added:
projects/bootstrap/trunk/impl-mc/src/main/java/org/
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/BasicMCServerConfig.java
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/deployer/
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/deployer/TempBasicXMLDeployer.java
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java
projects/bootstrap/trunk/impl-mc/src/test/java/org/
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/Pojo.java
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java
projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap.xml
projects/bootstrap/trunk/impl-mc/src/test/resources/log4j.xml
projects/bootstrap/trunk/spi-mc/src/main/java/org/
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/MCServerConfig.java
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/
projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/MCServer.java
Modified:
projects/bootstrap/trunk/impl-mc/pom.xml
projects/bootstrap/trunk/spi-mc/pom.xml
Log:
[JBBOOT-27] Add the MC impl of Bootstrap upon the new SPI
Modified: projects/bootstrap/trunk/impl-mc/pom.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/pom.xml 2009-04-10 10:56:39 UTC (rev 87119)
+++ projects/bootstrap/trunk/impl-mc/pom.xml 2009-04-10 11:07:18 UTC (rev 87120)
@@ -25,6 +25,9 @@
<!-- Properties -->
<properties>
+ <version.org.jboss.bootstrap_jboss.bootstrap.spi.mc>0.1.0-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.spi.mc>
+ <version.org.jboss.man_jboss.managed>2.0.0.GA</version.org.jboss.man_jboss.managed>
+
</properties>
<!-- Build -->
@@ -35,6 +38,42 @@
<!-- Dependencies -->
<dependencies>
+ <!-- junit:junit -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <!-- org.jboss.bootstrap:jboss-bootstrap-spi-mc -->
+ <dependency>
+ <groupId>org.jboss.bootstrap</groupId>
+ <artifactId>jboss-bootstrap-spi-mc</artifactId>
+ <version>${version.org.jboss.bootstrap_jboss.bootstrap.spi.mc}</version>
+ </dependency>
+
+ <!-- org.jboss.logging -->
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </dependency>
+
+ <!-- org.jboss.man:jboss-managed -->
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>${version.org.jboss.man_jboss.managed}</version>
+ </dependency>
+
+ <!-- org.jboss.microcontainer:jboss-kernel -->
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </dependency>
+
</dependencies>
</project>
Added: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/BasicMCServerConfig.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/BasicMCServerConfig.java (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/BasicMCServerConfig.java 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.impl.mc.config;
+
+import java.util.Map;
+
+import org.jboss.bootstrap.spi.config.AbstractBasicServerConfig;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+import org.jboss.logging.Logger;
+
+/**
+ * BasicServerConfig
+ *
+ * Simple Object-backed implementation of an MC Server Configuration
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class BasicMCServerConfig extends AbstractBasicServerConfig<MCServerConfig> implements MCServerConfig
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ @SuppressWarnings("unused")
+ private static final Logger log = Logger.getLogger(BasicMCServerConfig.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ */
+ public BasicMCServerConfig()
+ {
+ super(MCServerConfig.class);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param overrideProperties A Set of properties to override those found
+ * in System Properties
+ */
+ public BasicMCServerConfig(Map<String, String> overrideProperties)
+ {
+ super(MCServerConfig.class, overrideProperties);
+ }
+
+}
Copied: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/deployer/TempBasicXMLDeployer.java (from rev 86846, projects/bootstrap/trunk/legacy/src/main/java/org/jboss/bootstrap/microcontainer/TempBasicXMLDeployer.java)
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/deployer/TempBasicXMLDeployer.java (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/deployer/TempBasicXMLDeployer.java 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,205 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bootstrap.impl.mc.deployer;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.deployment.BasicKernelDeployer;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.logging.Logger;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+
+/**
+ * A copy of the mc BasicXMLDeployer that provides access to the KernelDeployments.
+ * TODO: replace when JBMICROCONT-383 is resolved.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class TempBasicXMLDeployer extends BasicKernelDeployer
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(TempBasicXMLDeployer.class);
+
+ /** Unmarshaller factory */
+ private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
+
+ /** The resolver */
+ private static final SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+
+ /** The deployments by url or name */
+ private Map<String, KernelDeployment> deploymentsByName = new ConcurrentHashMap<String, KernelDeployment>();
+
+ /**
+ * Create a new XML deployer
+ *
+ * @param kernel the kernel
+ */
+ public TempBasicXMLDeployer(Kernel kernel)
+ {
+ this(kernel, null);
+ }
+
+ /**
+ * Create a new XML deployer with mode.
+ *
+ * @param kernel the kernel
+ * @param mode the controller mode
+ */
+ public TempBasicXMLDeployer(Kernel kernel, ControllerMode mode)
+ {
+ super(kernel, mode);
+ }
+
+ public Collection<String> getDeploymentNames()
+ {
+ return deploymentsByName.keySet();
+ }
+
+ public void deploy(KernelDeployment deployment) throws Throwable
+ {
+ super.deploy(deployment);
+ deploymentsByName.put(deployment.getName(), deployment);
+ }
+
+ public void undeploy(KernelDeployment deployment)
+ {
+ deploymentsByName.remove(deployment.getName());
+ super.undeploy(deployment);
+ }
+
+ /**
+ * Undeploy a url
+ *
+ * @param url the url to undeploy
+ * @throws IllegalStateException if the url is unknown
+ */
+ public void undeploy(final URL url)
+ {
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+ undeploy(url.toString());
+ }
+
+ /**
+ * Undeploy a name deployment
+ *
+ * @param name the name of the deployment to undeploy
+ * @throws IllegalStateException if the name is unknown
+ */
+ public void undeploy(final String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ KernelDeployment deployment = deploymentsByName.remove(name);
+ if (deployment == null)
+ throw new IllegalStateException("Unknown deployment " + name);
+ undeploy(deployment);
+ }
+
+ /**
+ * Deploy a url
+ *
+ * @param url the url to deploy
+ * @return the kernel deployment
+ * @throws Throwable for any error
+ */
+ public KernelDeployment deploy(final URL url) throws Throwable
+ {
+ final boolean trace = log.isTraceEnabled();
+
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
+ if (trace)
+ log.trace("Parsing " + url);
+
+ long start = System.currentTimeMillis();
+
+ Unmarshaller unmarshaller = factory.newUnmarshaller();
+ KernelDeployment deployment = (KernelDeployment) unmarshaller.unmarshal(url.toString(), resolver);
+ if (deployment == null)
+ throw new RuntimeException("The xml " + url + " is not well formed!");
+ deployment.setName(url.toString());
+
+ if (trace)
+ {
+ long now = System.currentTimeMillis();
+ log.trace("Parsing " + url + " took " + (now-start) + " milliseconds");
+ }
+
+ deploy(deployment);
+
+ if (trace)
+ {
+ long now = System.currentTimeMillis();
+ log.trace("Deploying " + url + " took " + (now-start) + " milliseconds");
+ }
+
+ return deployment;
+ }
+
+ /**
+ * Deploy a stream. We may be deploying XML fragments.
+ *
+ * @param deploymentName the deployment name
+ * @param stream the stream
+ * @return the kernel deployment
+ * @throws Throwable for any error
+ */
+ public KernelDeployment deploy(String deploymentName, final InputStream stream) throws Throwable
+ {
+ boolean trace = log.isTraceEnabled();
+
+ if (trace)
+ log.trace("Parsing " + deploymentName);
+ Unmarshaller unmarshaller = factory.newUnmarshaller();
+ KernelDeployment deployment = (KernelDeployment) unmarshaller.unmarshal(stream, resolver);
+ if (deployment == null)
+ throw new RuntimeException("The deployment " + deploymentName + " is not well formed!");
+ deployment.setName(deploymentName);
+
+ deploy(deployment);
+
+ return deployment;
+ }
+
+ /**
+ * Access a read-only view of the deployer's deployments.
+ * @return the KernelDeployment map by name
+ */
+ public Map<String, KernelDeployment> getDeployments()
+ {
+ return Collections.unmodifiableMap(deploymentsByName);
+ }
+}
Property changes on: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/deployer/TempBasicXMLDeployer.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Added: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,233 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.impl.mc.server;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.bootstrap.impl.mc.deployer.TempBasicXMLDeployer;
+import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+import org.jboss.bootstrap.spi.mc.server.MCServer;
+import org.jboss.bootstrap.spi.metadata.BootstrapMetaData;
+import org.jboss.bootstrap.spi.server.AbstractServer;
+import org.jboss.bootstrap.spi.xml.BootstrapParser;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+
+/**
+ * MCServerImpl
+ *
+ * Microcontainer implementation of a Server.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MCServerImpl extends AbstractServer<MCServer, MCServerConfig> implements MCServer
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(MCServerImpl.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The MC Bootstrap
+ */
+ private BasicBootstrap bootstrap;
+
+ /**
+ * The MC Kernel
+ */
+ private Kernel kernel;
+
+ /**
+ * The XML Deployer
+ */
+ private TempBasicXMLDeployer kernelDeployer;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public MCServerImpl(final MCServerConfig config) throws InvalidConfigurationException, IllegalArgumentException
+ {
+ // Invoke super
+ super(config);
+
+ // Bootstrap and set the kernel
+ BasicBootstrap bootstrap = new BasicBootstrap();
+ bootstrap.run();
+ kernel = bootstrap.getKernel();
+
+ this.bootstrap = bootstrap;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.mc.server.MCServer#getKernel()
+ */
+ public Kernel getKernel()
+ {
+ return this.kernel;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.AbstractServer#doShutdown()
+ */
+ @Override
+ protected void doShutdown() throws Exception
+ {
+ // Shutdown the deployer
+ try
+ {
+ if (kernelDeployer != null)
+ {
+ kernelDeployer.shutdown();
+ kernelDeployer = null;
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error stopping xml deployer", t);
+ }
+
+ // Shutdown the controller
+ try
+ {
+ Kernel currentKernel = null;
+ if (kernel != null)
+ {
+ currentKernel = kernel;
+ kernel = null;
+ }
+ else if (bootstrap != null)
+ {
+ currentKernel = bootstrap.getKernel();
+ }
+ bootstrap = null;
+
+ if (currentKernel != null)
+ {
+ KernelController controller = currentKernel.getController();
+ controller.shutdown();
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error stopping xml deployer", t);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.AbstractServer#doStart()
+ */
+ @Override
+ protected void doStart() throws Exception
+ {
+ // Register the server implementation
+ final String mcServerBindName = "JBossServer";
+ final KernelController controller = kernel.getController();
+ final BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(mcServerBindName, getClass().getName());
+ builder.addMethodInstallCallback("addBootstrap");
+ builder.addMethodUninstallCallback("removeBootstrap");
+ builder.ignoreStart(); // We invoke start manually, don't let MC do it
+ try
+ {
+ log.debug("Installing " + this + " into MC under key: " + mcServerBindName);
+ controller.install(builder.getBeanMetaData(), this);
+ }
+ catch (Throwable t)
+ {
+ throw new Exception("Error in installing " + mcServerBindName + " during startup", t);
+ }
+
+ // Determine the url for the bootstrap
+ final MCServerConfig config = this.getConfiguration();
+ final URL configURL = config.getBootstrapConfLocation();
+ URL url = config.getBootstrapUrl();
+ log.info("Starting Microcontainer, bootstrapURL=" + url);
+
+ // Parse the bootstrap metadata
+ final BootstrapMetaData bootstrapMetaData = BootstrapParser.parse(url);
+ List<String> bootstrapURLs = bootstrapMetaData.getBootstrapURLs();
+ if (bootstrapURLs == null)
+ {
+ bootstrapURLs = Collections.emptyList();
+ }
+ if (bootstrapURLs.isEmpty())
+ {
+ log.warn("No bootstrap urls in " + url);
+ }
+ log.debug("BootstrapURLs=" + bootstrapURLs);
+
+ // Create an xml deployer
+ kernelDeployer = new TempBasicXMLDeployer(kernel);
+ try
+ {
+ // Deploy the bootstrap urls
+ for (String bootstrapURL : bootstrapURLs)
+ {
+ log.debug("Deploying bootstrap xml:" + bootstrapURL);
+ url = new URL(configURL, bootstrapURL);
+ kernelDeployer.deploy(url);
+ }
+
+ // Check it is complete
+ kernelDeployer.validate();
+ }
+ catch (Throwable t)
+ {
+ try
+ {
+ kernelDeployer.shutdown();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ throw new Exception("Encountered exception in server startup", t);
+ }
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+}
Added: projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/Pojo.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/Pojo.java (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/Pojo.java 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.impl.mc.server;
+
+import org.jboss.beans.metadata.api.annotations.Start;
+import org.jboss.logging.Logger;
+
+/**
+ * Pojo
+ *
+ * Simple test POJO
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class Pojo
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(Pojo.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private boolean started = false;
+
+ //-------------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Start lifecycle (called by MC upon install)
+ */
+ @Start
+ public void start() throws Throwable
+ {
+ log.info("Start lifecycle called: " + this);
+ this.started = true;
+ }
+
+ /**
+ * Returns whether or not the Service was started
+ * @return
+ */
+ public boolean isStarted()
+ {
+ return this.started;
+ }
+}
Added: projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,183 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.impl.mc.server.unit;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.bootstrap.impl.mc.config.BasicMCServerConfig;
+import org.jboss.bootstrap.impl.mc.server.MCServerImpl;
+import org.jboss.bootstrap.impl.mc.server.Pojo;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+import org.jboss.bootstrap.spi.mc.server.MCServer;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * MCServerUnitTestCase
+ *
+ * Test Cases to ensure that the MC Server Implementation is
+ * working as contracted
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MCServerUnitTestCase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(MCServerUnitTestCase.class);
+
+ private static final String NAME_CONF = "conf";
+
+ private static final String NAME_BOOTSTRAP = "bootstrap.xml";
+
+ /**
+ * The server to test
+ */
+ private static MCServer server;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates the server
+ */
+ @BeforeClass
+ public static void createServer() throws Throwable
+ {
+ // Create the server
+ final MCServerConfig config = getServerConfig();
+ server = new MCServerImpl(config);
+ }
+
+ /**
+ * Starts the server
+ *
+ * @throws Throwable
+ */
+ @Before
+ public void startServer() throws Throwable
+ {
+ server.start();
+ }
+
+ /**
+ * If started, shuts down the server
+ * @throws Throwable
+ */
+ @After
+ public void shutdownServer() throws Throwable
+ {
+ if (server.getState().equals(LifecycleState.STARTED))
+ {
+ server.shutdown();
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the server starts and that a simple bean
+ * may be installed into the underlying KernelController
+ *
+ * Uses standard MC APIs via the MCServer interface
+ */
+ @Test
+ public void testMcIntegration() throws Throwable
+ {
+ // Log
+ log.info("Testing server for start and valid MC accessibility");
+
+ // Get state
+ final LifecycleState state = server.getState();
+
+ // Ensure reports as started
+ TestCase.assertTrue("Server should report as started", state.equals(LifecycleState.STARTED));
+
+ /*
+ * Install a test MC bean into the Server, ensure MC takes
+ * over and lifecycle is invoked
+ */
+ final Pojo pojo = new Pojo();
+ final String mcBindName = "org.jboss.bootstrap.test.POJO";
+ final BeanMetaData beanMD = BeanMetaDataBuilder.createBuilder(mcBindName, pojo.getClass().getName())
+ .getBeanMetaData();
+ final KernelController controller = server.getKernel().getController();
+ controller.install(beanMD, pojo);
+ final ControllerContext beanContext = controller.getContext(mcBindName, null);
+ final ControllerState beanState = beanContext.getState();
+ TestCase.assertEquals("POJO did not properly install, error was: " + beanContext.getError(),
+ ControllerState.INSTALLED, beanState);
+
+ // Test Lifecycle was invoked by MC
+ final boolean pojoStarted = pojo.isStarted();
+ TestCase.assertTrue("Start lifecycle was not called upon the POJO", pojoStarted);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains a server configuration populated with all URLs and name
+ */
+ private static MCServerConfig getServerConfig()
+ {
+ // Get the home
+ final URL home = MCServerUnitTestCase.class.getProtectionDomain().getCodeSource().getLocation();
+
+ // Construct URLs
+ URL conf = null;
+ URL bootstrap = null;
+ try
+ {
+ conf = new URL(home, NAME_CONF);
+ bootstrap = new URL(home, NAME_BOOTSTRAP);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException("Error in URL (improper test setup)", e);
+ }
+
+ // Populate and return
+ return new BasicMCServerConfig().setBootstrapHome(home).setBootstrapConfLocation(conf).setBootstrapUrl(bootstrap)
+ .setBootstrapName(NAME_BOOTSTRAP);
+ }
+}
Added: projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap.xml (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap.xml 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bootstrap xmlns="urn:jboss:bootstrap:1.0">
+
+
+ <!--
+ Dummy file for testing, would ordinarily contain:
+
+ <url>something.xml</url>
+ -->
+
+</bootstrap>
\ No newline at end of file
Added: projects/bootstrap/trunk/impl-mc/src/test/resources/log4j.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/resources/log4j.xml (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/resources/log4j.xml 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 68671 2008-01-08 10:04:25Z wolfc $ -->
+
+<!--
+ | For more configuration infromation and examples see the Jakarta Log4j
+ | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <!-- ================================= -->
+ <!-- Preserve messages in a local file -->
+ <!-- ================================= -->
+
+ <!-- A time/date based rolling appender -->
+ <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
+ <param name="File" value="target/test.log"/>
+ <param name="Threshold" value="INFO"/>
+ <param name="Append" value="false"/>
+
+ <!-- Rollover at midnight each day -->
+ <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+ <!-- Rollover at the top of each hour
+ <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
+ -->
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+
+ <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+ <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+ -->
+ </layout>
+ </appender>
+
+ <!-- ============================== -->
+ <!-- Append messages to the console -->
+ <!-- ============================== -->
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+
+ <!-- ================ -->
+ <!-- Limit categories -->
+ <!-- ================ -->
+
+ <category name="org.jboss">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="org.jnp">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="org.jboss.bootstrap">
+ <priority value="ALL"/>
+ </category>
+
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+
+ <root>
+ <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="FILE"/>
+ </root>
+
+</log4j:configuration>
Modified: projects/bootstrap/trunk/spi-mc/pom.xml
===================================================================
--- projects/bootstrap/trunk/spi-mc/pom.xml 2009-04-10 10:56:39 UTC (rev 87119)
+++ projects/bootstrap/trunk/spi-mc/pom.xml 2009-04-10 11:07:18 UTC (rev 87120)
@@ -25,6 +25,8 @@
<!-- Properties -->
<properties>
+ <version.org.jboss.bootstrap_jboss.bootstrap.spi>0.1.0-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.spi>
+
</properties>
<!-- Build -->
@@ -35,6 +37,17 @@
<!-- Dependencies -->
<dependencies>
+ <dependency>
+ <groupId>org.jboss.bootstrap</groupId>
+ <artifactId>jboss-bootstrap-spi</artifactId>
+ <version>${version.org.jboss.bootstrap_jboss.bootstrap.spi}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </dependency>
+
</dependencies>
</project>
Added: projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/MCServerConfig.java
===================================================================
--- projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/MCServerConfig.java (rev 0)
+++ projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/config/MCServerConfig.java 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.spi.mc.config;
+
+import org.jboss.bootstrap.spi.config.ServerConfig;
+
+/**
+ * MCServerConfig
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface MCServerConfig extends ServerConfig<MCServerConfig>
+{
+
+}
Added: projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/MCServer.java
===================================================================
--- projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/MCServer.java (rev 0)
+++ projects/bootstrap/trunk/spi-mc/src/main/java/org/jboss/bootstrap/spi/mc/server/MCServer.java 2009-04-10 11:07:18 UTC (rev 87120)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.spi.mc.server;
+
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+import org.jboss.bootstrap.spi.server.Server;
+import org.jboss.kernel.Kernel;
+
+/**
+ * MCServer
+ *
+ * Contract of Microcontainer implementations of the Server
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface MCServer extends Server<MCServer, MCServerConfig>
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the underlying Kernel
+ *
+ * @return
+ */
+ Kernel getKernel();
+}
More information about the jboss-cvs-commits
mailing list