KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > factory > EJBModuleFactory


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, 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.management.j2ee.factory;
23
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import javax.management.MBeanServer JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29
30 import org.jboss.deployment.DeploymentInfo;
31 import org.jboss.ejb.EjbModule;
32 import org.jboss.logging.Logger;
33 import org.jboss.management.j2ee.EJB;
34 import org.jboss.management.j2ee.EJBModule;
35 import org.jboss.metadata.BeanMetaData;
36 import org.jboss.metadata.SessionMetaData;
37
38 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
39
40 /**
41  * A factory for mapping EJBDeployer deployments to EJBModule
42  *
43  * @author Scott.Stark@jboss.org
44  * @version $Revision: 42697 $
45  */

46 public class EJBModuleFactory
47         implements ManagedObjectFactory
48 {
49    private static Logger log = Logger.getLogger(EJBModuleFactory.class);
50    private static Map JavaDoc moduleServiceToMgmtMap = new ConcurrentReaderHashMap();
51    private Map JavaDoc deploymentToModuleNameMap = new ConcurrentReaderHashMap();
52    private Map JavaDoc containerToModuleNameMap = new ConcurrentReaderHashMap();
53
54    static ObjectName JavaDoc getEJBModuleName(ObjectName JavaDoc ejbModuleService)
55    {
56       ObjectName JavaDoc jsr77Name = (ObjectName JavaDoc) moduleServiceToMgmtMap.get(ejbModuleService);
57       return jsr77Name;
58    }
59
60    /**
61     * Create JSR-77 EJBModule
62     *
63     * @param server the MBeanServer context
64     * @param data arbitrary data associated with the creation context
65     */

66    public ObjectName JavaDoc create(MBeanServer JavaDoc server, Object JavaDoc data)
67    {
68       if ((data instanceof DeploymentInfo) == false)
69          return null;
70
71       DeploymentInfo di = (DeploymentInfo) data;
72       String JavaDoc ejbJarName = di.shortName;
73       ObjectName JavaDoc ejbModuleService = di.deployedObject;
74       ObjectName JavaDoc jsr77Name = EJBModule.create(server,
75               (di.parent == null ? null : di.parent.shortName),
76               ejbJarName,
77               di.localUrl,
78               ejbModuleService);
79       moduleServiceToMgmtMap.put(ejbModuleService, jsr77Name);
80       deploymentToModuleNameMap.put(di, jsr77Name);
81       log.debug("Created module: " + jsr77Name);
82       Iterator JavaDoc ejbs = di.mbeans.iterator();
83       while (ejbs.hasNext())
84       {
85          ObjectName JavaDoc containerName = (ObjectName JavaDoc) ejbs.next();
86          createEJB(server, containerName);
87       }
88       return jsr77Name;
89    }
90
91    /**
92     * Destroy JSR-77 EJBModule
93     *
94     * @param server the MBeanServer context
95     * @param data arbitrary data associated with the creation context
96     */

97    public void destroy(MBeanServer JavaDoc server, Object JavaDoc data)
98    {
99       if ((data instanceof DeploymentInfo) == false)
100          return;
101
102       DeploymentInfo di = (DeploymentInfo) data;
103       ObjectName JavaDoc jsr77Name = (ObjectName JavaDoc) deploymentToModuleNameMap.remove(di);
104
105       log.debug("Destroy module: " + jsr77Name);
106       Iterator JavaDoc ejbs = di.mbeans.iterator();
107       while (ejbs.hasNext())
108       {
109          ObjectName JavaDoc containerName = (ObjectName JavaDoc) ejbs.next();
110          destroyEJB(server, containerName);
111       }
112       
113       if (jsr77Name != null)
114       {
115          EJBModule.destroy(server, jsr77Name);
116       }
117
118       ObjectName JavaDoc ejbModuleService = di.deployedObject;
119       if (ejbModuleService != null)
120          containerToModuleNameMap.remove(ejbModuleService);
121    }
122
123    /**
124     Create an EJB mbean for the container
125
126     @param server - the deployment server
127     @param containerName - the internal ejb container jmx name
128     @return JSR77 ObjectName of the EJB mbean subtype
129     */

130    public ObjectName JavaDoc createEJB(MBeanServer JavaDoc server, ObjectName JavaDoc containerName)
131    {
132       ObjectName JavaDoc jsr77Name = null;
133       try
134       {
135          BeanMetaData metaData = (BeanMetaData) server.getAttribute(containerName, "BeanMetaData");
136          EjbModule ejbModule = (EjbModule) server.getAttribute(containerName, "EjbModule");
137          ObjectName JavaDoc ejbModName = EJBModuleFactory.getEJBModuleName(ejbModule.getServiceName());
138          String JavaDoc ejbName = metaData.getEjbName();
139          String JavaDoc jndiName = metaData.getJndiName();
140          String JavaDoc localJndiName = metaData.getLocalJndiName();
141          int type = EJB.STATELESS_SESSION_BEAN;
142          if (metaData.isSession())
143          {
144             SessionMetaData smetaData = (SessionMetaData) metaData;
145             if (smetaData.isStateful())
146                type = EJB.STATEFUL_SESSION_BEAN;
147          }
148          else if (metaData.isMessageDriven())
149             type = EJB.MESSAGE_DRIVEN_BEAN;
150          else
151             type = EJB.ENTITY_BEAN;
152
153          
154          jsr77Name = EJB.create(server, ejbModName, containerName, type,
155             ejbName, jndiName, localJndiName);
156          containerToModuleNameMap.put(containerName, jsr77Name);
157          log.debug("Create container: " + containerName + ", module: " + jsr77Name);
158       }
159       catch (Exception JavaDoc e)
160       {
161          log.debug("", e);
162       }
163
164       return jsr77Name;
165    }
166
167    /**
168     * Destory JSR-77 J2EEApplication
169     *
170     * @param server the MBeanServer context
171     * @param containerName arbitrary data associated with the creation context
172     */

173    public void destroyEJB(MBeanServer JavaDoc server, ObjectName JavaDoc containerName)
174    {
175       ObjectName JavaDoc jsr77Name = (ObjectName JavaDoc) containerToModuleNameMap.get(containerName);
176
177       log.debug("Destroy container: " + containerName + ", module: " + jsr77Name);
178       if (jsr77Name != null)
179       {
180          EJB.destroy(server, jsr77Name);
181       }
182    }
183
184 }
185
Popular Tags