KickJava   Java API By Example, From Geeks To Geeks.

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

59 public class RARDeployment extends ServiceDynamicMBeanSupport
60    implements BootstrapContext JavaDoc
61 {
62    /** The deployment info */
63    protected DeploymentInfo di;
64    
65    /** Our deployer */
66    protected RARDeployer deployer;
67    
68    /** The RARDeploymentMetaData */
69    protected RARDeploymentMetaData rdmd;
70    
71    /** The ConnectorMetaData */
72    protected ConnectorMetaData cmd;
73    
74    /** The JBossRAMetaData */
75    protected JBossRAMetaData ramd;
76    
77    /** The resource adapter */
78    protected ResourceAdapter JavaDoc resourceAdapter;
79
80    /**
81     * Create a new RAR deployment
82     *
83     * @param di the deployment info
84     */

85    public RARDeployment(DeploymentInfo di)
86    {
87       this.di = di;
88       this.deployer = (RARDeployer) di.deployer;
89       this.rdmd = (RARDeploymentMetaData)di.metaData;
90       this.cmd = rdmd.getConnectorMetaData();
91       this.ramd = rdmd.getRaXmlMetaData();
92       
93    }
94    
95    // Public --------------------------------------------------------
96

97    public Timer JavaDoc createTimer() throws UnavailableException JavaDoc
98    {
99       return new Timer JavaDoc(true);
100    }
101
102    public WorkManager JavaDoc getWorkManager()
103    {
104       return deployer.workManager;
105    }
106
107    public XATerminator JavaDoc getXATerminator()
108    {
109       return deployer.xaTerminator;
110    }
111    
112    protected void startService() throws Exception JavaDoc
113    {
114       if (cmd.getLicense().getRequired())
115       {
116          log.info("Required license terms exist, view META-INF/ra.xml in " + ServerConfigUtil.shortUrlFromServerHome(di.url.toString()));
117          log.debug("License terms full URL: " + di.url);
118       }
119       resourceAdapter = ResourceAdapterFactory.createResourceAdapter(rdmd);
120       resourceAdapter.start(this);
121    }
122    
123    protected void stopService() throws Exception JavaDoc
124    {
125       resourceAdapter.stop();
126    }
127    
128    protected String JavaDoc getInternalDescription()
129    {
130       String JavaDoc description = null;
131       DescriptionGroupMetaData dgmd = cmd.getDescription();
132       if (dgmd != null)
133          description = dgmd.getDescription();
134       if (description == null)
135          description = "RAR Deployment " + di.url;
136       return description;
137    }
138
139    protected MBeanAttributeInfo JavaDoc[] getInternalAttributeInfo()
140    {
141       Collection JavaDoc properties = cmd.getProperties();
142       MBeanAttributeInfo JavaDoc[] attrs = new MBeanAttributeInfo JavaDoc[11+properties.size()];
143       attrs[0] = new MBeanAttributeInfo JavaDoc("MetaData", ConnectorMetaData.class.getName(), "The meta data", true, false, false);
144       attrs[1] = new MBeanAttributeInfo JavaDoc("AuthenticationMechanism", String JavaDoc.class.getName(), "The authentication mechanism", true, false, false);
145       attrs[2] = new MBeanAttributeInfo JavaDoc("EISType", String JavaDoc.class.getName(), "The EIS type", true, false, false);
146       attrs[3] = new MBeanAttributeInfo JavaDoc("License", String JavaDoc.class.getName(), "The license", true, false, false);
147       attrs[4] = new MBeanAttributeInfo JavaDoc("RAClass", String JavaDoc.class.getName(), "The resource adapter class", true, false, false);
148       attrs[5] = new MBeanAttributeInfo JavaDoc("RAVersion", String JavaDoc.class.getName(), "The resource adapter version", true, false, false);
149       attrs[6] = new MBeanAttributeInfo JavaDoc("TransactionSupport", String JavaDoc.class.getName(), "The transaction support", true, false, false);
150       attrs[7] = new MBeanAttributeInfo JavaDoc("VendorName", String JavaDoc.class.getName(), "The vendor name", true, false, false);
151       attrs[8] = new MBeanAttributeInfo JavaDoc("Version", String JavaDoc.class.getName(), "The spec version", true, false, false);
152       attrs[9] = new MBeanAttributeInfo JavaDoc("ReauthenticationSupport", Boolean.TYPE.getName(), "Whether reauthentication support is supported", true, false, false);
153       attrs[10] = new MBeanAttributeInfo JavaDoc("ResourceAdapter", ResourceAdapter JavaDoc.class.getName(), "The resource adapter instance", true, false, false);
154       int n = 11;
155       for (Iterator JavaDoc i = properties.iterator(); i.hasNext();)
156       {
157          ConfigPropertyMetaData cpmd = (ConfigPropertyMetaData) i.next();
158          attrs[n++] = new MBeanAttributeInfo JavaDoc(cpmd.getName(), cpmd.getType(), cpmd.getDescription().getDescription(), true, false, false);
159       }
160       return attrs;
161    }
162    
163    protected Object JavaDoc getInternalAttribute(String JavaDoc attribute)
164       throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
165    {
166       if ("MetaData".equals(attribute))
167          return cmd;
168       else if ("AuthenticationMechanism".equals(attribute))
169          return cmd.getAuthenticationMechanism().getAuthenticationMechansimType();
170       else if ("EISType".equals(attribute))
171          return cmd.getEISType();
172       else if ("License".equals(attribute))
173          return cmd.getLicense().getDescription().getDescription();
174       else if ("RAClass".equals(attribute))
175          return cmd.getRAClass();
176       else if ("RAVersion".equals(attribute))
177          return cmd.getRAVersion();
178       else if ("TransactionSupport".equals(attribute))
179          return cmd.getTransactionSupport();
180       else if ("VendorName".equals(attribute))
181          return cmd.getVendorName();
182       else if ("Version".equals(attribute))
183          return cmd.getVersion();
184       else if ("ReauthenticationSupport".equals(attribute))
185          return new Boolean JavaDoc(cmd.getReauthenticationSupport());
186       else if ("ResourceAdapter".equals(attribute))
187          return resourceAdapter;
188       Object JavaDoc property = cmd.getProperty(attribute);
189       if (property != null)
190          return property;
191       
192       return super.getInternalAttribute(attribute);
193    }
194
195    protected MBeanOperationInfo JavaDoc[] getInternalOperationInfo()
196    {
197       MBeanOperationInfo JavaDoc[] ops = new MBeanOperationInfo JavaDoc[3];
198
199       MBeanParameterInfo JavaDoc[] createActivationSpecParams = new MBeanParameterInfo JavaDoc[]
200       {
201          new MBeanParameterInfo JavaDoc("MessagingType", Class JavaDoc.class.getName(), "The type of the message listener"),
202          new MBeanParameterInfo JavaDoc("ActivationConfig", Collection JavaDoc.class.getName(), "A collection of activation config properties")
203       };
204       ops[0] = new MBeanOperationInfo JavaDoc("createActivationSpec", "Create an activation spec",
205             createActivationSpecParams, ActivationSpec JavaDoc.class.getName(), MBeanOperationInfo.ACTION);
206
207       MBeanParameterInfo JavaDoc[] activationParams = new MBeanParameterInfo JavaDoc[]
208       {
209          new MBeanParameterInfo JavaDoc("MessageEndpointFactory", MessageEndpointFactory JavaDoc.class.getName(), "The message endpoint factory"),
210          new MBeanParameterInfo JavaDoc("ActivationSpec", ActivationSpec JavaDoc.class.getName(), "The activation spec")
211       };
212       ops[1] = new MBeanOperationInfo JavaDoc("endpointActivation", "Active the endpoint",
213             activationParams, Void JavaDoc.class.getName(), MBeanOperationInfo.ACTION);
214       ops[2] = new MBeanOperationInfo JavaDoc("endpointDeactivation", "Deactive the endpoint",
215             activationParams, Void JavaDoc.class.getName(), MBeanOperationInfo.ACTION);
216
217       return ops;
218    }
219    
220    protected Object JavaDoc internalInvoke(String JavaDoc actionName, Object JavaDoc[] params, String JavaDoc[] signature) throws MBeanException JavaDoc,
221          ReflectionException JavaDoc
222    {
223       if ("createActivationSpec".equals(actionName))
224       {
225          if (params.length != 2)
226             throw new IllegalArgumentException JavaDoc("Wrong number of parameters for " + actionName);
227          Class JavaDoc messagingType = (Class JavaDoc) params[0];
228          Collection JavaDoc activationConfig = (Collection JavaDoc) params[1];
229          return createActivationSpec(messagingType, activationConfig);
230       }
231       else if ("endpointActivation".equals(actionName))
232       {
233          if (params.length != 2)
234             throw new IllegalArgumentException JavaDoc("Wrong number of parameters for " + actionName);
235          MessageEndpointFactory JavaDoc messageEndpointFactory = (MessageEndpointFactory JavaDoc) params[0];
236          ActivationSpec JavaDoc activationSpec = (ActivationSpec JavaDoc) params[1];
237          endpointActivation(messageEndpointFactory, activationSpec);
238          return null;
239       }
240       else if ("endpointDeactivation".equals(actionName))
241       {
242          if (params.length != 2)
243             throw new IllegalArgumentException JavaDoc("Wrong number of parameters for " + actionName);
244          MessageEndpointFactory JavaDoc messageEndpointFactory = (MessageEndpointFactory JavaDoc) params[0];
245          ActivationSpec JavaDoc activationSpec = (ActivationSpec JavaDoc) params[1];
246          endpointDeactivation(messageEndpointFactory, activationSpec);
247          return null;
248       }
249       return super.internalInvoke(actionName, params, signature);
250    }
251
252    protected ActivationSpec JavaDoc createActivationSpec(Class JavaDoc messagingType, Collection JavaDoc activationConfig) throws MBeanException JavaDoc
253    {
254       boolean trace = log.isTraceEnabled();
255       if (trace)
256          log.trace("CreateActivateSpec rar=" + getServiceName() + " messagingType=" + messagingType.getName() + " activationConfig=" + activationConfig);
257       
258       try
259       {
260          // Find the meta data
261
MessageListenerMetaData mlmd = cmd.getMessageListener(messagingType.getName());
262          if (mlmd == null)
263             throw new DeploymentException("MessagingType '" + messagingType.getName() + "' not found in resource deployment " + getServiceName());
264          
265          return ActivationSpecFactory.createActivationSpec(getServiceName(), messagingType.getName(), activationConfig, mlmd);
266       }
267       catch (Exception JavaDoc e)
268       {
269          throw new MBeanException JavaDoc(e, "Error in create activation spec " + getServiceName());
270       }
271    }
272
273    protected void endpointActivation(MessageEndpointFactory JavaDoc messageEndpointFactory, ActivationSpec JavaDoc activationSpec) throws MBeanException JavaDoc
274    {
275       boolean trace = log.isTraceEnabled();
276       if (trace)
277          log.trace("EndpointActivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec);
278
279       try
280       {
281          activationSpec.setResourceAdapter(resourceAdapter);
282          resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec);
283       }
284       catch (Exception JavaDoc e)
285       {
286          throw new MBeanException JavaDoc(e, "Error in endpoint activation " + getServiceName());
287       }
288    }
289
290    protected void endpointDeactivation(MessageEndpointFactory JavaDoc messageEndpointFactory, ActivationSpec JavaDoc activationSpec) throws MBeanException JavaDoc
291    {
292       boolean trace = log.isTraceEnabled();
293       if (trace)
294          log.trace("EndpointDeactivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec);
295
296       try
297       {
298          resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec);
299       }
300       catch (Exception JavaDoc e)
301       {
302          throw new MBeanException JavaDoc(e, "Error in endpoint deactivation " + getServiceName());
303       }
304    }
305 }
306
Popular Tags