KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > deployment > BasicKernelDeployer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.kernel.plugins.deployment;
23
24 import java.util.List JavaDoc;
25 import java.util.ListIterator JavaDoc;
26
27 import org.jboss.kernel.Kernel;
28 import org.jboss.kernel.spi.deployment.KernelDeployment;
29 import org.jboss.logging.Logger;
30 import org.jboss.util.collection.CollectionsFactory;
31
32 /**
33  * BasicKernelDeployer.<p>
34  *
35  * An extension to the abstract kernel deployer that keeps track
36  * of deployments and adds a simple shutdown method.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 45764 $
40  */

41 public class BasicKernelDeployer extends AbstractKernelDeployer
42 {
43    /** The log */
44    private static final Logger log = Logger.getLogger(BasicKernelDeployer.class);
45
46    /** The deployments */
47    protected List JavaDoc<KernelDeployment> deployments = CollectionsFactory.createCopyOnWriteList();
48
49    /**
50     * Create a new BasicKernelDeployer.
51     *
52     * @param kernel the kernel
53     */

54    public BasicKernelDeployer(Kernel kernel)
55    {
56       super(kernel);
57    }
58
59    public void deploy(KernelDeployment deployment) throws Throwable JavaDoc
60    {
61       final boolean trace = log.isTraceEnabled();
62       if (trace)
63          log.trace("Deploying " + deployment);
64       super.deploy(deployment);
65       deployments.add(deployment);
66       if (trace)
67          log.trace("Deployed " + deployment);
68    }
69
70    public void undeploy(KernelDeployment deployment)
71    {
72       final boolean trace = log.isTraceEnabled();
73       if (trace)
74          log.trace("Undeploying " + deployment);
75       deployments.remove(deployment);
76       super.undeploy(deployment);
77       if (trace)
78          log.trace("Undeployed " + deployment);
79    }
80
81    /**
82     * Shutdown the deployer (undeploys everything)
83     */

84    public void shutdown()
85    {
86       ListIterator JavaDoc iterator = deployments.listIterator(deployments.size());
87       while (iterator.hasPrevious())
88       {
89          KernelDeployment deployment = (KernelDeployment) iterator.previous();
90          undeploy(deployment);
91       }
92    }
93 }
94
Popular Tags