KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > deployment > jboss > MainDeployerFacade


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.server.deployment.jboss;
10
11 import org.jboss.deployment.DeploymentException;
12 import org.jboss.deployment.MainDeployerMBean;
13 import org.jboss.portal.server.util.Service;
14
15 import java.net.URL JavaDoc;
16
17 /**
18  * @jmx.mbean
19  * @jboss.xmbean
20  *
21  * This is a hack for testing. We log the deployment exception in the MainDeployerProxy that keeps
22  * exception in a thread local and rethrow them once deployment is finished. We are forced to do that
23  * because the deployment mechanism we have is based on JMX notifications isolate the two deployment
24  * layers (JBoss AS and JBoss Portal).
25  *
26  * Having deployment interception will solve the problem.
27  *
28  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
29  * @version $Revision: 1.1 $
30  */

31 public class MainDeployerFacade extends Service
32 {
33
34    /** Keep a thread local of sessions. */
35    private static final ThreadLocal JavaDoc local = new ThreadLocal JavaDoc();
36
37    public static void log(DeploymentException e)
38    {
39       // Record the exception only if we have a session otherwise we may leek the exception in the thread local
40
Session session = (Session)local.get();
41       if (session != null && session.e == null)
42       {
43          session.e = e;
44       }
45    }
46
47    /** The main deployer delegate. */
48    private MainDeployerMBean mainDeployer;
49
50    /**
51     * @jmx.managed-attribute
52     */

53    public MainDeployerMBean getMainDeployer()
54    {
55       return mainDeployer;
56    }
57
58    /**
59     * @jmx.managed-attribute
60     */

61    public void setMainDeployer(MainDeployerMBean mainDeployer)
62    {
63       this.mainDeployer = mainDeployer;
64    }
65
66    /**
67     * @jmx.managed-operation
68     * @jmx.managed-parameter
69     * name="url"
70     * type="java.net.URL"
71     */

72    public void deploy(URL JavaDoc url) throws DeploymentException
73    {
74       perform(url, true);
75    }
76
77    /**
78     * @jmx.managed-operation
79     * @jmx.managed-parameter
80     * name="url"
81     * type="java.net.URL"
82     */

83    public void undeploy(URL JavaDoc url) throws DeploymentException
84    {
85       perform(url, false);
86    }
87
88    private void perform(URL JavaDoc url, boolean deploy) throws DeploymentException
89    {
90       try
91       {
92          Session session = new Session();
93          local.set(session);
94
95          // The main deployer could throw an exception but that will be an exception not related to jboss portal
96
if (deploy)
97          {
98             mainDeployer.deploy(url);
99          }
100          else
101          {
102             mainDeployer.undeploy(url);
103          }
104
105          // If e is not null that means an exception was thrown into jboss portal layer and we rethrow it
106
// to the client
107
if (session.e != null)
108          {
109             throw session.e;
110          }
111       }
112       finally
113       {
114          local.set(null);
115       }
116    }
117
118    /**
119     * Just a place holder for the deployment exception.
120     */

121    private static class Session
122    {
123       private DeploymentException e;
124    }
125 }
126
Popular Tags