Skip to content

Instantly share code, notes, and snippets.

@maeste
Created October 20, 2010 15:54
Show Gist options
  • Select an option

  • Save maeste/636689 to your computer and use it in GitHub Desktop.

Select an option

Save maeste/636689 to your computer and use it in GitHub Desktop.
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, 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;
import java.util.concurrent.Executor;
import javax.transaction.TransactionManager;
import javax.transaction.TransactionSynchronizationRegistry;
import org.jboss.as.connector.deployers.RaDeploymentActivator;
import org.jboss.as.model.AbstractSubsystemAdd;
import org.jboss.as.model.UpdateContext;
import org.jboss.as.model.UpdateFailedException;
import org.jboss.as.model.UpdateResultHandler;
import org.jboss.as.threads.ThreadsServices;
import org.jboss.as.txn.TxnServices;
import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext;
import org.jboss.jca.core.api.workmanager.WorkManager;
import org.jboss.jca.core.bootstrapcontext.BaseCloneableBootstrapContext;
import org.jboss.jca.core.workmanager.WorkManagerImpl;
import org.jboss.msc.inject.CastingInjector;
import org.jboss.msc.service.BatchBuilder;
import org.jboss.msc.service.BatchServiceBuilder;
import org.jboss.msc.service.ServiceActivatorContext;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.value.InjectedValue;
import org.jboss.tm.JBossXATerminator;
import com.arjuna.ats.internal.jbossatx.jta.jca.XATerminator;
import com.arjuna.ats.jbossatx.jta.TransactionManagerService;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ConnectorSubsystemAdd extends AbstractSubsystemAdd<ConnectorSubsystemElement> {
private static final long serialVersionUID = -874698675049495644L;
private boolean archiveValidation = true;
private boolean archiveValidationFailOnError = true;
private boolean archiveValidationFailOnWarn = false;
private boolean beanValidation = true;
private String shortRunningThreadPool = null;
private String longRunningThreadPool = null;
protected ConnectorSubsystemAdd() {
super(Namespace.CURRENT.getUriString());
}
@Override
protected <P> void applyUpdate(final UpdateContext updateContext, final UpdateResultHandler<? super Void, P> resultHandler,
final P param) {
final BatchBuilder builder = updateContext.getBatchBuilder();
new RaDeploymentActivator().activate(new ServiceActivatorContext() {
public BatchBuilder getBatchBuilder() {
return builder;
}
});
WorkManager wm = new WorkManagerImpl();
final InjectedValue<Executor> injectShortRunningExecutor = new InjectedValue<Executor>();
final InjectedValue<Executor> injectLongRunningExecutor = new InjectedValue<Executor>();
final InjectedValue<JBossXATerminator> xaTerminatorIjection = new InjectedValue<JBossXATerminator>();
final WorkManagerService wmService = new WorkManagerService(wm, injectLongRunningExecutor, injectLongRunningExecutor,
xaTerminatorIjection);
final BatchServiceBuilder<WorkManager> wmServiceBuilder = builder.addService(ConnectorServices.WORKMANAGER_SERVICE,
wmService);
wmServiceBuilder.addDependency(ThreadsServices.EXECUTOR.append(shortRunningThreadPool), Executor.class,
injectShortRunningExecutor);
wmServiceBuilder.addDependency(ThreadsServices.EXECUTOR.append(longRunningThreadPool), Executor.class,
injectLongRunningExecutor);
wmServiceBuilder.addDependency(TxnServices.JBOSS_TXN_XA_TERMINATOR, JBossXATerminator.class, xaTerminatorIjection);
wmServiceBuilder.setInitialMode(Mode.IMMEDIATE);
final InjectedValue<com.arjuna.ats.jbossatx.jta.TransactionManagerService> txManagerInjector = new InjectedValue<com.arjuna.ats.jbossatx.jta.TransactionManagerService>();
final InjectedValue<WorkManager> injectWorkManager = new InjectedValue<WorkManager>();
CloneableBootstrapContext ctx = new BaseCloneableBootstrapContext();
final DefaultBootStrapContextService defaultBootCtxService = new DefaultBootStrapContextService(ctx, injectWorkManager,
xaTerminatorIjection, txManagerInjector);
final BatchServiceBuilder<CloneableBootstrapContext> defaultBootCtxServiceBuilder = builder.addService(
ConnectorServices.DEFAULT_BOOTSTRAP_CONTEXT_SERVICE, defaultBootCtxService);
defaultBootCtxServiceBuilder.addDependency(ConnectorServices.WORKMANAGER_SERVICE, WorkManager.class, injectWorkManager);
defaultBootCtxServiceBuilder.addDependency(TxnServices.JBOSS_TXN_XA_TERMINATOR, JBossXATerminator.class,
xaTerminatorIjection);
defaultBootCtxServiceBuilder.addDependency(TxnServices.JBOSS_TXN_TRANSACTION_MANAGER,
new CastingInjector<com.arjuna.ats.jbossatx.jta.TransactionManagerService>(txManagerInjector,
com.arjuna.ats.jbossatx.jta.TransactionManagerService.class));
defaultBootCtxServiceBuilder.setInitialMode(Mode.IMMEDIATE);
final InjectedValue<CloneableBootstrapContext> injectDefaultBootStrapCtx = new InjectedValue<CloneableBootstrapContext>();
final ConnectorSubsystemConfiguration config = new ConnectorSubsystemConfiguration();
config.setArchiveValidation(archiveValidation);
config.setArchiveValidationFailOnError(archiveValidationFailOnError);
config.setArchiveValidationFailOnWarn(archiveValidationFailOnWarn);
config.setBeanValidation(beanValidation);
final ConnectorConfigService connectorConfigService = new ConnectorConfigService(config, injectDefaultBootStrapCtx);
final BatchServiceBuilder<ConnectorSubsystemConfiguration> configServiceBuilder = builder.addService(
ConnectorServices.CONNECTOR_CONFIG_SERVICE, connectorConfigService);
configServiceBuilder.addDependency(ConnectorServices.DEFAULT_BOOTSTRAP_CONTEXT_SERVICE,
CloneableBootstrapContext.class, injectDefaultBootStrapCtx);
configServiceBuilder.setInitialMode(Mode.IMMEDIATE);
}
protected void applyUpdate(ConnectorSubsystemElement element) throws UpdateFailedException {
element.setArchiveValidation(archiveValidation);
element.setArchiveValidationFailOnError(archiveValidationFailOnError);
element.setArchiveValidationFailOnWarn(archiveValidationFailOnWarn);
element.setBeanValidation(beanValidation);
element.setLongRunningThreadPool(longRunningThreadPool);
element.setShortRunningThreadPool(shortRunningThreadPool);
}
protected ConnectorSubsystemElement createSubsystemElement() {
ConnectorSubsystemElement element = new ConnectorSubsystemElement();
element.setArchiveValidation(archiveValidation);
element.setArchiveValidationFailOnError(archiveValidationFailOnError);
element.setArchiveValidationFailOnWarn(archiveValidationFailOnWarn);
element.setBeanValidation(beanValidation);
element.setLongRunningThreadPool(longRunningThreadPool);
element.setShortRunningThreadPool(shortRunningThreadPool);
return element;
}
public boolean isArchiveValidation() {
return archiveValidation;
}
public void setArchiveValidation(final boolean archiveValidation) {
this.archiveValidation = archiveValidation;
}
public boolean isArchiveValidationFailOnError() {
return archiveValidationFailOnError;
}
public void setArchiveValidationFailOnError(final boolean archiveValidationFailOnError) {
this.archiveValidationFailOnError = archiveValidationFailOnError;
}
public boolean isArchiveValidationFailOnWarn() {
return archiveValidationFailOnWarn;
}
public void setArchiveValidationFailOnWarn(final boolean archiveValidationFailOnWarn) {
this.archiveValidationFailOnWarn = archiveValidationFailOnWarn;
}
public boolean isBeanValidation() {
return beanValidation;
}
public void setBeanValidation(final boolean beanValidation) {
this.beanValidation = beanValidation;
}
public String getShortRunningThreadPool() {
return shortRunningThreadPool;
}
public void setShortRunningThreadPool(String shortRunningThreadPool) {
this.shortRunningThreadPool = shortRunningThreadPool;
}
public String getLongRunningThreadPool() {
return longRunningThreadPool;
}
public void setLongRunningThreadPool(String longRunningThreadPool) {
this.longRunningThreadPool = longRunningThreadPool;
}
}
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, 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;
import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext;
import org.jboss.jca.core.api.workmanager.WorkManager;
import org.jboss.logging.Logger;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.Value;
import org.jboss.tm.JBossXATerminator;
/**
* A DefaultBootStrapContextService Service
* @author <a href="[email protected]">Stefano Maestri</a>
*/
final class DefaultBootStrapContextService implements Service<CloneableBootstrapContext> {
private final CloneableBootstrapContext value;
private final Value<WorkManager> workManagerValue;
private final Value<com.arjuna.ats.jbossatx.jta.TransactionManagerService> txManager;
private final Value<JBossXATerminator> xaTerminator;
public Value<WorkManager> getWorkManagerValue() {
return workManagerValue;
}
private static final Logger log = Logger.getLogger("org.jboss.as.connector");
/** create an instance **/
public DefaultBootStrapContextService(CloneableBootstrapContext value, Value<WorkManager> workManagerValue,
Value<JBossXATerminator> xaTerminator, Value<com.arjuna.ats.jbossatx.jta.TransactionManagerService> txManager) {
log.infof("Building DefaultBootstrapContext");
this.value = value;
this.workManagerValue = workManagerValue;
this.txManager = txManager;
this.xaTerminator = xaTerminator;
}
@Override
public CloneableBootstrapContext getValue() throws IllegalStateException {
return ConnectorServices.notNull(value);
}
@Override
public void start(StartContext context) throws StartException {
this.value.setWorkManager(workManagerValue.getValue());
this.value.setTransactionSynchronizationRegistry(txManager.getValue().getTransactionSynchronizationRegistry());
this.value.setXATerminator(xaTerminator.getValue());
log.infof("Starting JCA DefaultBootstrapContext");
}
@Override
public void stop(StopContext context) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment