Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c6a744

Browse files
committedSep 23, 2024·
Merge branch '3.2.x' into 3.3.x
Closes gh-42421
2 parents bc20582 + 2aea7ca commit 9c6a744

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed
 

‎spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ActiveMQConnectionFactory jmsConnectionFactory(ArtemisProperties properties, Lis
5757
private static ActiveMQConnectionFactory createJmsConnectionFactory(ArtemisProperties properties,
5858
ArtemisConnectionDetails connectionDetails, ListableBeanFactory beanFactory) {
5959
return new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
60-
.createConnectionFactory(ActiveMQConnectionFactory.class);
60+
.createConnectionFactory(ActiveMQConnectionFactory::new, ActiveMQConnectionFactory::new);
6161
}
6262

6363
@Configuration(proxyBeanMethods = false)
@@ -93,7 +93,7 @@ JmsPoolConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory, A
9393
ArtemisConnectionDetails connectionDetails) {
9494
ActiveMQConnectionFactory connectionFactory = new ArtemisConnectionFactoryFactory(beanFactory, properties,
9595
connectionDetails)
96-
.createConnectionFactory(ActiveMQConnectionFactory.class);
96+
.createConnectionFactory(ActiveMQConnectionFactory::new, ActiveMQConnectionFactory::new);
9797
return new JmsPoolConnectionFactoryFactory(properties.getPool())
9898
.createPooledConnectionFactory(connectionFactory);
9999
}

‎spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryFactory.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.jms.artemis;
1818

19-
import java.lang.reflect.Constructor;
19+
import java.util.function.Function;
2020

2121
import org.apache.activemq.artemis.api.core.TransportConfiguration;
2222
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
@@ -61,10 +61,11 @@ class ArtemisConnectionFactoryFactory {
6161
this.connectionDetails = connectionDetails;
6262
}
6363

64-
<T extends ActiveMQConnectionFactory> T createConnectionFactory(Class<T> factoryClass) {
64+
<T extends ActiveMQConnectionFactory> T createConnectionFactory(Function<String, T> nativeFactoryCreator,
65+
Function<ServerLocator, T> embeddedFactoryCreator) {
6566
try {
6667
startEmbeddedJms();
67-
return doCreateConnectionFactory(factoryClass);
68+
return doCreateConnectionFactory(nativeFactoryCreator, embeddedFactoryCreator);
6869
}
6970
catch (Exception ex) {
7071
throw new IllegalStateException("Unable to create ActiveMQConnectionFactory", ex);
@@ -84,15 +85,16 @@ private void startEmbeddedJms() {
8485
}
8586
}
8687

87-
private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Class<T> factoryClass) throws Exception {
88+
private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Function<String, T> nativeFactoryCreator,
89+
Function<ServerLocator, T> embeddedFactoryCreator) throws Exception {
8890
ArtemisMode mode = this.connectionDetails.getMode();
8991
if (mode == null) {
9092
mode = deduceMode();
9193
}
9294
if (mode == ArtemisMode.EMBEDDED) {
93-
return createEmbeddedConnectionFactory(factoryClass);
95+
return createEmbeddedConnectionFactory(embeddedFactoryCreator);
9496
}
95-
return createNativeConnectionFactory(factoryClass);
97+
return createNativeConnectionFactory(nativeFactoryCreator);
9698
}
9799

98100
/**
@@ -115,23 +117,22 @@ private boolean isEmbeddedJmsClassPresent() {
115117
return false;
116118
}
117119

118-
private <T extends ActiveMQConnectionFactory> T createEmbeddedConnectionFactory(Class<T> factoryClass)
119-
throws Exception {
120+
private <T extends ActiveMQConnectionFactory> T createEmbeddedConnectionFactory(
121+
Function<ServerLocator, T> factoryCreator) throws Exception {
120122
try {
121123
TransportConfiguration transportConfiguration = new TransportConfiguration(
122124
InVMConnectorFactory.class.getName(), this.properties.getEmbedded().generateTransportParameters());
123-
ServerLocator serviceLocator = ActiveMQClient.createServerLocatorWithoutHA(transportConfiguration);
124-
return factoryClass.getConstructor(ServerLocator.class).newInstance(serviceLocator);
125+
ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(transportConfiguration);
126+
return factoryCreator.apply(serverLocator);
125127
}
126128
catch (NoClassDefFoundError ex) {
127129
throw new IllegalStateException("Unable to create InVM "
128130
+ "Artemis connection, ensure that artemis-jms-server.jar is in the classpath", ex);
129131
}
130132
}
131133

132-
private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Class<T> factoryClass)
133-
throws Exception {
134-
T connectionFactory = newNativeConnectionFactory(factoryClass);
134+
private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Function<String, T> factoryCreator) {
135+
T connectionFactory = newNativeConnectionFactory(factoryCreator);
135136
String user = this.connectionDetails.getUser();
136137
if (StringUtils.hasText(user)) {
137138
connectionFactory.setUser(user);
@@ -140,12 +141,10 @@ private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Cl
140141
return connectionFactory;
141142
}
142143

143-
private <T extends ActiveMQConnectionFactory> T newNativeConnectionFactory(Class<T> factoryClass) throws Exception {
144+
private <T extends ActiveMQConnectionFactory> T newNativeConnectionFactory(Function<String, T> factoryCreator) {
144145
String brokerUrl = StringUtils.hasText(this.connectionDetails.getBrokerUrl())
145146
? this.connectionDetails.getBrokerUrl() : DEFAULT_BROKER_URL;
146-
Constructor<T> constructor = factoryClass.getConstructor(String.class);
147-
return constructor.newInstance(brokerUrl);
148-
147+
return factoryCreator.apply(brokerUrl);
149148
}
150149

151150
}

‎spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisXAConnectionFactoryConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ ConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisP
4747
ArtemisConnectionDetails connectionDetails, XAConnectionFactoryWrapper wrapper) throws Exception {
4848
return wrapper
4949
.wrapConnectionFactory(new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
50-
.createConnectionFactory(ActiveMQXAConnectionFactory.class));
50+
.createConnectionFactory(ActiveMQXAConnectionFactory::new, ActiveMQXAConnectionFactory::new));
5151
}
5252

5353
@Bean
5454
ActiveMQXAConnectionFactory nonXaJmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisProperties properties,
5555
ArtemisConnectionDetails connectionDetails) {
5656
return new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
57-
.createConnectionFactory(ActiveMQXAConnectionFactory.class);
57+
.createConnectionFactory(ActiveMQXAConnectionFactory::new, ActiveMQXAConnectionFactory::new);
5858
}
5959

6060
}

0 commit comments

Comments
 (0)
Please sign in to comment.