Skip to content

Commit

Permalink
WFCORE-1841 lazy subsystem parser support
Browse files Browse the repository at this point in the history
- introduces parser providers (via staxmapper 1.3)
- migrates core subsystems to use it
- should redurce memory usage down a bit
  • Loading branch information
ctomc committed Oct 19, 2016
1 parent 3326d90 commit 1b10ebc
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 42 deletions.
Expand Up @@ -93,9 +93,10 @@ private PersistentResourceXMLDescription(PersistentResourceXMLBuilder builder) {
this.attributeGroups = null;
}
this.children = new ArrayList<>();
for (PersistentResourceXMLBuilder b : builder.children) {
for (PersistentResourceXMLBuilder b : builder.childrenBuilder) {
this.children.add(b.build());
}
builder.children.forEach(this.children::add);
this.useValueAsElementName = builder.useValueAsElementName;
this.noAddOperation = builder.noAddOperation;
this.additionalOperationsGenerator = builder.additionalOperationsGenerator;
Expand Down Expand Up @@ -462,7 +463,8 @@ public static class PersistentResourceXMLBuilder {
protected boolean noAddOperation;
protected AdditionalOperationsGenerator additionalOperationsGenerator;
protected final LinkedList<AttributeDefinition> attributeList = new LinkedList<>();
protected final List<PersistentResourceXMLBuilder> children = new ArrayList<>();
final List<PersistentResourceXMLBuilder> childrenBuilder = new ArrayList<>();
final List<PersistentResourceXMLDescription> children = new ArrayList<>();
protected final LinkedHashMap<String, AttributeParser> attributeParsers = new LinkedHashMap<>();
protected final LinkedHashMap<String, AttributeMarshaller> attributeMarshallers = new LinkedHashMap<>();
protected boolean useElementsForGroups = true;
Expand Down Expand Up @@ -502,6 +504,11 @@ protected PersistentResourceXMLBuilder(final PathElement pathElement, String nam
}

public PersistentResourceXMLBuilder addChild(PersistentResourceXMLBuilder builder) {
this.childrenBuilder.add(builder);
return this;
}

public PersistentResourceXMLBuilder addChild(PersistentResourceXMLDescription builder) {
this.children.add(builder);
return this;
}
Expand Down
Expand Up @@ -35,7 +35,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import java.util.function.Supplier;
import javax.xml.namespace.QName;

import org.jboss.as.controller.AttributeDefinition;
Expand Down Expand Up @@ -456,6 +456,18 @@ public void setSubsystemXmlMapping(String subsystemName, String namespaceUri, XM
}
}

@Override
public void setSubsystemXmlMapping(String subsystemName, String namespaceUri, Supplier<XMLElementReader<List<ModelNode>>> supplier){
assert subsystemName != null : "subsystemName is null";
assert namespaceUri != null : "namespaceUri is null";
synchronized (extension) {
extension.getSubsystemInfo(subsystemName).addParsingNamespace(namespaceUri);
if (extension.xmlMapper != null) {
extension.xmlMapper.registerRootElement(new QName(namespaceUri, SUBSYSTEM), supplier);
}
}
}

@Override
public void setProfileParsingCompletionHandler(ProfileParsingCompletionHandler handler) {
assert handler != null : "handler is null";
Expand Down
Expand Up @@ -23,6 +23,7 @@
package org.jboss.as.controller.parsing;

import java.util.List;
import java.util.function.Supplier;


import org.jboss.as.controller.ProcessType;
Expand Down Expand Up @@ -66,6 +67,9 @@ public interface ExtensionParsingContext {
*/
void setSubsystemXmlMapping(String subsystemName, String namespaceUri, XMLElementReader<List<ModelNode>> reader);


void setSubsystemXmlMapping(String subsystemName, String namespaceUri, Supplier<XMLElementReader<List<ModelNode>>> supplier);

/**
* Registers a {@link ProfileParsingCompletionHandler} to receive a callback upon completion of parsing of a
* profile.
Expand Down
Expand Up @@ -70,7 +70,7 @@ public void initialize(ExtensionContext context) {
}

final SubsystemRegistration subsystem = context.registerSubsystem(CommonAttributes.DEPLOYMENT_SCANNER, CURRENT_VERSION);
subsystem.registerXMLElementWriter(DeploymentScannerParser_2_0.INSTANCE);
subsystem.registerXMLElementWriter(new DeploymentScannerParser_2_0());

final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(new DeploymentScannerSubsystemDefinition());
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE);
Expand All @@ -89,9 +89,9 @@ public void initialize(ExtensionContext context) {
*/
@Override
public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DEPLOYMENT_SCANNER_1_0.getUriString(), DeploymentScannerParser_1_0.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DEPLOYMENT_SCANNER_1_1.getUriString(), DeploymentScannerParser_1_1.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DEPLOYMENT_SCANNER_2_0.getUriString(), DeploymentScannerParser_2_0.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DEPLOYMENT_SCANNER_1_0.getUriString(), DeploymentScannerParser_1_0::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DEPLOYMENT_SCANNER_1_1.getUriString(), DeploymentScannerParser_1_1::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DEPLOYMENT_SCANNER_2_0.getUriString(), DeploymentScannerParser_2_0::new);

}

Expand Down
Expand Up @@ -50,8 +50,6 @@
*/
class DeploymentScannerParser_1_0 implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {

public static final DeploymentScannerParser_1_0 INSTANCE = new DeploymentScannerParser_1_0();

/** {@inheritDoc} */
@Override
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
Expand Down
Expand Up @@ -49,8 +49,6 @@
*/
class DeploymentScannerParser_1_1 implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {

public static final DeploymentScannerParser_1_1 INSTANCE = new DeploymentScannerParser_1_1();

/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -49,8 +49,6 @@
*/
class DeploymentScannerParser_2_0 implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {

public static final DeploymentScannerParser_2_0 INSTANCE = new DeploymentScannerParser_2_0();

/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -58,16 +58,16 @@ public static StandardResourceDescriptionResolver getResolver(final String... ke

@Override
public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.IO_1_0.getUriString(), IOSubsystemParser_1_0.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.IO_1_1.getUriString(), IOSubsystemParser_1_1.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.IO_1_0.getUriString(), IOSubsystemParser_1_0::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.IO_1_1.getUriString(), IOSubsystemParser_1_1::new);
}

@Override
public void initialize(ExtensionContext context) {
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, ModelVersion.create(2));
final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(IORootDefinition.INSTANCE);
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE, false);
subsystem.registerXMLElementWriter(IOSubsystemParser_1_1.INSTANCE);
subsystem.registerXMLElementWriter(new IOSubsystemParser_1_1());
}


Expand Down
Expand Up @@ -33,11 +33,9 @@
*/
class IOSubsystemParser_1_0 extends PersistentResourceXMLParser {

static final IOSubsystemParser_1_0 INSTANCE = new IOSubsystemParser_1_0();

private final PersistentResourceXMLDescription xmlDescription;

private IOSubsystemParser_1_0() {
IOSubsystemParser_1_0() {
xmlDescription = builder(IORootDefinition.INSTANCE.getPathElement())
.addChild(
builder(WorkerResourceDefinition.INSTANCE.getPathElement())
Expand Down
Expand Up @@ -33,8 +33,6 @@
* @author <a href="mailto:tomaz.cerar@redhat.com">Tomaz Cerar</a> (c) 2013 Red Hat Inc.
*/
class IOSubsystemParser_1_1 extends PersistentResourceXMLParser {
static final IOSubsystemParser_1_1 INSTANCE = new IOSubsystemParser_1_1();


private static final PersistentResourceXMLDescription xmlDescription;

Expand Down
12 changes: 4 additions & 8 deletions jmx/src/main/java/org/jboss/as/jmx/JMXExtension.java
Expand Up @@ -79,10 +79,6 @@ static ResourceDescriptionResolver getResourceDescriptionResolver(final String k
new SensitivityClassification(SUBSYSTEM_NAME, "jmx", false, false, true);

static final SensitiveTargetAccessConstraintDefinition JMX_SENSITIVITY_DEF = new SensitiveTargetAccessConstraintDefinition(JMX_SENSITIVITY);
static final JMXSubsystemParser_1_3 parserCurrent = new JMXSubsystemParser_1_3();
static final JMXSubsystemParser_1_2 parser12 = new JMXSubsystemParser_1_2();
static final JMXSubsystemParser_1_1 parser11 = new JMXSubsystemParser_1_1();
static final JMXSubsystemParser_1_0 parser10 = new JMXSubsystemParser_1_0();
static final JMXSubsystemWriter writer = new JMXSubsystemWriter();

private static final int MANAGEMENT_API_MAJOR_VERSION = 1;
Expand Down Expand Up @@ -120,10 +116,10 @@ public void initialize(ExtensionContext context) {
*/
@Override
public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JMX_1_0.getUriString(), parser10);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JMX_1_1.getUriString(), parser11);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JMX_1_2.getUriString(), parser12);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JMX_1_3.getUriString(), parserCurrent);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JMX_1_0.getUriString(), JMXSubsystemParser_1_0::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JMX_1_1.getUriString(), JMXSubsystemParser_1_1::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JMX_1_2.getUriString(), JMXSubsystemParser_1_2::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JMX_1_3.getUriString(), JMXSubsystemParser_1_3::new);
}

private static ModelNode createAddOperation() {
Expand Down
21 changes: 11 additions & 10 deletions logging/src/main/java/org/jboss/as/logging/LoggingExtension.java
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.function.Supplier;

import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ExtensionContext;
Expand Down Expand Up @@ -229,14 +230,14 @@ public void initialize(final ExtensionContext context) {

@Override
public void initializeParsers(final ExtensionParsingContext context) {
setParser(context, Namespace.LOGGING_1_0, new LoggingSubsystemParser_1_0());
setParser(context, Namespace.LOGGING_1_1, new LoggingSubsystemParser_1_1());
setParser(context, Namespace.LOGGING_1_2, new LoggingSubsystemParser_1_2());
setParser(context, Namespace.LOGGING_1_3, new LoggingSubsystemParser_1_3());
setParser(context, Namespace.LOGGING_1_4, new LoggingSubsystemParser_1_4());
setParser(context, Namespace.LOGGING_1_5, new LoggingSubsystemParser_1_5());
setParser(context, Namespace.LOGGING_2_0, new LoggingSubsystemParser_2_0());
setParser(context, Namespace.LOGGING_3_0, new LoggingSubsystemParser_3_0());
setParser(context, Namespace.LOGGING_1_0, LoggingSubsystemParser_1_0::new);
setParser(context, Namespace.LOGGING_1_1, LoggingSubsystemParser_1_1::new);
setParser(context, Namespace.LOGGING_1_2, LoggingSubsystemParser_1_2::new);
setParser(context, Namespace.LOGGING_1_3, LoggingSubsystemParser_1_3::new);
setParser(context, Namespace.LOGGING_1_4, LoggingSubsystemParser_1_4::new);
setParser(context, Namespace.LOGGING_1_5, LoggingSubsystemParser_1_5::new);
setParser(context, Namespace.LOGGING_2_0, LoggingSubsystemParser_2_0::new);
setParser(context, Namespace.LOGGING_3_0, LoggingSubsystemParser_3_0::new);
}

private void registerLoggingProfileSubModels(final ManagementResourceRegistration registration, final PathManager pathManager) {
Expand Down Expand Up @@ -342,8 +343,8 @@ private void registerTransformers(final ChainedTransformationDescriptionBuilder
}
}

private static void setParser(final ExtensionParsingContext context, final Namespace namespace, final XMLElementReader<List<ModelNode>> parser) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, namespace.getUriString(), parser);
private static void setParser(final ExtensionParsingContext context, final Namespace namespace, final Supplier<XMLElementReader<List<ModelNode>>> supplier) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, namespace.getUriString(), supplier);
}

private static boolean getBooleanProperty(final String property) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -118,7 +118,7 @@
<version.org.jboss.slf4j.slf4j-jboss-logmanager>1.0.3.GA</version.org.jboss.slf4j.slf4j-jboss-logmanager>
<version.org.jboss.logging.jul-to-slf4j-stub>1.0.1.Final</version.org.jboss.logging.jul-to-slf4j-stub>
<version.org.jboss.spec.javax.interceptor.jboss-interceptors-api_1.2_spec>1.0.0.Final</version.org.jboss.spec.javax.interceptor.jboss-interceptors-api_1.2_spec>
<version.org.jboss.staxmapper>1.2.0.Final</version.org.jboss.staxmapper>
<version.org.jboss.staxmapper>1.3.0.Final</version.org.jboss.staxmapper>
<version.org.jboss.stdio>1.0.2.GA</version.org.jboss.stdio>
<version.org.jboss.threads>2.2.1.Final</version.org.jboss.threads>
<version.org.jboss.xnio>3.4.0.Final</version.org.jboss.xnio>
Expand Down
Expand Up @@ -88,8 +88,8 @@
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.as.controller.registry.OperationEntry.Flag;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.transform.OperationTransformer.TransformedOperation;
import org.jboss.as.controller.transform.ExtensionTransformerRegistration;
import org.jboss.as.controller.transform.OperationTransformer.TransformedOperation;
import org.jboss.as.model.test.ChildFirstClassLoaderBuilder;
import org.jboss.as.model.test.EAPRepositoryReachableUtil;
import org.jboss.as.model.test.ModelFixer;
Expand All @@ -107,6 +107,7 @@
import org.jboss.as.subsystem.test.ModelDescriptionValidator.ValidationConfiguration;
import org.jboss.dmr.ModelNode;
import org.jboss.modules.filter.ClassFilter;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLMapper;
import org.junit.Assert;
import org.junit.Assume;
Expand Down Expand Up @@ -556,7 +557,7 @@ private ExtensionRegistry cloneExtensionRegistry(AdditionalInitialization additi
ExtensionParsingContext epc = clone.getExtensionParsingContext(extension, null);
for (Map.Entry<String, SubsystemInformation> entry : extensionParsingRegistry.getAvailableSubsystems(extension).entrySet()) {
for (String namespace : entry.getValue().getXMLNamespaces()) {
epc.setSubsystemXmlMapping(entry.getKey(), namespace, null);
epc.setSubsystemXmlMapping(entry.getKey(), namespace, (XMLElementReader) null);
}
}
}
Expand Down

0 comments on commit 1b10ebc

Please sign in to comment.