KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jms > inflow > JmsActivationSpec


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.adapter.jms.inflow;
23
24 import javax.jms.Queue JavaDoc;
25 import javax.jms.Session JavaDoc;
26 import javax.jms.Topic JavaDoc;
27 import javax.resource.ResourceException JavaDoc;
28 import javax.resource.spi.ActivationSpec JavaDoc;
29 import javax.resource.spi.InvalidPropertyException JavaDoc;
30 import javax.resource.spi.ResourceAdapter JavaDoc;
31
32 import org.jboss.logging.Logger;
33 import org.jboss.util.Strings;
34
35 /**
36  * A generic jms ActivationSpec.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 58487 $
40  */

41 public class JmsActivationSpec implements ActivationSpec JavaDoc
42 {
43    /** The log */
44    private static final Logger log = Logger.getLogger(JmsActivationSpec.class);
45
46    /** The resource adapter */
47    private ResourceAdapter JavaDoc ra;
48
49    /** The destination */
50    private String JavaDoc destination;
51
52    /** The destination type */
53    private boolean isTopic = false;
54
55    /** The message selector */
56    private String JavaDoc messageSelector;
57
58    /** The acknowledgement mode */
59    private int acknowledgeMode;
60
61    /** The subscription durability */
62    private boolean subscriptionDurability;
63
64    /** The client id */
65    private String JavaDoc clientId;
66
67    /** The subscription name */
68    private String JavaDoc subscriptionName;
69
70    /** The reconnect interval in seconds */
71    private long reconnectInterval = 10;
72
73    /** The jms provider adapter jndi name */
74    private String JavaDoc providerAdapterJNDI = "java:/DefaultJMSProvider";
75
76    /** The user */
77    private String JavaDoc user;
78
79    /** The password */
80    private String JavaDoc pass;
81
82    /** The maximum number of messages */
83    private int maxMessages = 1;
84
85    /** The minimum number of sessions */
86    private int minSession = 1;
87
88    /** The maximum number of sessions */
89    private int maxSession = 15;
90
91    /** The keep alive time for sessions */
92    private long keepAlive = 60000;
93
94    /** Is the session transacted */
95    private boolean sessionTransacted = true;
96
97    /** The DLQ handler class */
98    private String JavaDoc dLQHandler = "org.jboss.resource.adapter.jms.inflow.dlq.GenericDLQHandler";
99
100    /** Whether to use a DLQ */
101    private boolean useDLQ = true;
102
103    /** The DLQ jndi binding */
104    private String JavaDoc dLQJNDIName = "queue/DLQ";
105
106    /** The DLQ user */
107    private String JavaDoc dLQUser;
108
109    /** The DLQ password */
110    private String JavaDoc dLQPassword;
111
112    /** The DLQ client id */
113    private String JavaDoc dLQClientID;
114
115    /** The DLQ max resent */
116    private int dLQMaxResent;
117    
118    //Default to 5 attempts
119
private int reconnectAttempts = 5;
120    
121    private boolean redeliverUnspecified = true;
122    
123    /**
124     * @return the acknowledgeMode.
125     */

126    public String JavaDoc getAcknowledgeMode()
127    {
128       if (sessionTransacted)
129          return "TRANSACTED";
130       else if (Session.DUPS_OK_ACKNOWLEDGE == acknowledgeMode)
131          return "DUPS_OK_ACKNOWLEDGE";
132       else
133          return "AUTO_ACKNOWLEDGE";
134    }
135
136    /**
137     * @param acknowledgeMode The acknowledgeMode to set.
138     */

139    public void setAcknowledgeMode(String JavaDoc acknowledgeMode)
140    {
141       if ("DUPS_OK_ACKNOWLEDGE".equals(acknowledgeMode))
142          this.acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
143       else if ("AUTO_ACKNOWLEDGE".equals(acknowledgeMode))
144          this.acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
145       else if ("SESSION_TRANSACTED".equals(acknowledgeMode))
146          this.acknowledgeMode = Session.SESSION_TRANSACTED;
147       else
148          throw new IllegalArgumentException JavaDoc("Unsupported acknowledgement mode " + acknowledgeMode);
149    }
150
151    /**
152     * @return the acknowledgement mode
153     */

154    public int getAcknowledgeModeInt()
155    {
156       if (sessionTransacted)
157          return Session.SESSION_TRANSACTED;
158       return acknowledgeMode;
159    }
160
161    /**
162     * @return the clientId.
163     */

164    public String JavaDoc getClientId()
165    {
166       return clientId;
167    }
168
169    /**
170     * @param clientId The clientId to set.
171     */

172    public void setClientId(String JavaDoc clientId)
173    {
174       this.clientId = clientId;
175    }
176
177    /**
178     * @return the destination.
179     */

180    public String JavaDoc getDestination()
181    {
182       return destination;
183    }
184
185    /**
186     * @param destination The destination to set.
187     */

188    public void setDestination(String JavaDoc destination)
189    {
190       this.destination = destination;
191    }
192
193    /**
194     * @return the destinationType.
195     */

196    public String JavaDoc getDestinationType()
197    {
198       if (isTopic)
199          return Topic JavaDoc.class.getName();
200       else
201          return Queue JavaDoc.class.getName();
202    }
203
204    /**
205     * @param destinationType The destinationType to set.
206     */

207    public void setDestinationType(String JavaDoc destinationType)
208    {
209       if (Topic JavaDoc.class.getName().equals(destinationType))
210          this.isTopic = true;
211       else
212          this.isTopic = false;
213    }
214
215    /**
216     * @return whether this is for a topic.
217     */

218    public boolean isTopic()
219    {
220       return isTopic;
221    }
222
223    /**
224     * @return the messageSelector.
225     */

226    public String JavaDoc getMessageSelector()
227    {
228       return messageSelector;
229    }
230
231    /**
232     * @param messageSelector The messageSelector to set.
233     */

234    public void setMessageSelector(String JavaDoc messageSelector)
235    {
236       this.messageSelector = messageSelector;
237    }
238
239    /**
240     * @return the subscriptionDurability.
241     */

242    public String JavaDoc getSubscriptionDurability()
243    {
244       if (subscriptionDurability)
245          return "Durable";
246       else
247          return "NonDurable";
248    }
249
250    /**
251     * @param subscriptionDurability The subscriptionDurability to set.
252     */

253    public void setSubscriptionDurability(String JavaDoc subscriptionDurability)
254    {
255       this.subscriptionDurability = "Durable".equals(subscriptionDurability);
256    }
257
258    /**
259     * @return wether the subscription is durable.
260     */

261    public boolean isDurable()
262    {
263       return subscriptionDurability;
264    }
265
266    /**
267     * @return the subscriptionName.
268     */

269    public String JavaDoc getSubscriptionName()
270    {
271       return subscriptionName;
272    }
273
274    /**
275     * @param subscriptionName The subscriptionName to set.
276     */

277    public void setSubscriptionName(String JavaDoc subscriptionName)
278    {
279       this.subscriptionName = subscriptionName;
280    }
281
282    /**
283     * @return the reconnectInterval.
284     */

285    public long getReconnectInterval()
286    {
287       return reconnectInterval;
288    }
289
290    /**
291     * @param reconnectInterval The reconnectInterval to set.
292     */

293    public void setReconnectInterval(long reconnectInterval)
294    {
295       this.reconnectInterval = reconnectInterval;
296    }
297
298    /**
299     * @return the reconnect interval
300     */

301    public long getReconnectIntervalLong()
302    {
303       return reconnectInterval * 1000;
304    }
305
306    /**
307     * @return the providerAdapterJNDI.
308     */

309    public String JavaDoc getProviderAdapterJNDI()
310    {
311       return providerAdapterJNDI;
312    }
313
314    /**
315     * @param providerAdapterJNDI The providerAdapterJNDI to set.
316     */

317    public void setProviderAdapterJNDI(String JavaDoc providerAdapterJNDI)
318    {
319       this.providerAdapterJNDI = providerAdapterJNDI;
320    }
321
322    /**
323     * @return the user.
324     */

325    public String JavaDoc getUser()
326    {
327       return user;
328    }
329
330    /**
331     * @param user The user to set.
332     */

333    public void setUser(String JavaDoc user)
334    {
335       this.user = user;
336    }
337
338    /**
339     * @return the password.
340     */

341    public String JavaDoc getPassword()
342    {
343       return pass;
344    }
345
346    /**
347     * @param pass The password to set.
348     */

349    public void setPassword(String JavaDoc pass)
350    {
351       this.pass = pass;
352    }
353
354    /**
355     * @return the maxMessages.
356     */

357    public int getMaxMessages()
358    {
359       return maxMessages;
360    }
361
362    /**
363     * @param maxMessages The maxMessages to set.
364     */

365    public void setMaxMessages(int maxMessages)
366    {
367       this.maxSession = maxMessages;
368    }
369
370    /**
371     * @return the maximum number of messages
372     */

373    public int getMaxMessagesInt()
374    {
375       return maxMessages;
376    }
377
378    /**
379     * @return the minSession.
380     */

381    public int getMinSession()
382    {
383       return minSession;
384    }
385
386    /**
387     * @param minSession The minSession to set.
388     */

389    public void setMinSession(int minSession)
390    {
391       this.minSession = minSession;
392    }
393
394    /**
395     * @return the minimum number of sessions
396     */

397    public int getMinSessionInt()
398    {
399       return minSession;
400    }
401
402    /**
403     * @return the maxSession.
404     */

405    public int getMaxSession()
406    {
407       return maxSession;
408    }
409
410    /**
411     * @param maxSession The maxSession to set.
412     */

413    public void setMaxSession(int maxSession)
414    {
415       this.maxSession = maxSession;
416    }
417
418    /**
419     * @return the maximum number of sessions
420     */

421    public int getMaxSessionInt()
422    {
423       return maxSession;
424    }
425
426    /**
427     * @return the keepAlive.
428     */

429    public long getKeepAlive()
430    {
431       return keepAlive;
432    }
433
434    /**
435     * @param keepAlive The keepAlive to set.
436     */

437    public void setKeepAlive(long keepAlive)
438    {
439       this.keepAlive = keepAlive;
440    }
441
442    /**
443     * @return the keep alive time of the session
444     */

445    public long getKeepAliveLong()
446    {
447       return keepAlive;
448    }
449
450    /**
451     * @return the sessionTransacted.
452     */

453    public boolean getSessionTransacted()
454    {
455       return sessionTransacted;
456    }
457
458    /**
459     * @param sessionTransacted The sessionTransacted to set.
460     */

461    public void setSessionTransacted(boolean sessionTransacted)
462    {
463       this.sessionTransacted = sessionTransacted;
464    }
465
466    /**
467     * @return whether the session is transaction
468     */

469    public boolean isSessionTransacted()
470    {
471       return sessionTransacted;
472    }
473
474    /**
475     * @return Returns the dLQHandler.
476     */

477    public String JavaDoc getDLQHandler()
478    {
479       return dLQHandler;
480    }
481
482    /**
483     * @param handler The dLQHandler to set.
484     */

485    public void setDLQHandler(String JavaDoc handler)
486    {
487       this.dLQHandler = handler;
488    }
489
490    /**
491     * @return Returns the dLQJNDIName.
492     */

493    public String JavaDoc getDLQJNDIName()
494    {
495       return dLQJNDIName;
496    }
497
498    /**
499     * @param name The dLQJNDIName to set.
500     */

501    public void setDLQJNDIName(String JavaDoc name)
502    {
503       dLQJNDIName = name;
504    }
505
506    /**
507     * @return Returns the useDLQ.
508     */

509    public boolean getUseDLQ()
510    {
511       return useDLQ;
512    }
513
514    /**
515     * @param useDLQ The useDLQ to set.
516     */

517    public void setUseDLQ(boolean useDLQ)
518    {
519       this.useDLQ = useDLQ;
520    }
521
522    /**
523     * Whether we should use a DLQ
524     *
525     * @return true when using a DLQ
526     */

527    public boolean isUseDLQ()
528    {
529       return useDLQ;
530    }
531
532    /**
533     * @return Returns the dLQClientID.
534     */

535    public String JavaDoc getDLQClientID()
536    {
537       return dLQClientID;
538    }
539
540    /**
541     * @param clientID The dLQClientID to set.
542     */

543    public void setDLQClientID(String JavaDoc clientID)
544    {
545       dLQClientID = clientID;
546    }
547
548    /**
549     * @return Returns the dLQPassword.
550     */

551    public String JavaDoc getDLQPassword()
552    {
553       return dLQPassword;
554    }
555
556    /**
557     * @param password The dLQPassword to set.
558     */

559    public void setDLQPassword(String JavaDoc password)
560    {
561       dLQPassword = password;
562    }
563
564    /**
565     * @return Returns the dLQUser.
566     */

567    public String JavaDoc getDLQUser()
568    {
569       return dLQUser;
570    }
571
572    /**
573     * @param user The dLQUser to set.
574     */

575    public void setDLQUser(String JavaDoc user)
576    {
577       dLQUser = user;
578    }
579
580    /**
581     * @return Returns the maxResent.
582     */

583    public int getDLQMaxResent()
584    {
585       return dLQMaxResent;
586    }
587    /**
588     * @param maxResent The maxResent to set.
589     */

590    public void setDLQMaxResent(int maxResent)
591    {
592       this.dLQMaxResent = maxResent;
593    }
594
595    public ResourceAdapter JavaDoc getResourceAdapter()
596    {
597       return ra;
598    }
599
600    public void setResourceAdapter(ResourceAdapter JavaDoc ra) throws ResourceException JavaDoc
601    {
602       this.ra = ra;
603    }
604
605    public void validate() throws InvalidPropertyException JavaDoc
606    {
607       if (log.isTraceEnabled())
608          log.trace("validate " + this);
609       // TODO validate
610
}
611
612    public String JavaDoc toString()
613    {
614       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
615       buffer.append(Strings.defaultToString(this)).append('(');
616       buffer.append("ra=").append(ra);
617       buffer.append(" destination=").append(destination);
618       buffer.append(" isTopic=").append(isTopic);
619       if (messageSelector != null)
620          buffer.append(" selector=").append(messageSelector);
621       buffer.append(" tx=").append(sessionTransacted);
622       if (sessionTransacted == false)
623          buffer.append(" ack=").append(getAcknowledgeMode());
624       buffer.append(" durable=").append(subscriptionDurability);
625       if (clientId != null)
626          buffer.append(" clientID=").append(clientId);
627       if (subscriptionName != null)
628          buffer.append(" subscription=").append(subscriptionName);
629       buffer.append(" reconnect=").append(reconnectInterval);
630       buffer.append(" provider=").append(providerAdapterJNDI);
631       buffer.append(" user=").append(user);
632       if (pass != null)
633          buffer.append(" pass=").append("<not shown>");
634       buffer.append(" maxMessages=").append(maxMessages);
635       buffer.append(" minSession=").append(minSession);
636       buffer.append(" maxSession=").append(maxSession);
637       buffer.append(" keepAlive=").append(keepAlive);
638       buffer.append(" useDLQ=").append(useDLQ);
639       if (useDLQ)
640       {
641          buffer.append(" DLQHandler=").append(dLQHandler);
642          buffer.append(" DLQJndiName=").append(dLQJNDIName);
643          buffer.append(" DLQUser=").append(dLQUser);
644          if (dLQPassword != null)
645             buffer.append(" DLQPass=").append("<not shown>");
646          if (dLQClientID != null)
647             buffer.append(" DLQClientID=").append(dLQClientID);
648          buffer.append(" DLQMaxResent=").append(dLQMaxResent);
649       }
650       buffer.append(')');
651       return buffer.toString();
652    }
653
654    public int getReconnectAttempts()
655    {
656       return reconnectAttempts;
657    }
658
659    public void setReconnectAttempts(int reconnectAttempts)
660    {
661       this.reconnectAttempts = reconnectAttempts;
662    }
663
664    public boolean getRedeliverUnspecified()
665    {
666       return redeliverUnspecified;
667    }
668
669    public void setRedeliverUnspecified(boolean redeliverUnspecified)
670    {
671       this.redeliverUnspecified = redeliverUnspecified;
672    }
673 }
Popular Tags