[jboss-cvs] JBossAS SVN: r91360 - in projects/embedded/trunk: core/src/main/java/org/jboss/embedded/core/server and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 16 18:36:25 EDT 2009
Author: ALRubinger
Date: 2009-07-16 18:36:24 -0400 (Thu, 16 Jul 2009)
New Revision: 91360
Modified:
projects/embedded/trunk/core/pom.xml
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
Log:
[EMB-32] Add server.undeploy()
Modified: projects/embedded/trunk/core/pom.xml
===================================================================
--- projects/embedded/trunk/core/pom.xml 2009-07-16 22:07:01 UTC (rev 91359)
+++ projects/embedded/trunk/core/pom.xml 2009-07-16 22:36:24 UTC (rev 91360)
@@ -25,19 +25,20 @@
<!-- Properties -->
<properties>
-
+
<!-- Versioning -->
<version.org.jboss.jbossas>5.2.0-SNAPSHOT</version.org.jboss.jbossas>
-
- <!--
- TODO: Properties below this line should be ultimately
- removed as these dependencies should be provided as part of the AS
- dependency chain
- -->
-
+
+ <!--
+ TODO: Properties below this line should be ultimately removed as
+ these dependencies should be provided as part of the AS dependency
+ chain
+ -->
+
<version.jboss.web>2.1.3.GA</version.jboss.web>
<version.jboss.messaging>1.4.3.GA</version.jboss.messaging>
-
+ <version.org.slf4j_slf4j.jboss.logging>1.0.2.GA</version.org.slf4j_slf4j.jboss.logging>
+
</properties>
<!-- Dependencies -->
@@ -47,7 +48,7 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
-
+
<!-- AS modules and 3rdparty deps -->
<dependency>
<groupId>org.jboss.jbossas</groupId>
@@ -88,6 +89,11 @@
<artifactId>jboss-messaging</artifactId>
<version>${version.jboss.messaging}</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.slf4j</groupId>
+ <artifactId>slf4j-jboss-logging</artifactId>
+ <version>${version.org.slf4j_slf4j.jboss.logging}</version>
+ </dependency>
</dependencies>
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java 2009-07-16 22:07:01 UTC (rev 91359)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java 2009-07-16 22:36:24 UTC (rev 91360)
@@ -42,10 +42,11 @@
// Contracts --------------------------------------------------------------------||
//-------------------------------------------------------------------------------||
- // /**
- // * Deploys the specified deployment into the server
- // */
- // void deploy(VirtualDeploymentGroup deployment);
+ /*
+ * Add methods to:
+ * 1) Deploy a Collection of Deployments at once (maindeployer.add, then process)
+ * 2) Undeploy a Collection of Deployments at once
+ */
/**
* Deploys the specified deployment into the server
@@ -57,11 +58,31 @@
void deploy(Deployment deployment) throws DeploymentException, IllegalArgumentException;
/**
- * Deploys the specified deployment into the server
+ * Deploys the specified archive into the server
*
- * @param deployment
+ * @param archive
* @throws DeploymentException
* @throws IllegalArgumentException If the deployment was not specified
*/
- void deploy(VirtualVfsArchive deployment) throws DeploymentException, IllegalArgumentException;
+ void deploy(VirtualVfsArchive archive) throws DeploymentException, IllegalArgumentException;
+
+ /**
+ * Undeploys the specified deployment
+ *
+ * @param deployment
+ * @throws IllegalArgumentException If the archive is not deployed or
+ * not specified
+ * @throws DeploymentException
+ */
+ void undeploy(Deployment deployment) throws IllegalArgumentException, DeploymentException;
+
+ /**
+ * Undeploys the specified archive
+ *
+ * @param archive
+ * @throws IllegalArgumentException If the archive is not deployed or
+ * not specified
+ * @throws DeploymentException
+ */
+ void undeploy(VirtualVfsArchive archive) throws IllegalArgumentException, DeploymentException;
}
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java 2009-07-16 22:07:01 UTC (rev 91359)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java 2009-07-16 22:36:24 UTC (rev 91360)
@@ -21,6 +21,10 @@
*/
package org.jboss.embedded.core.server;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.jboss.bootstrap.impl.as.config.BasicJBossASServerConfig;
import org.jboss.bootstrap.impl.as.server.AbstractJBossASServerBase;
import org.jboss.bootstrap.spi.as.config.JBossASServerConfig;
@@ -80,6 +84,15 @@
private static final String MC_NAME_MAIN_DEPLOYER = "MainDeployer";
//-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * A mapping of virtual archives to their resultant deployments (so we can undeploy archives)
+ */
+ private final Map<VirtualVfsArchive, Deployment> virtualArchiveDeployments = new ConcurrentHashMap<VirtualVfsArchive, Deployment>();;
+
+ //-------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -129,8 +142,8 @@
*/
public JBossASEmbeddedServerImpl(final String jbossHome) throws IllegalArgumentException
{
- // Call the other ctor
- this();
+ // Call super
+ super(JBossASEmbeddedServer.class);
// Init
this.initialize(jbossHome);
@@ -152,42 +165,77 @@
throw new IllegalArgumentException("deployment must be specified");
}
- // Get the MainDeployer
- final Kernel kernel = this.getKernel();
- final KernelController controller = kernel.getController();
- final ControllerContext context = controller.getContext(MC_NAME_MAIN_DEPLOYER, ControllerState.INSTALLED);
- if (context == null)
- {
- throw new IllegalStateException("Main deployer could not be found");
- }
- final Object target = context.getTarget();
- final MainDeployer mainDeployer = MainDeployer.class.cast(target);
-
// Deploy and check all's OK
+ final MainDeployer mainDeployer = this.getMainDeployer();
mainDeployer.deploy(deployment);
mainDeployer.checkComplete();
}
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.embedded.core.deployment.VirtualDeployment)
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive)
*/
@Override
- public void deploy(final VirtualVfsArchive deployment) throws DeploymentException, IllegalArgumentException
+ public void deploy(final VirtualVfsArchive archive) throws DeploymentException, IllegalArgumentException
{
// Precondition check
- if (deployment == null)
+ if (archive == null)
{
throw new IllegalArgumentException("deployment must be specified");
}
// Make a VFS Deployment
- final VirtualFile root = deployment.getRoot();
+ final VirtualFile root = archive.getRoot();
final Deployment d = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
// Deploy
this.deploy(d);
+
+ // Add to the map (so we can undeploy the archive later)
+ this.virtualArchiveDeployments.put(archive, d);
}
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#undeploy(org.jboss.deployers.client.spi.Deployment)
+ */
+ @Override
+ public void undeploy(final Deployment deployment) throws IllegalArgumentException, DeploymentException
+ {
+ // Get the MainDeployer
+ final MainDeployer mainDeployer = this.getMainDeployer();
+
+ // Undeploy
+ log.debug("Undeploying: " + deployment);
+ mainDeployer.undeploy(deployment);
+ log.debug("Undeployed: " + deployment);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#undeploy(org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive)
+ */
+ @Override
+ public void undeploy(final VirtualVfsArchive archive) throws IllegalArgumentException, DeploymentException
+ {
+ // Precondition check
+ if (archive == null)
+ {
+ throw new IllegalArgumentException("archive must be specified");
+ }
+
+ // Get the corresponding deployment
+ final Deployment deployment = this.getVirtualArchiveDeployments().get(archive);
+ if (deployment == null)
+ {
+ throw new IllegalArgumentException("The specified archive has not been deployed: " + archive.toString(true));
+ }
+
+ // Undeploy
+ this.undeploy(deployment);
+
+ // Remove from the map
+ this.virtualArchiveDeployments.remove(archive);
+ }
+
/*
* (non-Javadoc)
* @see org.jboss.bootstrap.impl.base.server.AbstractServer#getDefaultServerConfigClass()
@@ -265,4 +313,38 @@
// }
}
+ /**
+ * Obtains the MainDeployer via MC
+ * @return
+ */
+ protected final MainDeployer getMainDeployer()
+ {
+ // Get the MainDeployer
+ final Kernel kernel = this.getKernel();
+ final KernelController controller = kernel.getController();
+ final ControllerContext context = controller.getContext(MC_NAME_MAIN_DEPLOYER, ControllerState.INSTALLED);
+ if (context == null)
+ {
+ throw new IllegalStateException("Main deployer could not be found");
+ }
+ final Object target = context.getTarget();
+ final MainDeployer mainDeployer = MainDeployer.class.cast(target);
+
+ // Return
+ return mainDeployer;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns an immutable view of the archives/deployments map
+ * @return the virtualArchiveDeployments
+ */
+ protected final Map<VirtualVfsArchive, Deployment> getVirtualArchiveDeployments()
+ {
+ return Collections.unmodifiableMap(virtualArchiveDeployments);
+ }
+
}
Modified: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-16 22:07:01 UTC (rev 91359)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-16 22:36:24 UTC (rev 91360)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -58,9 +57,6 @@
import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
import org.jboss.embedded.core.server.JBossASEmbeddedServer;
import org.jboss.embedded.core.server.JBossASEmbeddedServerImpl;
-import org.jboss.embedded.testsuite.fulldep.ejb3.entity.Jbossian;
-import org.jboss.embedded.testsuite.fulldep.ejb3.entity.JbossianRegistrarBean;
-import org.jboss.embedded.testsuite.fulldep.ejb3.entity.JbossianRegistrarLocalBusiness;
import org.jboss.embedded.testsuite.fulldep.ejb3.mdb.MessageStoringMdb;
import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputBean;
import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputLocalBusiness;
@@ -246,12 +242,12 @@
// Make a deployment
final String name = "slsb.jar";
- final VirtualVfsArchive deployment = new VirtualVfsArchiveImpl(name).addClasses(OutputBean.class,
+ final VirtualVfsArchive archive = new VirtualVfsArchiveImpl(name).addClasses(OutputBean.class,
OutputLocalBusiness.class);
- log.info(deployment.toString(true));
+ log.info(archive.toString(true));
// Deploy
- server.deploy(deployment);
+ server.deploy(archive);
// Test
final OutputLocalBusiness bean = (OutputLocalBusiness) NAMING_CONTEXT.lookup(OutputBean.class.getSimpleName()
@@ -260,6 +256,9 @@
log.info("Got output: " + output);
Assert.assertEquals(OutputLocalBusiness.OUTPUT, output);
+ // Undeploy
+ server.undeploy(archive);
+
}
/**
@@ -291,12 +290,12 @@
final String appName = "testServletJsp";
final String name = appName + ".war";
final Class<?> servletClass = JspForwardingServlet.class;
- final VirtualVfsArchive deployment = new VirtualVfsArchiveImpl(name).addResource(locationWebXml, newPathWebXml)
+ final VirtualVfsArchive archive = new VirtualVfsArchiveImpl(name).addResource(locationWebXml, newPathWebXml)
.addResource(locationJsp, PATH_JSP).addClass(servletClass);
- log.info(deployment.toString(true));
+ log.info(archive.toString(true));
// Deploy
- server.deploy(deployment);
+ server.deploy(archive);
// Get an HTTP Client
final HttpClient client = new DefaultHttpClient();
@@ -324,6 +323,9 @@
final String line = reader.readLine();
log.info("Got response: " + line);
Assert.assertEquals(echoValue, line);
+
+ // Undeploy
+ server.undeploy(archive);
}
/**
@@ -341,13 +343,12 @@
log.info("testJmsAndMdb");
// Create a virtual archive for the MDB deployment
- final VirtualVfsArchive deployment = new VirtualVfsArchiveImpl("jms-mdb-test.jar").addClass(
- MessageStoringMdb.class).addResource(new URL(this.getBase(), PATH_QUEUE_SERVICE_XML),
- FILENAME_QUEUE_SERVICE_XML);
+ final VirtualVfsArchive archive = new VirtualVfsArchiveImpl("jms-mdb-test.jar").addClass(MessageStoringMdb.class)
+ .addResource(new URL(this.getBase(), PATH_QUEUE_SERVICE_XML), FILENAME_QUEUE_SERVICE_XML);
// Deploy
- log.info(deployment.toString(true));
- server.deploy(deployment);
+ log.info(archive.toString(true));
+ server.deploy(archive);
// Define a String message to send
final String message = "From in-JVM Test Message";
@@ -378,6 +379,9 @@
// Ensure equal
Assert.assertEquals("The test message received was not as expected", message, received);
+ // Undeploy
+ server.undeploy(archive);
+
}
/*
@@ -387,58 +391,58 @@
* (so we explicitly put it there in persistence.xml)
* 2) Permgen / OOM problems, even on huge heap. Why?
*/
-// /**
-// * Tests deployment of a JCA DataSource and EJB3 Entity Bean (JPA)
-// *
-// * A test SLSB will also be used to create a few rows in the DB,
-// * then obtain all.
-// *
-// * @throws Exception
-// */
-// @Test
-// public void testDataSourceAndEntity() throws Exception
-// {
-// // Log
-// log.info("testDataSourceAndEntity");
-//
-// // Create a virtual archive for DS, persistence.xml, Entity, and SLSB
-// final URL base = this.getBase();
-// final VirtualVfsArchive deployment = new VirtualVfsArchiveImpl("datasource-entity-test.jar").addClasses(
-// Jbossian.class, JbossianRegistrarLocalBusiness.class, JbossianRegistrarBean.class).addResource(
-// new URL(base, PATH_RESOURCE_DS_XML_EMBEDDED), FILENAME_EMBEDDED_DS).addResource(
-// new URL(base, PATH_RESOURCE_PERSISTENCE_XML_EMBEDDED), PATH_DESTINATION_PERSISTENCE_XML);
-//
-// // Deploy
-// log.info(deployment.toString(true));
-// server.deploy(deployment);
-//
-// // Make some JBossians
-// final Jbossian jgreene = new Jbossian("Jason T. Greene", "AS Hole", 12);
-// final Jbossian jpederse = new Jbossian("Jesper Pedersen", "Professional Tattletale", 21);
-// final Jbossian dmlloyd = new Jbossian("David M. Lloyd", "???????", 15);
-// final Jbossian wolfc = new Jbossian("Carlo de Wolf", "Head of Deep Voice", 13);
-// final Jbossian alr = new Jbossian("Andew Lee Rubinger", "The New Fluery", 58);
-// final Jbossian asaldhan = new Jbossian("Anil Saldhana", "Karma Police", 23);
-//
-// // Get an SLSB to interact w/ the DB
-// final JbossianRegistrarLocalBusiness slsb = (JbossianRegistrarLocalBusiness) NAMING_CONTEXT
-// .lookup(JbossianRegistrarBean.class.getSimpleName() + JNDI_SUFFIX_LOCAL_BUSINESS);
-//
-// // Add the JBossians
-// slsb.add(jgreene);
-// slsb.add(jpederse);
-// slsb.add(dmlloyd);
-// slsb.add(wolfc);
-// slsb.add(alr);
-// slsb.add(asaldhan);
-//
-// // Get all
-// final Collection<Jbossian> jbossians = slsb.getAllJbossians();
-// log.info("Got all JBossians: " + jbossians);
-//
-// // Test
-// Assert.assertEquals(6, jbossians.size());
-// }
+ // /**
+ // * Tests deployment of a JCA DataSource and EJB3 Entity Bean (JPA)
+ // *
+ // * A test SLSB will also be used to create a few rows in the DB,
+ // * then obtain all.
+ // *
+ // * @throws Exception
+ // */
+ // @Test
+ // public void testDataSourceAndEntity() throws Exception
+ // {
+ // // Log
+ // log.info("testDataSourceAndEntity");
+ //
+ // // Create a virtual archive for DS, persistence.xml, Entity, and SLSB
+ // final URL base = this.getBase();
+ // final VirtualVfsArchive deployment = new VirtualVfsArchiveImpl("datasource-entity-test.jar").addClasses(
+ // Jbossian.class, JbossianRegistrarLocalBusiness.class, JbossianRegistrarBean.class).addResource(
+ // new URL(base, PATH_RESOURCE_DS_XML_EMBEDDED), FILENAME_EMBEDDED_DS).addResource(
+ // new URL(base, PATH_RESOURCE_PERSISTENCE_XML_EMBEDDED), PATH_DESTINATION_PERSISTENCE_XML);
+ //
+ // // Deploy
+ // log.info(deployment.toString(true));
+ // server.deploy(deployment);
+ //
+ // // Make some JBossians
+ // final Jbossian jgreene = new Jbossian("Jason T. Greene", "AS Hole", 12);
+ // final Jbossian jpederse = new Jbossian("Jesper Pedersen", "Professional Tattletale", 21);
+ // final Jbossian dmlloyd = new Jbossian("David M. Lloyd", "???????", 15);
+ // final Jbossian wolfc = new Jbossian("Carlo de Wolf", "Head of Deep Voice", 13);
+ // final Jbossian alr = new Jbossian("Andew Lee Rubinger", "The New Fluery", 58);
+ // final Jbossian asaldhan = new Jbossian("Anil Saldhana", "Karma Police", 23);
+ //
+ // // Get an SLSB to interact w/ the DB
+ // final JbossianRegistrarLocalBusiness slsb = (JbossianRegistrarLocalBusiness) NAMING_CONTEXT
+ // .lookup(JbossianRegistrarBean.class.getSimpleName() + JNDI_SUFFIX_LOCAL_BUSINESS);
+ //
+ // // Add the JBossians
+ // slsb.add(jgreene);
+ // slsb.add(jpederse);
+ // slsb.add(dmlloyd);
+ // slsb.add(wolfc);
+ // slsb.add(alr);
+ // slsb.add(asaldhan);
+ //
+ // // Get all
+ // final Collection<Jbossian> jbossians = slsb.getAllJbossians();
+ // log.info("Got all JBossians: " + jbossians);
+ //
+ // // Test
+ // Assert.assertEquals(6, jbossians.size());
+ // }
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
More information about the jboss-cvs-commits
mailing list