Skip to content

Instantly share code, notes, and snippets.

@maeste
Created October 19, 2010 19:35
Show Gist options
  • Save maeste/634913 to your computer and use it in GitHub Desktop.
Save maeste/634913 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 org.jboss.as.connector.deployers.RaDeploymentActivator;
import org.jboss.as.model.AbstractSubsystemAdd;
import org.jboss.as.model.UpdateContext;
import org.jboss.as.model.UpdateResultHandler;
import org.jboss.as.threads.ThreadsServices;
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.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;
/**
* @author <a href="mailto:david.lloyd@redhat.com">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 WorkManagerService wmService = new WorkManagerService(wm, injectLongRunningExecutor, injectLongRunningExecutor);
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.setInitialMode(Mode.ON_DEMAND);
final InjectedValue<WorkManager> injectWorkManager = new InjectedValue<WorkManager>();
CloneableBootstrapContext ctx = new BaseCloneableBootstrapContext();
final DefaultBootStrapContextService defaultBootCtxService = new DefaultBootStrapContextService(ctx, injectWorkManager);
final BatchServiceBuilder<CloneableBootstrapContext> defaultBootCtxServiceBuilder = builder.addService(
ConnectorServices.DEFAULT_BOOTSTRAP_CONTEXT_SERVICE, defaultBootCtxService);
defaultBootCtxServiceBuilder.addDependency(ConnectorServices.WORKMANAGER_SERVICE);
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);
configServiceBuilder.setInitialMode(Mode.IMMEDIATE);
}
protected ConnectorSubsystemElement createSubsystemElement() {
return new ConnectorSubsystemElement();
}
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.Version;
import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext;
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;
/**
* A ConnectorConfigService.
* @author <a href="stefano.maestri@jboss.com">Stefano Maestri</a>
*/
final class ConnectorConfigService implements Service<ConnectorSubsystemConfiguration> {
private final ConnectorSubsystemConfiguration value;
private final Value<CloneableBootstrapContext> defaultBootstrapContext;
private static final Logger log = Logger.getLogger("org.jboss.as.connector");
/** create an instance **/
public ConnectorConfigService(ConnectorSubsystemConfiguration value,
Value<CloneableBootstrapContext> defaultBootstrapContext) {
this.value = value;
this.defaultBootstrapContext = defaultBootstrapContext;
}
@Override
public ConnectorSubsystemConfiguration getValue() throws IllegalStateException {
return ConnectorServices.notNull(value);
}
@Override
public void start(StartContext context) throws StartException {
this.value.setDefaultBootstrapContext(defaultBootstrapContext.getValue());
log.infof("Starting JCA Subsystem (%s)", Version.FULL_VERSION);
log.tracef("config=%s", value);
}
@Override
public void stop(StopContext context) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment