001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.kernel.deployment.jboss;
023:
024: import org.jboss.dependency.spi.ControllerMode;
025: import org.jboss.dependency.spi.ControllerState;
026: import org.jboss.deployment.DeploymentException;
027: import org.jboss.deployment.DeploymentInfo;
028: import org.jboss.kernel.Kernel;
029: import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
030: import org.jboss.kernel.plugins.deployment.AbstractKernelDeployer;
031: import org.jboss.kernel.spi.deployment.KernelDeployment;
032: import org.jboss.system.ServiceMBeanSupport;
033: import org.jboss.util.UnreachableStatementException;
034:
035: /**
036: * A jboss bean deployment
037: *
038: * @author <a href="adrian@jboss.com">Adrian Brock</a>
039: * @version $Revision: 57210 $
040: */
041: public class JBossBeanDeployment extends ServiceMBeanSupport implements
042: JBossBeanDeploymentMBean {
043: /** The deployment info */
044: protected DeploymentInfo di;
045:
046: /** The deployment */
047: protected KernelDeployment deployment;
048:
049: /** The kernel deployer */
050: protected AbstractKernelDeployer deployer;
051:
052: /**
053: * Create a new deployment
054: *
055: * @param di the deployment info
056: */
057: public JBossBeanDeployment(DeploymentInfo di) {
058: this .di = di;
059: this .deployment = (KernelDeployment) di.metaData;
060: }
061:
062: protected void createService() throws Exception {
063: Kernel kernel = getKernel();
064: deployer = new AbstractKernelDeployer(kernel,
065: ControllerState.CREATE, ControllerMode.MANUAL);
066: try {
067: deployer.deploy(deployment);
068: } catch (Throwable t) {
069: DeploymentException.rethrowAsDeploymentException(
070: "Cannot deploy " + deployment, t);
071: }
072: }
073:
074: protected void startService() throws Exception {
075: try {
076: deployer.change(deployment, ControllerState.INSTALLED);
077: deployer.validate(deployment);
078: } catch (Throwable t) {
079: DeploymentException.rethrowAsDeploymentException(
080: "Cannot start " + deployment, t);
081: }
082: }
083:
084: protected void stopService() throws Exception {
085: try {
086: deployer.change(deployment, ControllerState.CREATE);
087: } catch (Throwable t) {
088: DeploymentException.rethrowAsDeploymentException(
089: "Cannot stop " + deployment, t);
090: }
091: }
092:
093: protected void destroyService() throws Exception {
094: try {
095: if (deployer != null)
096: deployer.undeploy(deployment);
097: } catch (Throwable t) {
098: DeploymentException.rethrowAsDeploymentException(
099: "Cannot stop " + deployment, t);
100: }
101: deployer = null;
102: }
103:
104: /**
105: * Get the kernel for this deployment
106: *
107: * @return the kernel
108: */
109: protected Kernel getKernel() throws DeploymentException {
110: try {
111: BasicBootstrap bootstrap = new BasicBootstrap();
112: bootstrap.run();
113: return bootstrap.getKernel();
114: } catch (Throwable t) {
115: DeploymentException.rethrowAsDeploymentException(
116: "Unable to boot kernel", t);
117: throw new UnreachableStatementException();
118: }
119: }
120: }
|