Skip to content

Commit

Permalink
[WFLY-5661] Enable CCM for jta=false
Browse files Browse the repository at this point in the history
  • Loading branch information
gaol committed Jun 14, 2016
1 parent 4e2fb69 commit 942f827
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 27 deletions.
Expand Up @@ -26,6 +26,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.resource.ResourceException;

import org.jboss.as.connector.util.ConnectorServices;
Expand Down Expand Up @@ -62,6 +63,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU

phaseContext.getServiceTarget().addService(serviceName, action)
.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, action.cachedConnectionManager)
.addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, action.noTxCcmValue)
.install();
deploymentUnit.addToAttachmentList(Attachments.WEB_SETUP_ACTIONS, action);
deploymentUnit.addToAttachmentList(Attachments.OTHER_EE_SETUP_ACTIONS, action);
Expand All @@ -76,7 +78,7 @@ public void undeploy(final DeploymentUnit context) {
private static class CachedConnectionManagerSetupAction implements SetupAction, Service<Void> {

private final InjectedValue<CachedConnectionManager> cachedConnectionManager = new InjectedValue<CachedConnectionManager>();

private final InjectedValue<CachedConnectionManager> noTxCcmValue = new InjectedValue<CachedConnectionManager>();

private final ServiceName serviceName;

Expand All @@ -90,6 +92,10 @@ private CachedConnectionManagerSetupAction(final ServiceName serviceName) {
@Override
public void setup(final Map<String, Object> properties) {
try {
final CachedConnectionManager noTxCcm = noTxCcmValue.getOptionalValue();
if (noTxCcm != null) {
noTxCcm.pushMetaAwareObject(this, unsharable);
}
final CachedConnectionManager connectionManager = cachedConnectionManager.getOptionalValue();
if (connectionManager != null) {
connectionManager.pushMetaAwareObject(this, unsharable);
Expand All @@ -106,6 +112,10 @@ public void teardown(final Map<String, Object> properties) {
if (connectionManager != null) {
connectionManager.popMetaAwareObject(unsharable);
}
final CachedConnectionManager noTxCcm = noTxCcmValue.getOptionalValue();
if (noTxCcm != null) {
noTxCcm.popMetaAwareObject(unsharable);
}
} catch (ResourceException e) {
throw new RuntimeException(e);
}
Expand Down
Expand Up @@ -30,6 +30,7 @@

import org.jboss.as.connector.annotations.repository.jandex.JandexAnnotationRepositoryImpl;
import org.jboss.as.connector.logging.ConnectorLogger;
import org.jboss.as.connector.metadata.deployment.ResourceAdapterDeployment;
import org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor;
import org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor;
import org.jboss.as.connector.services.mdr.AS7MetadataRepository;
Expand Down Expand Up @@ -58,6 +59,7 @@
import org.jboss.dmr.ModelNode;
import org.jboss.jandex.Index;
import org.jboss.jca.common.annotations.Annotations;
import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
import org.jboss.jca.common.api.metadata.resourceadapter.Activation;
import org.jboss.jca.common.api.metadata.spec.Connector;
import org.jboss.jca.common.metadata.merge.Merger;
Expand Down Expand Up @@ -156,7 +158,7 @@ public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
}


public static ServiceBuilder process(final ConnectorXmlDescriptor connectorXmlDescriptor, final IronJacamarXmlDescriptor ironJacamarXmlDescriptor, final ClassLoader classLoader,
public static ServiceBuilder<ResourceAdapterDeployment> process(final ConnectorXmlDescriptor connectorXmlDescriptor, final IronJacamarXmlDescriptor ironJacamarXmlDescriptor, final ClassLoader classLoader,
final ServiceTarget serviceTarget, final Map<ResourceRoot, Index> annotationIndexes, final ServiceName duServiceName,
final ManagementResourceRegistration registration, Resource deploymentResource) throws DeploymentUnitProcessingException {

Expand Down Expand Up @@ -190,28 +192,37 @@ public static ServiceBuilder process(final ConnectorXmlDescriptor connectorXmlDe
cmd = (new Merger()).mergeConnectorWithCommonIronJacamar(activation, cmd);
}

TransactionSupportEnum transactionSupport = TransactionSupportEnum.NoTransaction;
if (cmd != null && cmd.getResourceadapter() != null && cmd.getResourceadapter().getOutboundResourceadapter() != null) {
transactionSupport = cmd.getResourceadapter().getOutboundResourceadapter().getTransactionSupport();
}
if (activation != null && activation.getTransactionSupport() != null) {
transactionSupport = activation.getTransactionSupport();
}
final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
final ResourceAdapterDeploymentService raDeploymentService = new ResourceAdapterDeploymentService(connectorXmlDescriptor, cmd, activation, classLoader, deployerServiceName, duServiceName, registration, deploymentResource);

// Create the service
return Services.addServerExecutorDependency(
serviceTarget.addService(deployerServiceName, raDeploymentService),
raDeploymentService.getExecutorServiceInjector(), false)
.addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, raDeploymentService.getMdrInjector())
.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, raDeploymentService.getRaRepositoryInjector())
.addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, raDeploymentService.getManagementRepositoryInjector())
.addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, raDeploymentService.getRegistryInjector())
.addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, raDeploymentService.getTxIntegrationInjector())
.addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, raDeploymentService.getConfigInjector())
.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, raDeploymentService.getSubjectFactoryInjector())
.addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class, raDeploymentService.getServerSecurityManager())
.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector())
.addDependency(ConnectorServices.IDLE_REMOVER_SERVICE)
.addDependency(ConnectorServices.CONNECTION_VALIDATOR_SERVICE)
.addDependency(NamingService.SERVICE_NAME);



ServiceBuilder<ResourceAdapterDeployment> builder = Services.addServerExecutorDependency(
serviceTarget.addService(deployerServiceName, raDeploymentService),
raDeploymentService.getExecutorServiceInjector(), false)
.addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, raDeploymentService.getMdrInjector())
.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, raDeploymentService.getRaRepositoryInjector())
.addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, raDeploymentService.getManagementRepositoryInjector())
.addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, raDeploymentService.getRegistryInjector())
.addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, raDeploymentService.getTxIntegrationInjector())
.addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, raDeploymentService.getConfigInjector())
.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, raDeploymentService.getSubjectFactoryInjector())
.addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class, raDeploymentService.getServerSecurityManager())
.addDependency(ConnectorServices.IDLE_REMOVER_SERVICE)
.addDependency(ConnectorServices.CONNECTION_VALIDATOR_SERVICE)
.addDependency(NamingService.SERVICE_NAME);
if (transactionSupport == null || transactionSupport.equals(TransactionSupportEnum.NoTransaction)) {
builder.addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector());
} else {
builder.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector());
}
return builder;
} catch (Throwable t) {
throw new DeploymentUnitProcessingException(t);
}
Expand Down
Expand Up @@ -853,4 +853,7 @@ public interface ConnectorLogger extends BasicLogger {
@LogMessage(level = INFO)
@Message(id = 99, value = "Unbound non-transactional data source: %s")
void unBoundNonJTADataSource(String jndiName);

@Message(id = 100, value = "Operation %s is not supported")
UnsupportedOperationException noSupportedOperation(String operation);
}
@@ -0,0 +1,189 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.as.connector.services.jca;

import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER;

import javax.resource.spi.ActivationSpec;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ResourceAdapter;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.TransactionSynchronizationRegistry;
import javax.transaction.xa.XAResource;

import org.jboss.jca.core.api.connectionmanager.ConnectionManager;
import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager;
import org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl;
import org.jboss.jca.core.spi.recovery.RecoveryPlugin;
import org.jboss.jca.core.spi.security.SubjectFactory;
import org.jboss.jca.core.spi.transaction.ConnectableResource;
import org.jboss.jca.core.spi.transaction.TransactionIntegration;
import org.jboss.jca.core.spi.transaction.XAResourceStatistics;
import org.jboss.jca.core.spi.transaction.local.LocalXAResource;
import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecovery;
import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecoveryRegistry;
import org.jboss.jca.core.spi.transaction.usertx.UserTransactionRegistry;
import org.jboss.jca.core.spi.transaction.xa.XAResourceWrapper;
import org.jboss.jca.core.spi.transaction.xa.XATerminator;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;

/**
* Cached connection manager service
*/
public class NonTxCachedConnectionManagerService implements Service<CachedConnectionManager> {

private volatile CachedConnectionManager value;

private final boolean debug;
private final boolean error;
private final boolean ignoreUnknownConnections;

/** create an instance **/
public NonTxCachedConnectionManagerService(final boolean debug, final boolean error, boolean ignoreUnknownConnections) {
super();
this.debug = debug;
this.error = error;
this.ignoreUnknownConnections = ignoreUnknownConnections;
}

@Override
public CachedConnectionManager getValue() throws IllegalStateException, IllegalArgumentException {
return value;
}

@Override
public void start(StartContext context) throws StartException {
value = new CachedConnectionManagerImpl(new NoopTransactionIntegration());
value.setDebug(debug);
value.setError(error);
value.setIgnoreUnknownConnections(ignoreUnknownConnections);

value.start();
ROOT_LOGGER.debugf("Started CcmService %s", context.getController().getName());
}

@Override
public void stop(StopContext context) {
value.stop();
ROOT_LOGGER.debugf("Stopped CcmService %s", context.getController().getName());
}

/** No operation transaction integration */
private static class NoopTransactionIntegration implements TransactionIntegration {

@Override
public TransactionManager getTransactionManager() {
return null;
}

@Override
public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() {
return null;
}

@Override
public UserTransactionRegistry getUserTransactionRegistry() {
return null;
}

@Override
public XAResourceRecoveryRegistry getRecoveryRegistry() {
return null;
}

@Override
public XATerminator getXATerminator() {
return null;
}

@Override
public XAResourceRecovery createXAResourceRecovery(ResourceAdapter rar, ActivationSpec as, String productName,
String productVersion) {
throw ROOT_LOGGER.noSupportedOperation("createXAResourceRecovery");
}

@Override
public XAResourceRecovery createXAResourceRecovery(ManagedConnectionFactory mcf, Boolean pad, Boolean override,
Boolean wrapXAResource, String recoverUserName, String recoverPassword, String recoverSecurityDomain,
SubjectFactory subjectFactory, RecoveryPlugin plugin, XAResourceStatistics xastat) {
throw ROOT_LOGGER.noSupportedOperation("createXAResourceRecovery-Security");
}

@Override
public LocalXAResource createLocalXAResource(ConnectionManager cm, String productName, String productVersion,
String jndiName, XAResourceStatistics xastat) {
throw ROOT_LOGGER.noSupportedOperation("createLocalXAResource");
}

@Override
public LocalXAResource createConnectableLocalXAResource(ConnectionManager cm, String productName,
String productVersion, String jndiName, ConnectableResource cr, XAResourceStatistics xastat) {
throw ROOT_LOGGER.noSupportedOperation("createConnectableLocalXAResource");
}

@Override
public LocalXAResource createConnectableLocalXAResource(ConnectionManager cm, String productName,
String productVersion, String jndiName, ManagedConnection mc, XAResourceStatistics xastat) {
return null;
}

@Override
public XAResourceWrapper createXAResourceWrapper(XAResource xares, boolean pad, Boolean override, String productName,
String productVersion, String jndiName, boolean firstResource, XAResourceStatistics xastat) {
throw ROOT_LOGGER.noSupportedOperation("createXAResourceWrapper");
}

@Override
public XAResourceWrapper createConnectableXAResourceWrapper(XAResource xares, boolean pad, Boolean override,
String productName, String productVersion, String jndiName, ConnectableResource cr, XAResourceStatistics xastat) {
throw ROOT_LOGGER.noSupportedOperation("createConnectableXAResourceWrapper");
}

@Override
public XAResourceWrapper createConnectableXAResourceWrapper(XAResource xares, boolean pad, Boolean override,
String productName, String productVersion, String jndiName, ManagedConnection mc, XAResourceStatistics xastat) {
throw ROOT_LOGGER.noSupportedOperation("createConnectableXAResourceWrapper");
}

@Override
public boolean isFirstResource(ManagedConnection mc) {
throw ROOT_LOGGER.noSupportedOperation("isFirstResource");
}

@Override
public boolean isConnectableResource(ManagedConnection mc) {
throw ROOT_LOGGER.noSupportedOperation("isConnectableResource");
}

@Override
public Object getIdentifier(Transaction tx) {
throw ROOT_LOGGER.noSupportedOperation("getIdentifier");
}
}

}
Expand Up @@ -172,7 +172,8 @@ void firstRuntimeStep(OperationContext context, ModelNode operation, ModelNode m
.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector());

} else {
dataSourceServiceBuilder.addDependency(ConnectorServices.NON_JTA_DS_RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector());
dataSourceServiceBuilder.addDependency(ConnectorServices.NON_JTA_DS_RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector())
.addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector());

}
//Register an empty override model regardless of we're enabled or not - the statistics listener will add the relevant childresources
Expand Down
Expand Up @@ -23,6 +23,7 @@

import org.jboss.as.connector.deployers.ra.processors.CachedConnectionManagerSetupProcessor;
import org.jboss.as.connector.services.jca.CachedConnectionManagerService;
import org.jboss.as.connector.services.jca.NonTxCachedConnectionManagerService;
import org.jboss.as.connector.util.ConnectorServices;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.OperationContext;
Expand Down Expand Up @@ -75,5 +76,10 @@ protected void execute(DeploymentProcessorTarget processorTarget) {
ccmService.getTransactionIntegrationInjector())
.install();

NonTxCachedConnectionManagerService noTxCcm = new NonTxCachedConnectionManagerService(debug, error, ignoreUnknownConnections);
serviceTarget
.addService(ConnectorServices.NON_TX_CCM_SERVICE, noTxCcm)
.install();

}
}
Expand Up @@ -47,4 +47,6 @@ public class Constants {

static final String BOOTSTRAP_CONTEXT = "bootstrap-context";

static final String TX = "TX";
static final String NON_TX = "NonTX";
}

0 comments on commit 942f827

Please sign in to comment.