Skip to content

Commit

Permalink
Merge pull request #9601 from mkouba/WFLY-6513
Browse files Browse the repository at this point in the history
WFLY-6513 Allow to configure the size of the global Weld thread pool
  • Loading branch information
kabir committed Feb 15, 2017
2 parents 4b12bf1 + 52ba895 commit 89894bf
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 31 deletions.
49 changes: 31 additions & 18 deletions weld/subsystem/src/main/java/org/jboss/as/weld/WeldExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
import org.jboss.as.controller.parsing.ExtensionParsingContext;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.transform.TransformationContext;
import org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.DiscardAttributeChecker;
import org.jboss.as.controller.transform.description.RejectAttributeChecker;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.TransformationDescription;
import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder;
import org.jboss.as.weld.logging.WeldLogger;
import org.jboss.dmr.ModelNode;
Expand All @@ -61,7 +61,7 @@ public class WeldExtension implements Extension {

private static final String RESOURCE_NAME = WeldExtension.class.getPackage().getName() + ".LocalDescriptions";

private static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(3, 0, 0);
private static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(4, 0, 0);

static StandardResourceDescriptionResolver getResourceDescriptionResolver(final String... keyPrefix) {
StringBuilder prefix = new StringBuilder(SUBSYSTEM_NAME);
Expand All @@ -78,7 +78,7 @@ public void initialize(final ExtensionContext context) {
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION);
final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(WeldResourceDefinition.INSTANCE);
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE);
subsystem.registerXMLElementWriter(WeldSubsystem30Parser.INSTANCE);
subsystem.registerXMLElementWriter(WeldSubsystem40Parser.INSTANCE);

if (context.isRegisterTransformers()) {
registerTransformers(subsystem);
Expand All @@ -88,15 +88,30 @@ public void initialize(final ExtensionContext context) {
/** {@inheritDoc} */
@Override
public void initializeParsers(final ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, WeldSubsystem10Parser.NAMESPACE, WeldSubsystem10Parser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, WeldSubsystem20Parser.NAMESPACE, WeldSubsystem20Parser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, WeldSubsystem30Parser.NAMESPACE, WeldSubsystem30Parser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, WeldSubsystem10Parser.NAMESPACE, () -> WeldSubsystem10Parser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, WeldSubsystem20Parser.NAMESPACE, () -> WeldSubsystem20Parser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, WeldSubsystem30Parser.NAMESPACE, () -> WeldSubsystem30Parser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, WeldSubsystem40Parser.NAMESPACE, () -> WeldSubsystem40Parser.INSTANCE);
}

private void registerTransformers(SubsystemRegistration subsystem) {
ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createSubsystemInstance();
builder.getAttributeBuilder()
//These new attributes are assumed to be 'true' in the old version but default to false in the current version. So discard if 'true' and reject if 'undefined'.
ModelVersion version1_0_0 = ModelVersion.create(1, 0, 0);
ModelVersion version3_0_0 = ModelVersion.create(3, 0, 0);

ChainedTransformationDescriptionBuilder chainedBuilder = TransformationDescriptionBuilder.Factory
.createChainedSubystemInstance(subsystem.getSubsystemVersion());

// Differences between the current version and 3.0.0
ResourceTransformationDescriptionBuilder builder300 = chainedBuilder.createBuilder(subsystem.getSubsystemVersion(), version3_0_0);
builder300.getAttributeBuilder().setDiscard(DiscardAttributeChecker.UNDEFINED, WeldResourceDefinition.THREAD_POOL_SIZE_ATTRIBUTE)
// Reject thread-pool-size attribute if defined
.addRejectCheck(RejectAttributeChecker.DEFINED, WeldResourceDefinition.THREAD_POOL_SIZE_ATTRIBUTE).end();

// Differences between 3.0.0 and 1.0.0
ResourceTransformationDescriptionBuilder builder100 = chainedBuilder.createBuilder(version3_0_0, version1_0_0);
builder100.getAttributeBuilder()
// These new attributes are assumed to be 'true' in the old version but default to false in the current version. So discard if 'true' and reject
// if 'undefined'.
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, false, new ModelNode(true)),
WeldResourceDefinition.NON_PORTABLE_MODE_ATTRIBUTE, WeldResourceDefinition.REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE)
.addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {
Expand All @@ -107,19 +122,17 @@ public String getRejectionLogMessage(Map<String, ModelNode> attributes) {
}

@Override
protected boolean rejectAttribute(PathAddress address, String attributeName, ModelNode attributeValue,
TransformationContext context) {
//This will not get called if it was discarded, so reject if it is undefined (default==false) or if defined and != 'true'
protected boolean rejectAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
// This will not get called if it was discarded, so reject if it is undefined (default==false) or if defined and != 'true'
return !attributeValue.isDefined() || !attributeValue.asString().equals("true");
}
}, WeldResourceDefinition.NON_PORTABLE_MODE_ATTRIBUTE, WeldResourceDefinition.REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE)

// development mode - not supported in older versions
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(false)),
WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE)
// if the attribute was not discarded it means that it is defined as 'true'. Therefore, reject.
.addRejectCheck(RejectAttributeChecker.DEFINED, WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE)
.end();
TransformationDescription.Tools.register(builder.build(), subsystem, ModelVersion.create(1, 0, 0));
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(false)), WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE)
// if the attribute was not discarded it means that it is defined as 'true'. Therefore, reject.
.addRejectCheck(RejectAttributeChecker.DEFINED, WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE).end();

chainedBuilder.buildAndRegister(subsystem, new ModelVersion[] { version1_0_0, version3_0_0 });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.operations.validation.IntRangeValidator;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

Expand All @@ -45,6 +46,7 @@ class WeldResourceDefinition extends PersistentResourceDefinition {
static final String REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE_NAME = "require-bean-descriptor";
static final String NON_PORTABLE_MODE_ATTRIBUTE_NAME = "non-portable-mode";
static final String DEVELOPMENT_MODE_ATTRIBUTE_NAME = "development-mode";
static final String THREAD_POOL_SIZE = "thread-pool-size";

static final SimpleAttributeDefinition REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE =
new SimpleAttributeDefinitionBuilder(REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE_NAME, ModelType.BOOLEAN, true)
Expand All @@ -67,6 +69,13 @@ class WeldResourceDefinition extends PersistentResourceDefinition {
.setRestartAllServices()
.build();

static final SimpleAttributeDefinition THREAD_POOL_SIZE_ATTRIBUTE =
new SimpleAttributeDefinitionBuilder(THREAD_POOL_SIZE, ModelType.INT, true)
.setAllowExpression(true)
.setValidator(new IntRangeValidator(1))
.setRestartAllServices()
.build();

private WeldResourceDefinition() {
super(
WeldExtension.PATH_SUBSYSTEM,
Expand All @@ -77,6 +86,6 @@ private WeldResourceDefinition() {

@Override
public Collection<AttributeDefinition> getAttributes() {
return Arrays.asList(new AttributeDefinition[] {REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE, NON_PORTABLE_MODE_ATTRIBUTE, DEVELOPMENT_MODE_ATTRIBUTE});
return Arrays.asList(new AttributeDefinition[] {REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE, NON_PORTABLE_MODE_ATTRIBUTE, DEVELOPMENT_MODE_ATTRIBUTE, THREAD_POOL_SIZE_ATTRIBUTE});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2017, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.weld;

import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentResourceXMLParser;

class WeldSubsystem40Parser extends PersistentResourceXMLParser {

public static final String NAMESPACE = "urn:jboss:domain:weld:4.0";
static final WeldSubsystem40Parser INSTANCE = new WeldSubsystem40Parser();
private static final PersistentResourceXMLDescription xmlDescription;

static {
xmlDescription = PersistentResourceXMLDescription.builder(WeldResourceDefinition.INSTANCE, NAMESPACE)
.addAttributes(WeldResourceDefinition.NON_PORTABLE_MODE_ATTRIBUTE, WeldResourceDefinition.REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE,
WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE, WeldResourceDefinition.THREAD_POOL_SIZE_ATTRIBUTE)
.build();
}

private WeldSubsystem40Parser() {
}

@Override
public PersistentResourceXMLDescription getParserDescription() {
return xmlDescription;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protected void populateModel(ModelNode operation, ModelNode model) throws Operat
WeldResourceDefinition.REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE.validateAndSet(operation, model);
WeldResourceDefinition.NON_PORTABLE_MODE_ATTRIBUTE.validateAndSet(operation, model);
WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE.validateAndSet(operation, model);
WeldResourceDefinition.THREAD_POOL_SIZE_ATTRIBUTE.validateAndSet(operation, model);
}

@Override
Expand All @@ -81,6 +82,8 @@ protected void performBoottime(final OperationContext context, ModelNode operati
final boolean requireBeanDescriptor = REQUIRE_BEAN_DESCRIPTOR_ATTRIBUTE.resolveModelAttribute(context, model).asBoolean();
final boolean nonPortableMode = WeldResourceDefinition.NON_PORTABLE_MODE_ATTRIBUTE.resolveModelAttribute(context, model).asBoolean();
final boolean developmentMode = WeldResourceDefinition.DEVELOPMENT_MODE_ATTRIBUTE.resolveModelAttribute(context, model).asBoolean();
final int threadPoolSize = WeldResourceDefinition.THREAD_POOL_SIZE_ATTRIBUTE.resolveModelAttribute(context, model)
.asInt(WeldExecutorServices.DEFAULT_BOUND);

context.addStep(new AbstractDeploymentChainStep() {
@Override
Expand Down Expand Up @@ -118,7 +121,7 @@ protected void execute(DeploymentProcessorTarget processorTarget) {
context.getServiceTarget().addService(TCCLSingletonService.SERVICE_NAME, singleton).setInitialMode(
Mode.ON_DEMAND).install();

context.getServiceTarget().addService(WeldExecutorServices.SERVICE_NAME, new WeldExecutorServices()).setInitialMode(Mode.ON_DEMAND).install();
context.getServiceTarget().addService(WeldExecutorServices.SERVICE_NAME, new WeldExecutorServices(threadPoolSize)).setInitialMode(Mode.ON_DEMAND).install();
}

// Synchronization objects created by iiop ejb beans require wrapping by JTSSychronizationWrapper to work correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@
*/
public class WeldExecutorServices extends AbstractExecutorServices implements Service<ExecutorServices> {

public static final int DEFAULT_BOUND = Runtime.getRuntime().availableProcessors() + 1;
public static final ServiceName SERVICE_NAME = Services.JBOSS_AS.append("weld", "executor");
private static final String THREAD_NAME_PATTERN = "Weld Thread Pool -- %t";

private final int bound;
private ExecutorService executor;

public WeldExecutorServices() {
this.bound = Runtime.getRuntime().availableProcessors() + 1;
this(DEFAULT_BOUND);
}

public WeldExecutorServices(int bound) {
this.bound = bound;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ weld.remove=Operation removing the weld subsystem.
weld.require-bean-descriptor=If true then implicit bean archives without bean descriptor file (beans.xml) are ignored by Weld
weld.non-portable-mode=If true then the non-portable mode is enabled. The non-portable mode is suggested by the specification to overcome problems with legacy applications that do not use CDI SPI properly and may be rejected by more strict validation in CDI 1.1.
weld.development-mode=Weld comes with a special mode for application development. When the development mode is enabled, certain built-in tools, which facilitate the development of CDI applications, are available. Setting this attribute to true activates the development mode.
weld.thread-pool-size=The number of threads to be used by the Weld thread pool. The pool is shared across all CDI-enabled deployments and used primarily for parallel Weld bootstrap.
59 changes: 59 additions & 0 deletions weld/subsystem/src/main/resources/schema/jboss-as-weld_4_0.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2015, 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.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:jboss:domain:weld:4.0"
xmlns="urn:jboss:domain:weld:4.0"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="4.0">

<!-- The Weld subsystem root element -->

<xs:element name="subsystem" type="subsystem"/>

<xs:complexType name="subsystem">
<xs:attribute name="require-bean-descriptor" type="xs:boolean" default="false">
<xs:annotation>
<xs:documentation>If true then implicit bean archives without bean descriptor file (beans.xml) are ignored by Weld</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="non-portable-mode" type="xs:boolean" default="false">
<xs:annotation>
<xs:documentation>If true then the non-portable mode is enabled. The non-portable mode is suggested by the specification to overcome problems with legacy applications that do not use CDI SPI properly and may be rejected by more strict validation in CDI 1.1.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="development-mode" type="xs:boolean" default="false">
<xs:annotation>
<xs:documentation>Weld comes with a special mode for application development. When the development mode is enabled, certain built-in tools, which facilitate the development of CDI applications, are available. Setting this attribute to true activates the development mode.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="thread-pool-size" type="xs:int">
<xs:annotation>
<xs:documentation>The number of threads to be used by the Weld thread pool. The pool is shared across all CDI-enabled deployments and used primarily for parallel Weld bootstrap.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>

</xs:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<!-- See src/resources/configuration/ReadMe.txt for how the configuration assembly works -->
<config>
<extension-module>org.jboss.as.weld</extension-module>
<subsystem xmlns="urn:jboss:domain:weld:3.0"/>
<subsystem xmlns="urn:jboss:domain:weld:4.0"/>
</config>

0 comments on commit 89894bf

Please sign in to comment.