Skip to content

Commit 8bc033c

Browse files
committed
Tweak the InstantiatorService interface and use it to instantiate the XA TransactionManager
1 parent 571e3ca commit 8bc033c

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

ehcache-core/src/main/java/org/ehcache/core/spi/service/InstantiatorService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919

2020
public interface InstantiatorService extends Service {
2121

22-
<T> T instantiate(Class<T> clazz, Object[] arguments);
22+
<T> T instantiate(Class<T> clazz, Object ... arguments) throws IllegalArgumentException;
2323
}

ehcache-impl/src/main/java/org/ehcache/impl/internal/classes/DefaultInstantiatorService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void stop() {
3333
}
3434

3535
@Override
36-
public <T> T instantiate(Class<T> clazz, Object[] arguments) {
36+
public <T> T instantiate(Class<T> clazz, Object ... arguments) {
3737
try {
3838
return ConstructorUtils.invokeConstructor(clazz, arguments);
3939
} catch (ReflectiveOperationException e) {

ehcache-transactions/src/jakarta/java/org/ehcache/transactions/xa/txmgr/provider/LookupTransactionManagerProvider.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.ehcache.transactions.xa.txmgr.provider;
1818

1919
import jakarta.transaction.TransactionManager;
20+
import org.ehcache.core.spi.service.InstantiatorService;
2021
import org.ehcache.spi.service.Service;
22+
import org.ehcache.spi.service.ServiceDependencies;
2123
import org.ehcache.spi.service.ServiceProvider;
2224
import org.ehcache.transactions.xa.txmgr.TransactionManagerWrapper;
2325

@@ -37,10 +39,11 @@
3739
* Note that in this scheme, the lookup instance is not expected to cache the {@code TransactionManagerWrapper}
3840
* unless it can be considered a singleton.
3941
*/
42+
@ServiceDependencies(InstantiatorService.class)
4043
public class LookupTransactionManagerProvider implements TransactionManagerProvider<TransactionManager> {
4144

42-
private final TransactionManagerLookup<TransactionManager> lookup;
43-
private volatile TransactionManagerWrapper<TransactionManager> transactionManagerWrapper;
45+
private final LookupTransactionManagerProviderConfiguration config;
46+
private TransactionManagerWrapper<TransactionManager> transactionManagerWrapper;
4447

4548
/**
4649
* Creates a new instance with the provided configuration.
@@ -53,11 +56,7 @@ public LookupTransactionManagerProvider(LookupTransactionManagerProviderConfigur
5356
if (config == null) {
5457
throw new NullPointerException("LookupTransactionManagerProviderConfiguration cannot be null");
5558
}
56-
try {
57-
lookup = config.getTransactionManagerLookup().newInstance();
58-
} catch (InstantiationException | IllegalAccessException e) {
59-
throw new IllegalArgumentException("Could not instantiate lookup class", e);
60-
}
59+
this.config = config;
6160
}
6261

6362
/**
@@ -73,7 +72,8 @@ public TransactionManagerWrapper<TransactionManager> getTransactionManagerWrappe
7372
*/
7473
@Override
7574
public void start(ServiceProvider<Service> serviceProvider) {
76-
this.transactionManagerWrapper = lookup.lookupTransactionManagerWrapper();
75+
InstantiatorService instantiatorService = serviceProvider.getService(InstantiatorService.class);
76+
this.transactionManagerWrapper = instantiatorService.instantiate(config.getTransactionManagerLookup()).lookupTransactionManagerWrapper();
7777
}
7878

7979
/**

ehcache-transactions/src/main/java/org/ehcache/transactions/xa/txmgr/provider/LookupTransactionManagerProvider.java

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

1717
package org.ehcache.transactions.xa.txmgr.provider;
1818

19+
import org.ehcache.core.spi.service.InstantiatorService;
1920
import org.ehcache.spi.service.Service;
21+
import org.ehcache.spi.service.ServiceDependencies;
2022
import org.ehcache.spi.service.ServiceProvider;
2123
import org.ehcache.transactions.xa.txmgr.TransactionManagerWrapper;
2224

@@ -38,10 +40,11 @@
3840
* Note that in this scheme, the lookup instance is not expected to cache the {@code TransactionManagerWrapper}
3941
* unless it can be considered a singleton.
4042
*/
43+
@ServiceDependencies(InstantiatorService.class)
4144
public class LookupTransactionManagerProvider implements TransactionManagerProvider<TransactionManager> {
4245

43-
private final TransactionManagerLookup<TransactionManager> lookup;
44-
private volatile TransactionManagerWrapper<TransactionManager> transactionManagerWrapper;
46+
private final LookupTransactionManagerProviderConfiguration config;
47+
private TransactionManagerWrapper<TransactionManager> transactionManagerWrapper;
4548

4649
/**
4750
* Creates a new instance with the provided configuration.
@@ -54,11 +57,7 @@ public LookupTransactionManagerProvider(LookupTransactionManagerProviderConfigur
5457
if (config == null) {
5558
throw new NullPointerException("LookupTransactionManagerProviderConfiguration cannot be null");
5659
}
57-
try {
58-
lookup = config.getTransactionManagerLookup().newInstance();
59-
} catch (InstantiationException | IllegalAccessException e) {
60-
throw new IllegalArgumentException("Could not instantiate lookup class", e);
61-
}
60+
this.config = config;
6261
}
6362

6463
/**
@@ -74,7 +73,8 @@ public TransactionManagerWrapper<TransactionManager> getTransactionManagerWrappe
7473
*/
7574
@Override
7675
public void start(ServiceProvider<Service> serviceProvider) {
77-
this.transactionManagerWrapper = lookup.lookupTransactionManagerWrapper();
76+
InstantiatorService instantiatorService = serviceProvider.getService(InstantiatorService.class);
77+
this.transactionManagerWrapper = instantiatorService.instantiate(config.getTransactionManagerLookup()).lookupTransactionManagerWrapper();
7878
}
7979

8080
/**

0 commit comments

Comments
 (0)