Skip to content

Commit

Permalink
Use IronJacamar's WorkManager and BootstrapContext implementation
Browse files Browse the repository at this point in the history
- This gets rid of the original implementation I had for `jakarta.resource.spi.BootstrapContext` and `jakarta.resource.spi.work.WorkManager` and uses the implementations
provided by IronJacamar
- Fixes #43
- Initial work on #42
  • Loading branch information
gastaldi committed Sep 12, 2023
1 parent 7d46811 commit 5f09866
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 210 deletions.
4 changes: 4 additions & 0 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-context-propagation-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.ironjacamar</groupId>
<artifactId>quarkus-ironjacamar</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.quarkiverse.ironjacamar.runtime.QuarkusIronJacamarLogger;
import io.quarkus.arc.BeanDestroyer;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
Expand Down Expand Up @@ -229,6 +230,14 @@ void registerSyntheticBeans(
}
}

@BuildStep
@Record(value = ExecutionTime.STATIC_INIT)
void initDefaultBootstrapContext(BeanContainerBuildItem beanContainerBuildItem,
IronJacamarRecorder recorder) {
// Create the default bootstrap context
recorder.initDefaultBoostrapContext();
}

@BuildStep
@Record(value = ExecutionTime.RUNTIME_INIT)
@Consume(SyntheticBeansRuntimeInitBuildItem.class)
Expand Down
4 changes: 4 additions & 0 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-context-propagation</artifactId>
</dependency>
<dependency>
<groupId>jakarta.resource</groupId>
<artifactId>jakarta.resource-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
public interface Defaults {
String DEFAULT_RESOURCE_ADAPTER_NAME = "<default>";
String DEFAULT_ACTIVATION_SPEC_NAME = "<default>";
String DEFAULT_WORK_MANAGER_NAME = "default";
String DEFAULT_BOOTSTRAP_CONTEXT_NAME = "default";

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package io.quarkiverse.ironjacamar.runtime;

import static io.quarkiverse.ironjacamar.Defaults.DEFAULT_BOOTSTRAP_CONTEXT_NAME;
import static io.quarkiverse.ironjacamar.Defaults.DEFAULT_WORK_MANAGER_NAME;

import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

import jakarta.enterprise.inject.spi.DeploymentException;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.XATerminator;
import jakarta.transaction.TransactionSynchronizationRegistry;

import org.eclipse.microprofile.context.ManagedExecutor;
import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext;
import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager;
import org.jboss.jca.core.bootstrapcontext.BaseCloneableBootstrapContext;
import org.jboss.jca.core.bootstrapcontext.BootstrapContextCoordinator;
import org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl;
import org.jboss.jca.core.spi.transaction.TransactionIntegration;
import org.jboss.jca.core.workmanager.WorkManagerCoordinator;
import org.jboss.jca.core.workmanager.WorkManagerImpl;

import io.quarkiverse.ironjacamar.runtime.security.QuarkusSecurityIntegration;
import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.SyntheticCreationalContext;
Expand Down Expand Up @@ -65,18 +73,43 @@ public CachedConnectionManager apply(SyntheticCreationalContext<CachedConnection
};
}

public void initDefaultBoostrapContext() {
ArcContainer container = Arc.container();
TransactionIntegration transactionIntegration = container.select(TransactionIntegration.class).get();
BaseCloneableBootstrapContext bootstrapContext = new BaseCloneableBootstrapContext();
ManagedExecutor executorService = container.select(ManagedExecutor.class).get();

// Create WorkManagerImpl
WorkManagerImpl workManager = new WorkManagerImpl();
workManager.setName(DEFAULT_WORK_MANAGER_NAME);
workManager.setSpecCompliant(true);
workManager.setSecurityIntegration(new QuarkusSecurityIntegration());

// TODO: Should we have separate thread pools for short and long running tasks?
workManager.setShortRunningThreadPool(executorService);
workManager.setLongRunningThreadPool(executorService);

bootstrapContext.setName(DEFAULT_BOOTSTRAP_CONTEXT_NAME);
bootstrapContext.setWorkManager(workManager);
bootstrapContext.setWorkManagerName(DEFAULT_WORK_MANAGER_NAME);
bootstrapContext.setTransactionSynchronizationRegistry(transactionIntegration.getTransactionSynchronizationRegistry());
bootstrapContext.setXATerminator(transactionIntegration.getXATerminator());

// Register the default in the coordinator
WorkManagerCoordinator.getInstance().setDefaultWorkManager(workManager);
BootstrapContextCoordinator.getInstance().setDefaultBootstrapContext(bootstrapContext);
}

public RuntimeValue<Future<String>> initResourceAdapter(
String key,
Supplier<Vertx> vertxSupplier) {
ArcContainer container = Arc.container();
Vertx vertx = vertxSupplier.get();
IronJacamarContainer ijContainer = container.select(IronJacamarContainer.class, Identifier.Literal.of(key)).get();
// Lookup JTA beans
TransactionSynchronizationRegistry tsr = container.select(TransactionSynchronizationRegistry.class).get();
XATerminator xaTerminator = container.select(XATerminator.class).get();
IronJacamarVerticle verticle = new IronJacamarVerticle(ijContainer.getResourceAdapter(), tsr, xaTerminator,
key,
ijContainer.getResourceAdapterFactory().getDescription());
CloneableBootstrapContext bootstrapContext = BootstrapContextCoordinator.getInstance().getDefaultBootstrapContext();
IronJacamarVerticle verticle = new IronJacamarVerticle(key, ijContainer.getResourceAdapterFactory().getDescription(),
ijContainer.getResourceAdapter(),
bootstrapContext);
Future<String> future = vertx.deployVerticle(verticle, new DeploymentOptions()
.setWorkerPoolName("jca-worker-pool-" + key)
.setWorkerPoolSize(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,43 @@

import java.util.Objects;

import jakarta.resource.spi.BootstrapContext;
import jakarta.resource.spi.ResourceAdapter;
import jakarta.resource.spi.XATerminator;
import jakarta.transaction.TransactionSynchronizationRegistry;

import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext;
import org.jboss.jca.core.api.workmanager.WorkManager;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;

/**
* A Vert.x {@link io.vertx.core.Verticle} that starts and stops a JCA {@link ResourceAdapter}.
*/
final class IronJacamarVerticle extends AbstractVerticle {

private final ResourceAdapter ra;
private final TransactionSynchronizationRegistry tsr;
private final XATerminator xaTerminator;
private final String id;
private final String description;
private final ResourceAdapter ra;
private final CloneableBootstrapContext bootstrapContext;

private QuarkusWorkManager workManager;

public IronJacamarVerticle(ResourceAdapter resourceAdapter, TransactionSynchronizationRegistry tsr,
XATerminator xaTerminator, String id, String description) {
this.ra = Objects.requireNonNull(resourceAdapter, "resourceAdapter cannot be null");
this.tsr = Objects.requireNonNull(tsr, "tsr cannot be null");
this.xaTerminator = Objects.requireNonNull(xaTerminator, "xaTerminator cannot be null");
public IronJacamarVerticle(String id, String description, ResourceAdapter resourceAdapter,
CloneableBootstrapContext bootstrapContext) {
this.id = Objects.requireNonNull(id, "id cannot be null");
this.description = Objects.requireNonNull(description, "description cannot be null");
this.ra = Objects.requireNonNull(resourceAdapter, "resourceAdapter cannot be null");
this.bootstrapContext = Objects.requireNonNull(bootstrapContext, "bootstrapContext cannot be null");
}

@Override
public void start() throws Exception {
QuarkusIronJacamarLogger.log.startingResourceAdapter(id, description);
workManager = new QuarkusWorkManager(vertx);
// Create BootstrapContext
BootstrapContext bootstrapContext = new QuarkusBootstrapContext(workManager, tsr, xaTerminator);
ra.start(bootstrapContext);
}

@Override
public void stop(Promise<Void> stopPromise) {
public void stop() {
QuarkusIronJacamarLogger.log.stoppingResourceAdapter(id);
if (workManager != null) {
workManager.close().andThen((v) -> ra.stop()).andThen(stopPromise);
} else {
ra.stop();
stopPromise.complete();
}
ra.stop();
// Shutdown the work manager
((WorkManager) bootstrapContext.getWorkManager()).shutdown();
bootstrapContext.shutdown();
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5f09866

Please sign in to comment.