KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > deployers > RARDeployment


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.resource.deployers;
23
24 import java.net.URL JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Timer JavaDoc;
28
29 import javax.management.Attribute JavaDoc;
30 import javax.management.AttributeNotFoundException JavaDoc;
31 import javax.management.InvalidAttributeValueException JavaDoc;
32 import javax.management.MBeanAttributeInfo JavaDoc;
33 import javax.management.MBeanException JavaDoc;
34 import javax.management.MBeanOperationInfo JavaDoc;
35 import javax.management.MBeanParameterInfo JavaDoc;
36 import javax.management.ReflectionException JavaDoc;
37 import javax.resource.spi.ActivationSpec JavaDoc;
38 import javax.resource.spi.BootstrapContext JavaDoc;
39 import javax.resource.spi.ResourceAdapter JavaDoc;
40 import javax.resource.spi.UnavailableException JavaDoc;
41 import javax.resource.spi.XATerminator JavaDoc;
42 import javax.resource.spi.endpoint.MessageEndpointFactory JavaDoc;
43 import javax.resource.spi.work.WorkManager JavaDoc;
44
45 import org.jboss.deployment.DeploymentException;
46 import org.jboss.resource.deployment.ActivationSpecFactory;
47 import org.jboss.resource.deployment.ResourceAdapterFactory;
48 import org.jboss.resource.metadata.ConfigPropertyMetaData;
49 import org.jboss.resource.metadata.ConnectorMetaData;
50 import org.jboss.resource.metadata.DescriptionGroupMetaData;
51 import org.jboss.resource.metadata.MessageListenerMetaData;
52 import org.jboss.system.ServiceDynamicMBeanSupport;
53 import org.jboss.system.server.ServerConfigUtil;
54
55 /**
56  * A resource adapter deployment
57  *
58  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
59  * @version $Revision: 46109 $
60  */

61 public class RARDeployment extends ServiceDynamicMBeanSupport implements BootstrapContext JavaDoc
62 {
63    /** The RARDeploymentMetaData */
64    /* TODO protected RARDeploymentMetaData rdmd; */
65    
66    /** The ConnectorMetaData */
67    protected ConnectorMetaData cmd;
68    
69    /** The JBossRAMetaData */
70    /* TODO protected JBossRAMetaData ramd; */
71    
72    /** The resource adapter */
73    protected ResourceAdapter JavaDoc resourceAdapter;
74
75    /** The work manager */
76    private WorkManager JavaDoc workManager;
77
78    /** The xa terminator */
79    private XATerminator JavaDoc xaTerminator;
80    
81    /**
82     * Create a new RAR deployment
83     *
84     * @param cmd the metadata
85     */

86    public RARDeployment(ConnectorMetaData cmd)
87    {
88       if (cmd == null)
89          throw new IllegalArgumentException JavaDoc("Null metadata");
90       this.cmd = cmd;
91       /* TODO this.ramd = rdmd.getRaXmlMetaData(); */
92       
93    }
94
95    public Timer JavaDoc createTimer() throws UnavailableException JavaDoc
96    {
97       return new Timer JavaDoc(true);
98    }
99
100    /**
101     * Get the workManager.
102     *
103     * @return the workManager.
104     */

105    public WorkManager JavaDoc getWorkManager()
106    {
107       return workManager;
108    }
109
110    /**
111     * Set the workManager.
112     *
113     * @param workManager the workManager.
114     */

115    public void setWorkManager(WorkManager JavaDoc workManager)
116    {
117       this.workManager = workManager;
118    }
119
120    /**
121     * Get the XATerminator.
122     *
123     * @return the xaTerminator.
124     */

125    public XATerminator JavaDoc getXATerminator()
126    {
127       return xaTerminator;
128    }
129
130    /**
131     * Set the xXATerminator.
132     *
133     * @param xaTerminator the XATerminator.
134     */

135    public void setXATerminator(XATerminator JavaDoc xaTerminator)
136    {
137       this.xaTerminator = xaTerminator;
138    }
139
140    protected void startService() throws Exception JavaDoc
141    {
142       URL JavaDoc url = cmd.getURL();
143       
144       if (cmd.getLicense().getRequired())
145       {
146          log.info ("Required license terms exist, view " + ServerConfigUtil.shortUrlFromServerHome(url.toString()));
147          log.debug("License terms full URL: " + url);
148       }
149       resourceAdapter = ResourceAdapterFactory.createResourceAdapter(cmd);
150       resourceAdapter.start(this);
151    }
152    
153    protected void stopService() throws Exception JavaDoc
154    {
155       resourceAdapter.stop();
156    }
157    
158    protected String JavaDoc getInternalDescription()
159    {
160       String JavaDoc description = null;
161       DescriptionGroupMetaData dgmd = cmd.getDescription();
162       if (dgmd != null)
163          description = dgmd.getDescription();
164       if (description == null)
165          description = "RAR Deployment " + cmd.getURL();
166       return description;
167    }
168
169    protected MBeanAttributeInfo JavaDoc[] getInternalAttributeInfo()
170    {
171       Collection JavaDoc properties = cmd.getProperties();
172       MBeanAttributeInfo JavaDoc[] attrs = new MBeanAttributeInfo JavaDoc[13+properties.size()];
173       attrs[0] = new MBeanAttributeInfo JavaDoc("MetaData", ConnectorMetaData.class.getName(), "The meta data", true, false, false);
174       attrs[1] = new MBeanAttributeInfo JavaDoc("AuthenticationMechanism", String JavaDoc.class.getName(), "The authentication mechanism", true, false, false);
175       attrs[2] = new MBeanAttributeInfo JavaDoc("EISType", String JavaDoc.class.getName(), "The EIS type", true, false, false);
176       attrs[3] = new MBeanAttributeInfo JavaDoc("License", String JavaDoc.class.getName(), "The license", true, false, false);
177       attrs[4] = new MBeanAttributeInfo JavaDoc("RAClass", String JavaDoc.class.getName(), "The resource adapter class", true, false, false);
178       attrs[5] = new MBeanAttributeInfo JavaDoc("RAVersion", String JavaDoc.class.getName(), "The resource adapter version", true, false, false);
179       attrs[6] = new MBeanAttributeInfo JavaDoc("TransactionSupport", String JavaDoc.class.getName(), "The transaction support", true, false, false);
180       attrs[7] = new MBeanAttributeInfo JavaDoc("VendorName", String JavaDoc.class.getName(), "The vendor name", true, false, false);
181       attrs[8] = new MBeanAttributeInfo JavaDoc("Version", String JavaDoc.class.getName(), "The spec version", true, false, false);
182       attrs[9] = new MBeanAttributeInfo JavaDoc("ReauthenticationSupport", Boolean.TYPE.getName(), "Whether reauthentication support is supported", true, false, false);
183       attrs[10] = new MBeanAttributeInfo JavaDoc("ResourceAdapter", ResourceAdapter JavaDoc.class.getName(), "The resource adapter instance", true, false, false);
184       attrs[11] = new MBeanAttributeInfo JavaDoc("WorkManager", WorkManager JavaDoc.class.getName(), "The work manager", true, true, false);
185       attrs[12] = new MBeanAttributeInfo JavaDoc("XATerminator", XATerminator JavaDoc.class.getName(), "The xa terminator", true, true, false);
186       int n = 13;
187       for (Iterator JavaDoc i = properties.iterator(); i.hasNext();)
188       {
189          ConfigPropertyMetaData cpmd = (ConfigPropertyMetaData) i.next();
190          attrs[n++] = new MBeanAttributeInfo JavaDoc(cpmd.getName(), cpmd.getType(), cpmd.getDescription().getDescription(), true, false, false);
191       }
192       return attrs;
193    }
194    
195    protected Object JavaDoc getInternalAttribute(String JavaDoc attribute)
196       throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
197    {
198       if ("MetaData".equals(attribute))
199          return cmd;
200       else if ("AuthenticationMechanism".equals(attribute))
201          return cmd.getAuthenticationMechanism().getAuthenticationMechansimType();
202       else if ("EISType".equals(attribute))
203          return cmd.getEISType();
204       else if ("License".equals(attribute))
205          return cmd.getLicense().getDescription().getDescription();
206       else if ("RAClass".equals(attribute))
207          return cmd.getRAClass();
208       else if ("RAVersion".equals(attribute))
209          return cmd.getRAVersion();
210       else if ("TransactionSupport".equals(attribute))
211          return cmd.getTransactionSupport();
212       else if ("VendorName".equals(attribute))
213          return cmd.getVendorName();
214       else if ("Version".equals(attribute))
215          return cmd.getVersion();
216       else if ("ReauthenticationSupport".equals(attribute))
217          return new Boolean JavaDoc(cmd.getReauthenticationSupport());
218       else if ("ResourceAdapter".equals(attribute))
219          return resourceAdapter;
220       else if ("WorkManager".equals(attribute))
221          return workManager;
222       else if ("XATerminator".equals(attribute))
223          return xaTerminator;
224       Object JavaDoc property = cmd.getProperty(attribute);
225       if (property != null)
226          return property;
227       
228       return super.getInternalAttribute(attribute);
229    }
230
231    protected void setInternalAttribute(Attribute JavaDoc attribute) throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
232    {
233       String JavaDoc name = attribute.getName();
234       if ("WorkManager".equals(name))
235          this.workManager = (WorkManager JavaDoc) attribute.getValue();
236       else if ("XATerminator".equals(name))
237          this.xaTerminator = (XATerminator JavaDoc) attribute.getValue();
238       else
239          super.setInternalAttribute(attribute);
240    }
241
242    protected MBeanOperationInfo JavaDoc[] getInternalOperationInfo()
243    {
244       MBeanOperationInfo JavaDoc[] ops = new MBeanOperationInfo JavaDoc[3];
245
246       MBeanParameterInfo JavaDoc[] createActivationSpecParams = new MBeanParameterInfo JavaDoc[]
247       {
248          new MBeanParameterInfo JavaDoc("MessagingType", Class JavaDoc.class.getName(), "The type of the message listener"),
249          new MBeanParameterInfo JavaDoc("ActivationConfig", Collection JavaDoc.class.getName(), "A collection of activation config properties")
250       };
251       ops[0] = new MBeanOperationInfo JavaDoc("createActivationSpec", "Create an activation spec",
252             createActivationSpecParams, ActivationSpec JavaDoc.class.getName(), MBeanOperationInfo.ACTION);
253
254       MBeanParameterInfo JavaDoc[] activationParams = new MBeanParameterInfo JavaDoc[]
255       {
256          new MBeanParameterInfo JavaDoc("MessageEndpointFactory", MessageEndpointFactory JavaDoc.class.getName(), "The message endpoint factory"),
257          new MBeanParameterInfo JavaDoc("ActivationSpec", ActivationSpec JavaDoc.class.getName(), "The activation spec")
258       };
259       ops[1] = new MBeanOperationInfo JavaDoc("endpointActivation", "Active the endpoint",
260             activationParams, Void JavaDoc.class.getName(), MBeanOperationInfo.ACTION);
261       ops[2] = new MBeanOperationInfo JavaDoc("endpointDeactivation", "Deactive the endpoint",
262             activationParams, Void JavaDoc.class.getName(), MBeanOperationInfo.ACTION);
263
264       return ops;
265    }
266    
267    protected Object JavaDoc internalInvoke(String JavaDoc actionName, Object JavaDoc[] params, String JavaDoc[] signature) throws MBeanException JavaDoc,
268          ReflectionException JavaDoc
269    {
270       if ("createActivationSpec".equals(actionName))
271       {
272          if (params.length != 2)
273             throw new IllegalArgumentException JavaDoc("Wrong number of parameters for " + actionName);
274          Class JavaDoc messagingType = (Class JavaDoc) params[0];
275          Collection JavaDoc activationConfig = (Collection JavaDoc) params[1];
276          return createActivationSpec(messagingType, activationConfig);
277       }
278       else if ("endpointActivation".equals(actionName))
279       {
280          if (params.length != 2)
281             throw new IllegalArgumentException JavaDoc("Wrong number of parameters for " + actionName);
282          MessageEndpointFactory JavaDoc messageEndpointFactory = (MessageEndpointFactory JavaDoc) params[0];
283          ActivationSpec JavaDoc activationSpec = (ActivationSpec JavaDoc) params[1];
284          endpointActivation(messageEndpointFactory, activationSpec);
285          return null;
286       }
287       else if ("endpointDeactivation".equals(actionName))
288       {
289          if (params.length != 2)
290             throw new IllegalArgumentException JavaDoc("Wrong number of parameters for " + actionName);
291          MessageEndpointFactory JavaDoc messageEndpointFactory = (MessageEndpointFactory JavaDoc) params[0];
292          ActivationSpec JavaDoc activationSpec = (ActivationSpec JavaDoc) params[1];
293          endpointDeactivation(messageEndpointFactory, activationSpec);
294          return null;
295       }
296       return super.internalInvoke(actionName, params, signature);
297    }
298
299    protected ActivationSpec JavaDoc createActivationSpec(Class JavaDoc messagingType, Collection JavaDoc activationConfig) throws MBeanException JavaDoc
300    {
301       boolean trace = log.isTraceEnabled();
302       if (trace)
303          log.trace("CreateActivateSpec rar=" + getServiceName() + " messagingType=" + messagingType.getName() + " activationConfig=" + activationConfig);
304       
305       try
306       {
307          // Find the meta data
308
MessageListenerMetaData mlmd = cmd.getMessageListener(messagingType.getName());
309          if (mlmd == null)
310             throw new DeploymentException("MessagingType '" + messagingType.getName() + "' not found in resource deployment " + getServiceName());
311          
312          return ActivationSpecFactory.createActivationSpec(getServiceName(), messagingType.getName(), activationConfig, mlmd);
313       }
314       catch (Exception JavaDoc e)
315       {
316          throw new MBeanException JavaDoc(e, "Error in create activation spec " + getServiceName());
317       }
318    }
319
320    protected void endpointActivation(MessageEndpointFactory JavaDoc messageEndpointFactory, ActivationSpec JavaDoc activationSpec) throws MBeanException JavaDoc
321    {
322       boolean trace = log.isTraceEnabled();
323       if (trace)
324          log.trace("EndpointActivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec);
325
326       try
327       {
328          activationSpec.setResourceAdapter(resourceAdapter);
329          resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec);
330       }
331       catch (Exception JavaDoc e)
332       {
333          throw new MBeanException JavaDoc(e, "Error in endpoint activation " + getServiceName());
334       }
335    }
336
337    protected void endpointDeactivation(MessageEndpointFactory JavaDoc messageEndpointFactory, ActivationSpec JavaDoc activationSpec) throws MBeanException JavaDoc
338    {
339       boolean trace = log.isTraceEnabled();
340       if (trace)
341          log.trace("EndpointDeactivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec);
342
343       try
344       {
345          resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec);
346       }
347       catch (Exception JavaDoc e)
348       {
349          throw new MBeanException JavaDoc(e, "Error in endpoint deactivation " + getServiceName());
350       }
351    }
352 }
353
Popular Tags