/
JmsActivationSpecConfig.java
289 lines (238 loc) · 8.06 KB
/
JmsActivationSpecConfig.java
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
/*
* Copyright 2002-2020 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.jms.listener.endpoint;
import javax.jms.Session;
import org.springframework.core.Constants;
import org.springframework.jms.support.QosSettings;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.lang.Nullable;
/**
* Common configuration object for activating a JMS message endpoint.
* Gets converted into a provider-specific JCA 1.5 ActivationSpec
* object for activating the endpoint.
*
* <p>Typically used in combination with {@link JmsMessageEndpointManager},
* but not tied to it.
*
* @author Juergen Hoeller
* @author Stephane Nicoll
* @since 2.5
* @see JmsActivationSpecFactory
* @see JmsMessageEndpointManager#setActivationSpecConfig
* @see javax.resource.spi.ResourceAdapter#endpointActivation
*/
public class JmsActivationSpecConfig {
/** Constants instance for {@code javax.jms.Session}. */
private static final Constants sessionConstants = new Constants(Session.class);
@Nullable
private String destinationName;
private boolean pubSubDomain = false;
@Nullable
private Boolean replyPubSubDomain;
@Nullable
private QosSettings replyQosSettings;
private boolean subscriptionDurable = false;
private boolean subscriptionShared = false;
@Nullable
private String subscriptionName;
@Nullable
private String clientId;
@Nullable
private String messageSelector;
private int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
private int maxConcurrency = -1;
private int prefetchSize = -1;
@Nullable
private MessageConverter messageConverter;
public void setDestinationName(@Nullable String destinationName) {
this.destinationName = destinationName;
}
@Nullable
public String getDestinationName() {
return this.destinationName;
}
public void setPubSubDomain(boolean pubSubDomain) {
this.pubSubDomain = pubSubDomain;
}
public boolean isPubSubDomain() {
return this.pubSubDomain;
}
public void setReplyPubSubDomain(boolean replyPubSubDomain) {
this.replyPubSubDomain = replyPubSubDomain;
}
public boolean isReplyPubSubDomain() {
if (this.replyPubSubDomain != null) {
return this.replyPubSubDomain;
}
else {
return isPubSubDomain();
}
}
public void setReplyQosSettings(@Nullable QosSettings replyQosSettings) {
this.replyQosSettings = replyQosSettings;
}
@Nullable
public QosSettings getReplyQosSettings() {
return this.replyQosSettings;
}
public void setSubscriptionDurable(boolean subscriptionDurable) {
this.subscriptionDurable = subscriptionDurable;
if (subscriptionDurable) {
this.pubSubDomain = true;
}
}
public boolean isSubscriptionDurable() {
return this.subscriptionDurable;
}
public void setSubscriptionShared(boolean subscriptionShared) {
this.subscriptionShared = subscriptionShared;
if (subscriptionShared) {
this.pubSubDomain = true;
}
}
public boolean isSubscriptionShared() {
return this.subscriptionShared;
}
public void setSubscriptionName(@Nullable String subscriptionName) {
this.subscriptionName = subscriptionName;
}
@Nullable
public String getSubscriptionName() {
return this.subscriptionName;
}
public void setDurableSubscriptionName(@Nullable String durableSubscriptionName) {
this.subscriptionName = durableSubscriptionName;
this.subscriptionDurable = (durableSubscriptionName != null);
}
@Nullable
public String getDurableSubscriptionName() {
return (this.subscriptionDurable ? this.subscriptionName : null);
}
public void setClientId(@Nullable String clientId) {
this.clientId = clientId;
}
@Nullable
public String getClientId() {
return this.clientId;
}
public void setMessageSelector(@Nullable String messageSelector) {
this.messageSelector = messageSelector;
}
@Nullable
public String getMessageSelector() {
return this.messageSelector;
}
/**
* Set the JMS acknowledgement mode by the name of the corresponding constant
* in the JMS {@link Session} interface, e.g. "CLIENT_ACKNOWLEDGE".
* <p>Note that JCA resource adapters generally only support auto and dups-ok
* (see Spring's {@link StandardJmsActivationSpecFactory}). ActiveMQ also
* supports "SESSION_TRANSACTED" in the form of RA-managed transactions
* (automatically translated by Spring's {@link DefaultJmsActivationSpecFactory}.
* @param constantName the name of the {@link Session} acknowledge mode constant
* @see javax.jms.Session#AUTO_ACKNOWLEDGE
* @see javax.jms.Session#CLIENT_ACKNOWLEDGE
* @see javax.jms.Session#DUPS_OK_ACKNOWLEDGE
* @see javax.jms.Session#SESSION_TRANSACTED
* @see StandardJmsActivationSpecFactory
* @see DefaultJmsActivationSpecFactory
*/
public void setAcknowledgeModeName(String constantName) {
setAcknowledgeMode(sessionConstants.asNumber(constantName).intValue());
}
/**
* Set the JMS acknowledgement mode to use.
* @see javax.jms.Session#AUTO_ACKNOWLEDGE
* @see javax.jms.Session#CLIENT_ACKNOWLEDGE
* @see javax.jms.Session#DUPS_OK_ACKNOWLEDGE
* @see javax.jms.Session#SESSION_TRANSACTED
*/
public void setAcknowledgeMode(int acknowledgeMode) {
this.acknowledgeMode = acknowledgeMode;
}
/**
* Return the JMS acknowledgement mode to use.
*/
public int getAcknowledgeMode() {
return this.acknowledgeMode;
}
/**
* Specify concurrency limits via a "lower-upper" String, e.g. "5-10", or a simple
* upper limit String, e.g. "10".
* <p>JCA listener containers will always scale from zero to the given upper limit.
* A specified lower limit will effectively be ignored.
* <p>This property is primarily supported for configuration compatibility with
* {@link org.springframework.jms.listener.DefaultMessageListenerContainer}.
* For this activation config, generally use {@link #setMaxConcurrency} instead.
*/
public void setConcurrency(String concurrency) {
try {
int separatorIndex = concurrency.indexOf('-');
if (separatorIndex != -1) {
setMaxConcurrency(Integer.parseInt(concurrency.substring(separatorIndex + 1)));
}
else {
setMaxConcurrency(Integer.parseInt(concurrency));
}
}
catch (NumberFormatException ex) {
throw new IllegalArgumentException("Invalid concurrency value [" + concurrency + "]: only " +
"single maximum integer (e.g. \"5\") and minimum-maximum combo (e.g. \"3-5\") supported. " +
"Note that JmsActivationSpecConfig will effectively ignore the minimum value and " +
"scale from zero up to the number of consumers according to the maximum value.");
}
}
/**
* Specify the maximum number of consumers/sessions to use, effectively
* controlling the number of concurrent invocations on the target listener.
*/
public void setMaxConcurrency(int maxConcurrency) {
this.maxConcurrency = maxConcurrency;
}
/**
* Return the maximum number of consumers/sessions to use.
*/
public int getMaxConcurrency() {
return this.maxConcurrency;
}
/**
* Specify the maximum number of messages to load into a session
* (a kind of batch size).
*/
public void setPrefetchSize(int prefetchSize) {
this.prefetchSize = prefetchSize;
}
/**
* Return the maximum number of messages to load into a session.
*/
public int getPrefetchSize() {
return this.prefetchSize;
}
/**
* Set the {@link MessageConverter} strategy for converting JMS Messages.
* @param messageConverter the message converter to use
*/
public void setMessageConverter(@Nullable MessageConverter messageConverter) {
this.messageConverter = messageConverter;
}
/**
* Return the {@link MessageConverter} to use, if any.
*/
@Nullable
public MessageConverter getMessageConverter() {
return this.messageConverter;
}
}