001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.resource.adapter.jms.inflow;
023:
024: import javax.jms.Queue;
025: import javax.jms.Session;
026: import javax.jms.Topic;
027: import javax.resource.ResourceException;
028: import javax.resource.spi.ActivationSpec;
029: import javax.resource.spi.InvalidPropertyException;
030: import javax.resource.spi.ResourceAdapter;
031:
032: import org.jboss.logging.Logger;
033: import org.jboss.util.Strings;
034:
035: /**
036: * A generic jms ActivationSpec.
037: *
038: * @author <a href="adrian@jboss.com">Adrian Brock</a>
039: * @version $Revision: 60926 $
040: */
041: public class JmsActivationSpec implements ActivationSpec {
042: /** The log */
043: private static final Logger log = Logger
044: .getLogger(JmsActivationSpec.class);
045:
046: /** The resource adapter */
047: private ResourceAdapter ra;
048:
049: /** The destination */
050: private String destination;
051:
052: /** The destination type */
053: private boolean isTopic = false;
054:
055: /** The message selector */
056: private String messageSelector;
057:
058: /** The acknowledgement mode */
059: private int acknowledgeMode;
060:
061: /** The subscription durability */
062: private boolean subscriptionDurability;
063:
064: /** The client id */
065: private String clientId;
066:
067: /** The subscription name */
068: private String subscriptionName;
069:
070: /** The reconnect interval in seconds */
071: private long reconnectInterval = 10;
072:
073: /** The jms provider adapter jndi name */
074: private String providerAdapterJNDI = "java:/DefaultJMSProvider";
075:
076: /** The user */
077: private String user;
078:
079: /** The password */
080: private String pass;
081:
082: /** The maximum number of messages */
083: private int maxMessages = 1;
084:
085: /** The minimum number of sessions */
086: private int minSession = 1;
087:
088: /** The maximum number of sessions */
089: private int maxSession = 15;
090:
091: /** The keep alive time for sessions */
092: private long keepAlive = 60000;
093:
094: /** Is the session transacted */
095: private boolean sessionTransacted = true;
096:
097: /** The DLQ handler class */
098: private String dLQHandler = "org.jboss.resource.adapter.jms.inflow.dlq.GenericDLQHandler";
099:
100: /** Whether to use a DLQ */
101: private boolean useDLQ = true;
102:
103: /** The DLQ jndi binding */
104: private String dLQJNDIName = "queue/DLQ";
105:
106: /** The DLQ user */
107: private String dLQUser;
108:
109: /** The DLQ password */
110: private String dLQPassword;
111:
112: /** The DLQ client id */
113: private String dLQClientID;
114:
115: /** The DLQ max resent */
116: private int dLQMaxResent = 5;
117:
118: //Used to specify whether or not we should attempt to redeliver a message in an unspecified txn context
119: private boolean redeliverUnspecified = true;
120:
121: private int transactionTimeout;
122:
123: private Boolean isSameRMOverrideValue;
124:
125: /**
126: * @return the acknowledgeMode.
127: */
128: public String getAcknowledgeMode() {
129: if (sessionTransacted)
130: return "TRANSACTED";
131: else if (Session.DUPS_OK_ACKNOWLEDGE == acknowledgeMode)
132: return "DUPS_OK_ACKNOWLEDGE";
133: else
134: return "AUTO_ACKNOWLEDGE";
135: }
136:
137: /**
138: * @param acknowledgeMode The acknowledgeMode to set.
139: */
140: public void setAcknowledgeMode(String acknowledgeMode) {
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(
149: "Unsupported acknowledgement mode "
150: + acknowledgeMode);
151: }
152:
153: /**
154: * @return the acknowledgement mode
155: */
156: public int getAcknowledgeModeInt() {
157: if (sessionTransacted)
158: return Session.SESSION_TRANSACTED;
159: return acknowledgeMode;
160: }
161:
162: /**
163: * @return the clientId.
164: */
165: public String getClientId() {
166: return clientId;
167: }
168:
169: /**
170: * @param clientId The clientId to set.
171: */
172: public void setClientId(String clientId) {
173: this .clientId = clientId;
174: }
175:
176: /**
177: * @return the destination.
178: */
179: public String getDestination() {
180: return destination;
181: }
182:
183: /**
184: * @param destination The destination to set.
185: */
186: public void setDestination(String destination) {
187: this .destination = destination;
188: }
189:
190: /**
191: * @return the destinationType.
192: */
193: public String getDestinationType() {
194: if (isTopic)
195: return Topic.class.getName();
196: else
197: return Queue.class.getName();
198: }
199:
200: /**
201: * @param destinationType The destinationType to set.
202: */
203: public void setDestinationType(String destinationType) {
204: if (Topic.class.getName().equals(destinationType))
205: this .isTopic = true;
206: else
207: this .isTopic = false;
208: }
209:
210: /**
211: * @return whether this is for a topic.
212: */
213: public boolean isTopic() {
214: return isTopic;
215: }
216:
217: /**
218: * @return the messageSelector.
219: */
220: public String getMessageSelector() {
221: return messageSelector;
222: }
223:
224: /**
225: * @param messageSelector The messageSelector to set.
226: */
227: public void setMessageSelector(String messageSelector) {
228: this .messageSelector = messageSelector;
229: }
230:
231: /**
232: * @return the subscriptionDurability.
233: */
234: public String getSubscriptionDurability() {
235: if (subscriptionDurability)
236: return "Durable";
237: else
238: return "NonDurable";
239: }
240:
241: /**
242: * @param subscriptionDurability The subscriptionDurability to set.
243: */
244: public void setSubscriptionDurability(String subscriptionDurability) {
245: this .subscriptionDurability = "Durable"
246: .equals(subscriptionDurability);
247: }
248:
249: /**
250: * @return wether the subscription is durable.
251: */
252: public boolean isDurable() {
253: return subscriptionDurability;
254: }
255:
256: /**
257: * @return the subscriptionName.
258: */
259: public String getSubscriptionName() {
260: return subscriptionName;
261: }
262:
263: /**
264: * @param subscriptionName The subscriptionName to set.
265: */
266: public void setSubscriptionName(String subscriptionName) {
267: this .subscriptionName = subscriptionName;
268: }
269:
270: /**
271: * @return the reconnectInterval.
272: */
273: public long getReconnectInterval() {
274: return reconnectInterval;
275: }
276:
277: /**
278: * @param reconnectInterval The reconnectInterval to set.
279: */
280: public void setReconnectInterval(long reconnectInterval) {
281: this .reconnectInterval = reconnectInterval;
282: }
283:
284: /**
285: * @return the reconnect interval
286: */
287: public long getReconnectIntervalLong() {
288: return reconnectInterval * 1000;
289: }
290:
291: /**
292: * @return the providerAdapterJNDI.
293: */
294: public String getProviderAdapterJNDI() {
295: return providerAdapterJNDI;
296: }
297:
298: /**
299: * @param providerAdapterJNDI The providerAdapterJNDI to set.
300: */
301: public void setProviderAdapterJNDI(String providerAdapterJNDI) {
302: this .providerAdapterJNDI = providerAdapterJNDI;
303: }
304:
305: /**
306: * @return the user.
307: */
308: public String getUser() {
309: return user;
310: }
311:
312: /**
313: * @param user The user to set.
314: */
315: public void setUser(String user) {
316: this .user = user;
317: }
318:
319: /**
320: * @return the password.
321: */
322: public String getPassword() {
323: return pass;
324: }
325:
326: /**
327: * @param pass The password to set.
328: */
329: public void setPassword(String pass) {
330: this .pass = pass;
331: }
332:
333: /**
334: * @return the maxMessages.
335: */
336: public int getMaxMessages() {
337: return maxMessages;
338: }
339:
340: /**
341: * @param maxMessages The maxMessages to set.
342: */
343: public void setMaxMessages(int maxMessages) {
344: this .maxSession = maxMessages;
345: }
346:
347: /**
348: * @return the maximum number of messages
349: */
350: public int getMaxMessagesInt() {
351: return maxMessages;
352: }
353:
354: /**
355: * @return the minSession.
356: */
357: public int getMinSession() {
358: return minSession;
359: }
360:
361: /**
362: * @param minSession The minSession to set.
363: */
364: public void setMinSession(int minSession) {
365: this .minSession = minSession;
366: }
367:
368: /**
369: * @return the minimum number of sessions
370: */
371: public int getMinSessionInt() {
372: return minSession;
373: }
374:
375: /**
376: * @return the maxSession.
377: */
378: public int getMaxSession() {
379: return maxSession;
380: }
381:
382: /**
383: * @param maxSession The maxSession to set.
384: */
385: public void setMaxSession(int maxSession) {
386: this .maxSession = maxSession;
387: }
388:
389: /**
390: * @return the maximum number of sessions
391: */
392: public int getMaxSessionInt() {
393: return maxSession;
394: }
395:
396: /**
397: * @return the keepAlive.
398: */
399: public long getKeepAlive() {
400: return keepAlive;
401: }
402:
403: /**
404: * @param keepAlive The keepAlive to set.
405: */
406: public void setKeepAlive(long keepAlive) {
407: this .keepAlive = keepAlive;
408: }
409:
410: /**
411: * @return the keep alive time of the session
412: */
413: public long getKeepAliveLong() {
414: return keepAlive;
415: }
416:
417: /**
418: * @return the sessionTransacted.
419: */
420: public boolean getSessionTransacted() {
421: return sessionTransacted;
422: }
423:
424: /**
425: * @param sessionTransacted The sessionTransacted to set.
426: */
427: public void setSessionTransacted(boolean sessionTransacted) {
428: this .sessionTransacted = sessionTransacted;
429: }
430:
431: /**
432: * @return whether the session is transaction
433: */
434: public boolean isSessionTransacted() {
435: return sessionTransacted;
436: }
437:
438: /**
439: * @return Returns the dLQHandler.
440: */
441: public String getDLQHandler() {
442: return dLQHandler;
443: }
444:
445: /**
446: * @param handler The dLQHandler to set.
447: */
448: public void setDLQHandler(String handler) {
449: this .dLQHandler = handler;
450: }
451:
452: /**
453: * @return Returns the dLQJNDIName.
454: */
455: public String getDLQJNDIName() {
456: return dLQJNDIName;
457: }
458:
459: /**
460: * @param name The dLQJNDIName to set.
461: */
462: public void setDLQJNDIName(String name) {
463: dLQJNDIName = name;
464: }
465:
466: /**
467: * @return Returns the useDLQ.
468: */
469: public boolean getUseDLQ() {
470: return useDLQ;
471: }
472:
473: /**
474: * @param useDLQ The useDLQ to set.
475: */
476: public void setUseDLQ(boolean useDLQ) {
477: this .useDLQ = useDLQ;
478: }
479:
480: /**
481: * Whether we should use a DLQ
482: *
483: * @return true when using a DLQ
484: */
485: public boolean isUseDLQ() {
486: return useDLQ;
487: }
488:
489: /**
490: * @return Returns the dLQClientID.
491: */
492: public String getDLQClientID() {
493: return dLQClientID;
494: }
495:
496: /**
497: * @param clientID The dLQClientID to set.
498: */
499: public void setDLQClientID(String clientID) {
500: dLQClientID = clientID;
501: }
502:
503: /**
504: * @return Returns the dLQPassword.
505: */
506: public String getDLQPassword() {
507: return dLQPassword;
508: }
509:
510: /**
511: * @param password The dLQPassword to set.
512: */
513: public void setDLQPassword(String password) {
514: dLQPassword = password;
515: }
516:
517: /**
518: * @return Returns the dLQUser.
519: */
520: public String getDLQUser() {
521: return dLQUser;
522: }
523:
524: /**
525: * @param user The dLQUser to set.
526: */
527: public void setDLQUser(String user) {
528: dLQUser = user;
529: }
530:
531: /**
532: * @return Returns the maxResent.
533: */
534: public int getDLQMaxResent() {
535: return dLQMaxResent;
536: }
537:
538: /**
539: * @param maxResent The maxResent to set.
540: */
541: public void setDLQMaxResent(int maxResent) {
542: this .dLQMaxResent = maxResent;
543: }
544:
545: public ResourceAdapter getResourceAdapter() {
546: return ra;
547: }
548:
549: public void setResourceAdapter(ResourceAdapter ra)
550: throws ResourceException {
551: this .ra = ra;
552: }
553:
554: public void validate() throws InvalidPropertyException {
555: if (log.isTraceEnabled())
556: log.trace("validate " + this );
557: // TODO validate
558: }
559:
560: public String toString() {
561: StringBuffer buffer = new StringBuffer();
562: buffer.append(Strings.defaultToString(this )).append('(');
563: buffer.append("ra=").append(ra);
564: buffer.append(" destination=").append(destination);
565: buffer.append(" isTopic=").append(isTopic);
566: if (messageSelector != null)
567: buffer.append(" selector=").append(messageSelector);
568: buffer.append(" tx=").append(sessionTransacted);
569: if (sessionTransacted == false)
570: buffer.append(" ack=").append(getAcknowledgeMode());
571: buffer.append(" durable=").append(subscriptionDurability);
572: if (clientId != null)
573: buffer.append(" clientID=").append(clientId);
574: if (subscriptionName != null)
575: buffer.append(" subscription=").append(subscriptionName);
576: buffer.append(" reconnect=").append(reconnectInterval);
577: buffer.append(" provider=").append(providerAdapterJNDI);
578: buffer.append(" user=").append(user);
579: if (pass != null)
580: buffer.append(" pass=").append("<not shown>");
581: buffer.append(" maxMessages=").append(maxMessages);
582: buffer.append(" minSession=").append(minSession);
583: buffer.append(" maxSession=").append(maxSession);
584: buffer.append(" keepAlive=").append(keepAlive);
585: buffer.append(" useDLQ=").append(useDLQ);
586: if (useDLQ) {
587: buffer.append(" DLQHandler=").append(dLQHandler);
588: buffer.append(" DLQJndiName=").append(dLQJNDIName);
589: buffer.append(" DLQUser=").append(dLQUser);
590: if (dLQPassword != null)
591: buffer.append(" DLQPass=").append("<not shown>");
592: if (dLQClientID != null)
593: buffer.append(" DLQClientID=").append(dLQClientID);
594: buffer.append(" DLQMaxResent=").append(dLQMaxResent);
595: }
596: buffer.append(')');
597: return buffer.toString();
598: }
599:
600: public boolean getRedeliverUnspecified() {
601: return redeliverUnspecified;
602: }
603:
604: public void setRedeliverUnspecified(boolean redeliverUnspecified) {
605: this .redeliverUnspecified = redeliverUnspecified;
606: }
607:
608: public int getTransactionTimeout() {
609: return transactionTimeout;
610: }
611:
612: public void setTransactionTimeout(int transactionTimeout) {
613: this .transactionTimeout = transactionTimeout;
614: }
615:
616: public Boolean getIsSameRMOverrideValue() {
617: return isSameRMOverrideValue;
618: }
619:
620: public void setIsSameRMOverrideValue(Boolean isSameRMOverrideValue) {
621: this.isSameRMOverrideValue = isSameRMOverrideValue;
622: }
623:
624: }
|