Skip to content

Commit

Permalink
[WFLY-11381] Refactoring WeldTransactionServices to use non deprecate…
Browse files Browse the repository at this point in the history
…d ServiceBuilder methods.
  • Loading branch information
ropalka committed Nov 20, 2018
1 parent 220d1c9 commit 64137ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Expand Up @@ -29,21 +29,22 @@
import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.ServiceTarget;


import java.util.function.Consumer;

/** /**
*
* @author Martin Kouba * @author Martin Kouba
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/ */
public class TransactionsBootstrapDependencyInstaller implements BootstrapDependencyInstaller { public class TransactionsBootstrapDependencyInstaller implements BootstrapDependencyInstaller {


@Override @Override
public ServiceName install(ServiceTarget serviceTarget, DeploymentUnit deploymentUnit, boolean jtsEnabled) { public ServiceName install(ServiceTarget serviceTarget, DeploymentUnit deploymentUnit, boolean jtsEnabled) {
final WeldTransactionServices weldTransactionServices = new WeldTransactionServices(jtsEnabled);

final ServiceName weldTransactionServiceName = deploymentUnit.getServiceName().append(WeldTransactionServices.SERVICE_NAME); final ServiceName weldTransactionServiceName = deploymentUnit.getServiceName().append(WeldTransactionServices.SERVICE_NAME);

final ServiceBuilder<?> sb = serviceTarget.addService(weldTransactionServiceName);
final ServiceBuilder sb = serviceTarget.addService(weldTransactionServiceName, weldTransactionServices); final Consumer<WeldTransactionServices> weldTransactionServicesConsumer = sb.provides(weldTransactionServiceName);
// Ensure the local transaction provider is started before we start // Ensure the local transaction provider is started before we start
sb.requires(ServiceNames.capabilityServiceName(deploymentUnit, "org.wildfly.transactions.global-default-local-provider")); sb.requires(ServiceNames.capabilityServiceName(deploymentUnit, "org.wildfly.transactions.global-default-local-provider"));
sb.setInstance(new WeldTransactionServices(jtsEnabled, weldTransactionServicesConsumer));
sb.install(); sb.install();


return weldTransactionServiceName; return weldTransactionServiceName;
Expand Down
Expand Up @@ -21,17 +21,18 @@
*/ */
package org.jboss.as.weld.services.bootstrap; package org.jboss.as.weld.services.bootstrap;


import java.util.function.Consumer;

import javax.transaction.RollbackException; import javax.transaction.RollbackException;
import javax.transaction.Status; import javax.transaction.Status;
import javax.transaction.Synchronization; import javax.transaction.Synchronization;
import javax.transaction.SystemException; import javax.transaction.SystemException;
import javax.transaction.UserTransaction; import javax.transaction.UserTransaction;


import org.jboss.as.weld.ServiceNames; import org.jboss.as.weld.ServiceNames;
import org.jboss.msc.service.Service; import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext; import org.jboss.msc.service.StopContext;
import org.jboss.weld.transaction.spi.TransactionServices; import org.jboss.weld.transaction.spi.TransactionServices;
import org.wildfly.transaction.client.ContextTransactionManager; import org.wildfly.transaction.client.ContextTransactionManager;
Expand All @@ -44,16 +45,17 @@
* *
* @author Stuart Douglas * @author Stuart Douglas
* @author <a href="mailto:tadamski@redhat.com">Tomasz Adamski</a> * @author <a href="mailto:tadamski@redhat.com">Tomasz Adamski</a>
* * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/ */
public class WeldTransactionServices implements TransactionServices, Service<WeldTransactionServices> { public class WeldTransactionServices implements TransactionServices, Service {


public static final ServiceName SERVICE_NAME = ServiceNames.WELD_TRANSACTION_SERVICES_SERVICE_NAME; public static final ServiceName SERVICE_NAME = ServiceNames.WELD_TRANSACTION_SERVICES_SERVICE_NAME;

private final Consumer<WeldTransactionServices> weldTransactionServicesConsumer;
private final boolean jtsEnabled; private final boolean jtsEnabled;


public WeldTransactionServices(final boolean jtsEnabled) { public WeldTransactionServices(final boolean jtsEnabled, final Consumer<WeldTransactionServices> weldTransactionServicesConsumer) {
this.jtsEnabled = jtsEnabled; this.jtsEnabled = jtsEnabled;
this.weldTransactionServicesConsumer = weldTransactionServicesConsumer;
} }


@Override @Override
Expand Down Expand Up @@ -101,18 +103,13 @@ public void registerSynchronization(Synchronization synchronizedObserver) {
} }


@Override @Override
public void start(StartContext context) throws StartException { public void start(final StartContext context) {

weldTransactionServicesConsumer.accept(this);
}

@Override
public void stop(StopContext context) {

} }


@Override @Override
public WeldTransactionServices getValue() throws IllegalStateException, IllegalArgumentException { public void stop(final StopContext context) {
return this; weldTransactionServicesConsumer.accept(null);
} }


} }

0 comments on commit 64137ef

Please sign in to comment.