summaryrefslogtreecommitdiff
path: root/qpid/java/jca/src/main/java/org/apache/qpid/ra/inflow/QpidActivationSpec.java
blob: 3d9a88adb54fce4f2415f8e6757a63d4241fe690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.ra.inflow;

import java.io.Serializable;

import javax.jms.Session;
import javax.resource.ResourceException;
import javax.resource.spi.ActivationSpec;
import javax.resource.spi.InvalidPropertyException;
import javax.resource.spi.ResourceAdapter;

import org.apache.qpid.ra.ConnectionFactoryProperties;
import org.apache.qpid.ra.QpidResourceAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The activation spec
 * These properties are set on the MDB ActivactionProperties
 *
 */
public class QpidActivationSpec extends ConnectionFactoryProperties implements ActivationSpec, Serializable
{
   private static final long serialVersionUID = 7379131936083146158L;

   private static final int DEFAULT_MAX_SESSION = 15;

   /** The logger */
   private static final transient Logger _log = LoggerFactory.getLogger(QpidActivationSpec.class);

   /** The resource adapter */
   private QpidResourceAdapter _ra;

   /** The destination */
   private String _destination;

   /** The destination type */
   private String _destinationType;

   /** The message selector */
   private String _messageSelector;

   /** The acknowledgement mode */
   private int _acknowledgeMode;

   /** The subscription durability */
   private boolean _subscriptionDurability;

   /** The subscription name */
   private String _subscriptionName;

   /** The maximum number of sessions */
   private Integer _maxSession;

   /** Transaction timeout */
   private Integer _transactionTimeout;

   /** prefetch low */
   private Integer _prefetchLow;

   /** prefetch high */
   private Integer _prefetchHigh;

   private boolean _useJNDI = true;

   // undefined by default, default is specified at the RA level in QpidRAProperties
   private Integer _setupAttempts;

   // undefined by default, default is specified at the RA level in QpidRAProperties
   private Long _setupInterval;

   private Boolean _useConnectionPerHandler;

   /**
    * Constructor
    */
   public QpidActivationSpec()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("constructor()");
      }

      _acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
      _maxSession = DEFAULT_MAX_SESSION;
      _transactionTimeout = 0;
   }

   /**
    * Get the resource adapter
    * @return The resource adapter
    */
   public ResourceAdapter getResourceAdapter()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getResourceAdapter()");
      }

      return _ra;
   }

   /**
    * @return the useJNDI
    */
   public boolean isUseJNDI()
   {
      return _useJNDI;
   }

   /**
    * @param value the useJNDI to set
    */
   public void setUseJNDI(final boolean value)
   {
      _useJNDI = value;
   }

   /**
    * Set the resource adapter
    * @param ra The resource adapter
    * @exception ResourceException Thrown if incorrect resource adapter
    */
   public void setResourceAdapter(final ResourceAdapter ra) throws ResourceException
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setResourceAdapter(" + ra + ")");
      }

      if (ra == null || !(ra instanceof QpidResourceAdapter))
      {
         throw new ResourceException("Resource adapter is " + ra);
      }

      this._ra = (QpidResourceAdapter)ra;
   }

   /**
    * Get the destination
    * @return The value
    */
   public String getDestination()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getDestination()");
      }

      return _destination;
   }

   /**
    * Set the destination
    * @param value The value
    */
   public void setDestination(final String value)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setDestination(" + value + ")");
      }

      _destination = value;
   }

   /**
    * Get the destination type
    * @return The value
    */
   public String getDestinationType()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getDestinationType()");
      }

      return _destinationType;
   }

   /**
    * Set the destination type
    * @param value The value
    */
   public void setDestinationType(final String value)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setDestinationType(" + value + ")");
      }

      _destinationType = value;
   }

   /**
    * Get the message selector
    * @return The value
    */
   public String getMessageSelector()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getMessageSelector()");
      }

      return _messageSelector;
   }

   /**
    * Set the message selector
    * @param value The value
    */
   public void setMessageSelector(final String value)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setMessageSelector(" + value + ")");
      }

      _messageSelector = value;
   }

   /**
    * Get the acknowledge mode
    * @return The value
    */
   public String getAcknowledgeMode()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getAcknowledgeMode()");
      }

      if (Session.DUPS_OK_ACKNOWLEDGE == _acknowledgeMode)
      {
         return "Dups-ok-acknowledge";
      }
      else
      {
         return "Auto-acknowledge";
      }
   }

   /**
    * Set the acknowledge mode
    * @param value The value
    */
   public void setAcknowledgeMode(final String value)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setAcknowledgeMode(" + value + ")");
      }

      if ("DUPS_OK_ACKNOWLEDGE".equalsIgnoreCase(value) || "Dups-ok-acknowledge".equalsIgnoreCase(value))
      {
         _acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
      }
      else if ("AUTO_ACKNOWLEDGE".equalsIgnoreCase(value) || "Auto-acknowledge".equalsIgnoreCase(value))
      {
         _acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
      }
      else
      {
         throw new IllegalArgumentException("Unsupported acknowledgement mode " + value);
      }
   }

   /**
    * @return the acknowledgement mode
    */
   public int getAcknowledgeModeInt()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getAcknowledgeMode()");
      }

      return _acknowledgeMode;
   }

   /**
    * Get the subscription durability
    * @return The value
    */
   public String getSubscriptionDurability()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getSubscriptionDurability()");
      }

      if (_subscriptionDurability)
      {
         return "Durable";
      }
      else
      {
         return "NonDurable";
      }
   }

   /**
    * Set the subscription durability
    * @param value The value
    */
   public void setSubscriptionDurability(final String value)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setSubscriptionDurability(" + value + ")");
      }

      _subscriptionDurability = "Durable".equals(value);
   }

   /**
    * Get the status of subscription durability
    * @return The value
    */
   public boolean isSubscriptionDurable()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("isSubscriptionDurable()");
      }

      return _subscriptionDurability;
   }

   /**
    * Get the subscription name
    * @return The value
    */
   public String getSubscriptionName()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getSubscriptionName()");
      }

      return _subscriptionName;
   }

   /**
    * Set the subscription name
    * @param value The value
    */
   public void setSubscriptionName(final String value)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setSubscriptionName(" + value + ")");
      }

      _subscriptionName = value;
   }

   /**
    * Get the number of max session
    * @return The value
    */
   public Integer getMaxSession()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getMaxSession()");
      }

      if (_maxSession == null)
      {
         return DEFAULT_MAX_SESSION;
      }

      return _maxSession;
   }

   /**
    * Set the number of max session
    * @param value The value
    */
   public void setMaxSession(final Integer value)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setMaxSession(" + value + ")");
      }

      _maxSession = value;
   }

   /**
    * Get the transaction timeout
    * @return The value
    */
   public Integer getTransactionTimeout()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getTransactionTimeout()");
      }

      return _transactionTimeout;
   }

   /**
    * Set the transaction timeout
    * @param value The value
    */
   public void setTransactionTimeout(final Integer value)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setTransactionTimeout(" + value + ")");
      }

      _transactionTimeout = value;
   }

   /**
    * Get the prefetch low
    * @return The value
    */
   public Integer getPrefetchLow()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getPrefetchLow()");
      }

      return _prefetchLow;
   }

   /**
    * Set the prefetch low
    * @param value The value
    */
   public void setPrefetchLow(final Integer prefetchLow)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setPrefetchLow(" + prefetchLow + ")");
      }

      this._prefetchLow = prefetchLow;
   }

   /**
    * Get the prefetch high
    * @return The value
    */
   public Integer getPrefetchHigh()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getPrefetchHigh()");
      }

      return _prefetchHigh;
   }

   /**
    * Set the prefetch high
    * @param value The value
    */
   public void setPrefetchHigh(final Integer prefetchHigh)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setPrefetchHigh(" + prefetchHigh + ")");
      }

      this._prefetchHigh = prefetchHigh;
   }

   public int getSetupAttempts()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getSetupAttempts()");
      }

      if (_setupAttempts == null)
      {
         return _ra.getSetupAttempts();
      }
      else
      {
         return _setupAttempts;
      }
   }

   public void setSetupAttempts(int setupAttempts)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setSetupAttempts(" + setupAttempts + ")");
      }

      this._setupAttempts = setupAttempts;
   }

   public long getSetupInterval()
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("getSetupInterval()");
      }

      if (_setupInterval == null)
      {
         return _ra.getSetupInterval();
      }
      else
      {
         return _setupInterval;
      }
   }

   public void setSetupInterval(long setupInterval)
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("setSetupInterval(" + setupInterval + ")");
      }

      this._setupInterval = setupInterval;
   }

   public Boolean isUseConnectionPerHandler()
   {              
       return (_useConnectionPerHandler == null) ? _ra.isUseConnectionPerHandler() : _useConnectionPerHandler;
   }
   
   public void setUseConnectionPerHandler(Boolean connectionPerHandler)
   {
       this._useConnectionPerHandler = connectionPerHandler;                       
   }

   /**
    * Validate
    * @exception InvalidPropertyException Thrown if a validation exception occurs
    */
   public void validate() throws InvalidPropertyException
   {
      if (_log.isTraceEnabled())
      {
         _log.trace("validate()");
      }

      if (_destination == null || _destination.trim().equals(""))
      {
         throw new InvalidPropertyException("Destination is mandatory");
      }
   }

   
   /**
    * Get a string representation
    * @return The value
    */
   @Override
   public String toString()
   {
      StringBuffer buffer = new StringBuffer();
      buffer.append(QpidActivationSpec.class.getName()).append('(');
      buffer.append("ra=").append(_ra);
      buffer.append(" destination=").append(_destination);
      buffer.append(" destinationType=").append(_destinationType);
      
      if (_messageSelector != null)
      {
         buffer.append(" selector=").append(_messageSelector);
      }
      
      buffer.append(" ack=").append(getAcknowledgeMode());
      buffer.append(" durable=").append(_subscriptionDurability);
      buffer.append(" clientID=").append(getClientId());
      
      if (_subscriptionName != null)
      {
         buffer.append(" subscription=").append(_subscriptionName);
      }
      
      buffer.append(" user=").append(getUserName());
      
      if (getPassword() != null)
      {
         buffer.append(" password=").append("********");
      }
      
      buffer.append(" maxSession=").append(_maxSession);
      
      if (_prefetchLow != null)
      {
         buffer.append(" prefetchLow=").append(_prefetchLow);
      }
      if (_prefetchHigh != null)
      {
         buffer.append(" prefetchHigh=").append(_prefetchHigh);
      }
      
      buffer.append(" connectionPerHandler=").append(isUseConnectionPerHandler());
      buffer.append(')');

      return buffer.toString();
   }
}