Skip to content

Commit c9be3aa

Browse files
committed
Update JDK to 17.
Switch from javax.jms.* to jakarta.jms.* namespace. Update testing libraries and maven plugins.
1 parent 501e5f2 commit c9be3aa

File tree

51 files changed

+3474
-5014
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3474
-5014
lines changed

pom.xml

Lines changed: 215 additions & 199 deletions
Large diffs are not rendered by default.

src/main/java/com/amazon/sqs/javamessaging/AmazonSQSMessagingClientWrapper.java

Lines changed: 127 additions & 179 deletions
Large diffs are not rendered by default.

src/main/java/com/amazon/sqs/javamessaging/PrefetchManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ public interface PrefetchManager {
2525
* messageQueue when user calls for receive or message listener onMessage is
2626
* called.
2727
*/
28-
public void messageDispatched();
28+
void messageDispatched();
2929

3030
/**
3131
* Notify the prefetchThread that the message listener has finished with any
3232
* previous message and is ready to accept another.
3333
*/
34-
public void messageListenerReady();
34+
void messageListenerReady();
3535

3636
/**
3737
* This is used to determine the state of the consumer, when the message
3838
* listener scheduler is processing the messages.
3939
*
4040
* @return The message consumer, which owns the prefetchThread
4141
*/
42-
public SQSMessageConsumer getMessageConsumer();
42+
SQSMessageConsumer getMessageConsumer();
4343
}

src/main/java/com/amazon/sqs/javamessaging/SQSConnection.java

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
import java.util.Set;
1919
import java.util.concurrent.ConcurrentHashMap;
2020

21-
import javax.jms.IllegalStateException;
22-
import javax.jms.Connection;
23-
import javax.jms.ConnectionConsumer;
24-
import javax.jms.ConnectionMetaData;
25-
import javax.jms.Destination;
26-
import javax.jms.ExceptionListener;
27-
import javax.jms.InvalidClientIDException;
28-
import javax.jms.JMSException;
29-
import javax.jms.Queue;
30-
import javax.jms.QueueConnection;
31-
import javax.jms.QueueSession;
32-
import javax.jms.ServerSessionPool;
33-
import javax.jms.Session;
34-
import javax.jms.Topic;
21+
import jakarta.jms.IllegalStateException;
22+
import jakarta.jms.Connection;
23+
import jakarta.jms.ConnectionConsumer;
24+
import jakarta.jms.ConnectionMetaData;
25+
import jakarta.jms.Destination;
26+
import jakarta.jms.ExceptionListener;
27+
import jakarta.jms.InvalidClientIDException;
28+
import jakarta.jms.JMSException;
29+
import jakarta.jms.Queue;
30+
import jakarta.jms.QueueConnection;
31+
import jakarta.jms.QueueSession;
32+
import jakarta.jms.ServerSessionPool;
33+
import jakarta.jms.Session;
34+
import jakarta.jms.Topic;
3535

3636
import org.slf4j.Logger;
3737
import org.slf4j.LoggerFactory;
@@ -107,7 +107,7 @@ public class SQSConnection implements Connection, QueueConnection {
107107
*/
108108
private volatile boolean actionOnConnectionTaken = false;
109109

110-
private final Set<Session> sessions = Collections.newSetFromMap(new ConcurrentHashMap<Session, Boolean>());
110+
private final Set<Session> sessions = Collections.newSetFromMap(new ConcurrentHashMap<>());
111111

112112
SQSConnection(AmazonSQSMessagingClientWrapper amazonSQSClientJMSWrapper, int numberOfMessagesToPrefetch) {
113113
amazonSQSClient = amazonSQSClientJMSWrapper;
@@ -167,7 +167,7 @@ public QueueSession createQueueSession(boolean transacted, int acknowledgeMode)
167167
*
168168
* @param transacted
169169
* Only false is supported.
170-
* @param acknowledgeMode
170+
* @param sessionMode
171171
* Legal values are <code>Session.AUTO_ACKNOWLEDGE</code>,
172172
* <code>Session.CLIENT_ACKNOWLEDGE</code>,
173173
* <code>Session.DUPS_OK_ACKNOWLEDGE</code>, and
@@ -179,26 +179,26 @@ public QueueSession createQueueSession(boolean transacted, int acknowledgeMode)
179179
* transaction and acknowledge mode.
180180
*/
181181
@Override
182-
public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException {
182+
public Session createSession(boolean transacted, int sessionMode) throws JMSException {
183183
checkClosed();
184184
actionOnConnectionTaken = true;
185-
if (transacted || acknowledgeMode == Session.SESSION_TRANSACTED)
185+
if (transacted || sessionMode == Session.SESSION_TRANSACTED)
186186
throw new JMSException("SQSSession does not support transacted");
187187

188188
SQSSession sqsSession;
189-
if (acknowledgeMode == Session.AUTO_ACKNOWLEDGE) {
190-
sqsSession = new SQSSession(this, AcknowledgeMode.ACK_AUTO.withOriginalAcknowledgeMode(acknowledgeMode));
191-
} else if (acknowledgeMode == Session.CLIENT_ACKNOWLEDGE || acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE) {
192-
sqsSession = new SQSSession(this, AcknowledgeMode.ACK_RANGE.withOriginalAcknowledgeMode(acknowledgeMode));
193-
} else if (acknowledgeMode == SQSSession.UNORDERED_ACKNOWLEDGE) {
194-
sqsSession = new SQSSession(this, AcknowledgeMode.ACK_UNORDERED.withOriginalAcknowledgeMode(acknowledgeMode));
189+
if (sessionMode == Session.AUTO_ACKNOWLEDGE) {
190+
sqsSession = new SQSSession(this, AcknowledgeMode.ACK_AUTO.withOriginalAcknowledgeMode(sessionMode));
191+
} else if (sessionMode == Session.CLIENT_ACKNOWLEDGE || sessionMode == Session.DUPS_OK_ACKNOWLEDGE) {
192+
sqsSession = new SQSSession(this, AcknowledgeMode.ACK_RANGE.withOriginalAcknowledgeMode(sessionMode));
193+
} else if (sessionMode == SQSSession.UNORDERED_ACKNOWLEDGE) {
194+
sqsSession = new SQSSession(this, AcknowledgeMode.ACK_UNORDERED.withOriginalAcknowledgeMode(sessionMode));
195195
} else {
196196
LOG.error("Unrecognized acknowledgeMode. Cannot create Session.");
197197
throw new JMSException("Unrecognized acknowledgeMode. Cannot create Session.");
198198
}
199199
synchronized (stateLock) {
200200
if (closing) {
201-
/**
201+
/*
202202
* SQSSession's constructor has already started a SQSSessionCallbackScheduler which should be closed
203203
* before leaving sqsSession object.
204204
*/
@@ -207,18 +207,27 @@ public Session createSession(boolean transacted, int acknowledgeMode) throws JMS
207207
}
208208
sessions.add(sqsSession);
209209

210-
/**
210+
/*
211211
* Any new sessions created on a started connection should be
212212
* started on creation
213213
*/
214214
if (running) {
215215
sqsSession.start();
216216
}
217217
}
218-
219218
return sqsSession;
220219
}
221220

221+
@Override
222+
public Session createSession(int sessionMode) throws JMSException {
223+
return createSession(false, sessionMode);
224+
}
225+
226+
@Override
227+
public Session createSession() throws JMSException {
228+
throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
229+
}
230+
222231
@Override
223232
public ExceptionListener getExceptionListener() throws JMSException {
224233
checkClosing();
@@ -303,7 +312,7 @@ public void start() throws JMSException {
303312
* This means that a client can rely on the fact that none of its message
304313
* listeners will be called and that all threads of control waiting for
305314
* receive calls to return will not return with a message until the
306-
* connection is restarted. The receive timers for a stopped connection
315+
* connection is restarted. The received timers for a stopped connection
307316
* continue to advance, so receives may time out while the connection is
308317
* stopped.
309318
* <P>
@@ -336,7 +345,7 @@ public void stop() throws JMSException {
336345
try {
337346
for (Session session : sessions) {
338347
SQSSession sqsSession = (SQSSession) session;
339-
/**
348+
/*
340349
* Session stop call blocks until receives and/or
341350
* message listeners in progress have completed.
342351
*/
@@ -375,12 +384,11 @@ public void stop() throws JMSException {
375384
*/
376385
@Override
377386
public void close() throws JMSException {
378-
379387
if (closed) {
380388
return;
381389
}
382390

383-
/**
391+
/*
384392
* A message listener must not attempt to close its own connection as
385393
* this would lead to deadlock.
386394
*/
@@ -411,7 +419,7 @@ public void close() throws JMSException {
411419

412420
}
413421
}
414-
}/** Blocks until closing of the connection completes */
422+
}/* Blocks until closing of the connection completes */
415423
else {
416424
synchronized (stateLock) {
417425
while (!closed) {
@@ -432,7 +440,7 @@ public void close() throws JMSException {
432440
* from list of Sessions.
433441
*/
434442
void removeSession(Session session) throws JMSException {
435-
/**
443+
/*
436444
* No need to synchronize on stateLock assuming this can be only called
437445
* by session.close(), on which point connection will not be worried
438446
* about missing closing this session.
@@ -505,9 +513,22 @@ public ConnectionConsumer createConnectionConsumer(Destination destination, Stri
505513
throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
506514
}
507515

516+
@Override
517+
public ConnectionConsumer createSharedConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException {
518+
throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
519+
}
520+
508521
/** This method is not supported. */
509522
@Override
510-
public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector,
523+
public ConnectionConsumer createDurableConnectionConsumer(
524+
Topic topic, String subscriptionName, String messageSelector,
525+
ServerSessionPool sessionPool, int maxMessages) throws JMSException {
526+
throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
527+
}
528+
529+
@Override
530+
public ConnectionConsumer createSharedDurableConnectionConsumer(
531+
Topic topic, String subscriptionName, String messageSelector,
511532
ServerSessionPool sessionPool, int maxMessages) throws JMSException {
512533
throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
513534
}

src/main/java/com/amazon/sqs/javamessaging/SQSConnectionFactory.java

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,30 @@
1414
*/
1515
package com.amazon.sqs.javamessaging;
1616

17-
import java.util.function.Supplier;
18-
19-
import javax.jms.ConnectionFactory;
20-
import javax.jms.JMSException;
21-
import javax.jms.QueueConnection;
22-
import javax.jms.QueueConnectionFactory;
23-
17+
import jakarta.jms.*;
2418
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
2519
import software.amazon.awssdk.auth.credentials.AwsCredentials;
2620
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
2721
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
2822
import software.amazon.awssdk.services.sqs.SqsClient;
2923
import software.amazon.awssdk.services.sqs.SqsClientBuilder;
3024

25+
import java.util.function.Supplier;
26+
3127
/**
3228
* A ConnectionFactory object encapsulates a set of connection configuration
3329
* parameters for <code>SqsClient</code> as well as setting
3430
* <code>numberOfMessagesToPrefetch</code>.
35-
* <P>
31+
* <p>
3632
* The <code>numberOfMessagesToPrefetch</code> parameter is used to size of the
3733
* prefetched messages, which can be tuned based on the application workload. It
3834
* helps in returning messages from internal buffers(if there is any) instead of
3935
* waiting for the SQS <code>receiveMessage</code> call to return.
40-
* <P>
36+
* <p>
4137
* If more physical connections than the default maximum value (that is 50 as of
4238
* today) are needed on the connection pool,
4339
* {@link software.amazon.awssdk.core.client.config.ClientOverrideConfiguration} needs to be configured.
44-
* <P>
40+
* <p>
4541
* None of the <code>createConnection</code> methods set-up the physical
4642
* connection to SQS, so validity of credentials are not checked with those
4743
* methods.
@@ -50,18 +46,16 @@
5046
public class SQSConnectionFactory implements ConnectionFactory, QueueConnectionFactory {
5147
private final ProviderConfiguration providerConfiguration;
5248
private final Supplier<SqsClient> amazonSQSClientSupplier;
53-
54-
/*
5549

56-
/*
50+
/**
5751
* Creates a SQSConnectionFactory that uses SqsClientBuilder.standard() for creating SqsClient connections.
5852
* Every SQSConnection will have its own copy of SqsClient.
5953
*/
6054
public SQSConnectionFactory(ProviderConfiguration providerConfiguration) {
6155
this(providerConfiguration, SqsClient.create());
6256
}
63-
64-
/*
57+
58+
/**
6559
* Creates a SQSConnectionFactory that uses the provided SqsClient connection.
6660
* Every SQSConnection will use the same provided SqsClient.
6761
*/
@@ -73,15 +67,10 @@ public SQSConnectionFactory(ProviderConfiguration providerConfiguration, final S
7367
throw new IllegalArgumentException("AmazonSQS client cannot be null");
7468
}
7569
this.providerConfiguration = providerConfiguration;
76-
this.amazonSQSClientSupplier = new Supplier<SqsClient>() {
77-
@Override
78-
public SqsClient get() {
79-
return client;
80-
}
81-
};
70+
this.amazonSQSClientSupplier = () -> client;
8271
}
83-
84-
/*
72+
73+
/**
8574
* Creates a SQSConnectionFactory that uses the provided SqsClientBuilder for creating AmazonSQS client connections.
8675
* Every SQSConnection will have its own copy of AmazonSQS client created through the provided builder.
8776
*/
@@ -93,19 +82,14 @@ public SQSConnectionFactory(ProviderConfiguration providerConfiguration, final S
9382
throw new IllegalArgumentException("AmazonSQS client builder cannot be null");
9483
}
9584
this.providerConfiguration = providerConfiguration;
96-
this.amazonSQSClientSupplier = new Supplier<SqsClient>() {
97-
@Override
98-
public SqsClient get() {
99-
return clientBuilder.build();
100-
}
101-
};
85+
this.amazonSQSClientSupplier = clientBuilder::build;
10286
}
103-
87+
10488

10589
@Override
10690
public SQSConnection createConnection() throws JMSException {
10791
try {
108-
SqsClient amazonSQS = amazonSQSClientSupplier.get();
92+
SqsClient amazonSQS = amazonSQSClientSupplier.get();
10993
return createConnection(amazonSQS, null);
11094
} catch (RuntimeException e) {
11195
throw (JMSException) new JMSException("Error creating SQS client: " + e.getMessage()).initCause(e);
@@ -118,36 +102,52 @@ public SQSConnection createConnection(String awsAccessKeyId, String awsSecretKey
118102
return createConnection(basicAWSCredentials);
119103
}
120104

105+
@Override
106+
public JMSContext createContext() {
107+
throw new JMSRuntimeException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
108+
}
109+
110+
@Override
111+
public JMSContext createContext(String userName, String password) {
112+
throw new JMSRuntimeException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
113+
}
114+
115+
@Override
116+
public JMSContext createContext(String userName, String password, int sessionMode) {
117+
throw new JMSRuntimeException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
118+
}
119+
120+
@Override
121+
public JMSContext createContext(int sessionMode) {
122+
throw new JMSRuntimeException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
123+
}
124+
121125
public SQSConnection createConnection(AwsCredentials awsCredentials) throws JMSException {
122126
AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(awsCredentials);
123127
return createConnection(awsCredentialsProvider);
124128
}
125-
129+
126130
public SQSConnection createConnection(AwsCredentialsProvider awsCredentialsProvider) throws JMSException {
127131
try {
128132
SqsClient amazonSQS = amazonSQSClientSupplier.get();
129133
return createConnection(amazonSQS, awsCredentialsProvider);
130-
} catch(Exception e) {
134+
} catch (Exception e) {
131135
throw (JMSException) new JMSException("Error creating SQS client: " + e.getMessage()).initCause(e);
132136
}
133137
}
134-
138+
135139
private SQSConnection createConnection(SqsClient amazonSQS, AwsCredentialsProvider awsCredentialsProvider) throws JMSException {
136140
AmazonSQSMessagingClientWrapper amazonSQSClientJMSWrapper = new AmazonSQSMessagingClientWrapper(amazonSQS, awsCredentialsProvider);
137141
return new SQSConnection(amazonSQSClientJMSWrapper, providerConfiguration.getNumberOfMessagesToPrefetch());
138142
}
139-
143+
140144
@Override
141145
public QueueConnection createQueueConnection() throws JMSException {
142-
return (QueueConnection) createConnection();
146+
return createConnection();
143147
}
144148

145149
@Override
146150
public QueueConnection createQueueConnection(String userName, String password) throws JMSException {
147-
return (QueueConnection) createConnection(userName, password);
151+
return createConnection(userName, password);
148152
}
149-
150-
151-
152-
153153
}

0 commit comments

Comments
 (0)