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 c4f2d7a
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 85 deletions.
Expand Up @@ -35,14 +35,14 @@
public final class PersistentResourceXMLDescription {

protected final PathElement pathElement;
protected final String xmlElementName;
protected final String xmlWrapperElement;
protected final LinkedHashMap<String, LinkedHashMap<String, AttributeDefinition>> attributesByGroup;
private final String xmlElementName;
private final String xmlWrapperElement;
private final LinkedHashMap<String, LinkedHashMap<String, AttributeDefinition>> attributesByGroup;
protected final List<PersistentResourceXMLDescription> children;
protected final Map<String, AttributeDefinition> attributeElements = new HashMap<>();
protected final boolean useValueAsElementName;
protected final boolean noAddOperation;
protected final AdditionalOperationsGenerator additionalOperationsGenerator;
private final Map<String, AttributeDefinition> attributeElements = new HashMap<>();
private final boolean useValueAsElementName;
private final boolean noAddOperation;
private final AdditionalOperationsGenerator additionalOperationsGenerator;
private boolean flushRequired = true;
private boolean childAlreadyRead = false;
private final Map<String, AttributeParser> attributeParsers;
Expand All @@ -65,7 +65,7 @@ private PersistentResourceXMLDescription(PersistentResourceXMLBuilder builder) {
this.namespaceURI = builder.namespaceURI;
if (useElementsForGroups) {
// Ensure we have a map for the default group even if there are no attributes so we don't NPE later
this.attributesByGroup.put(null, new LinkedHashMap<String, AttributeDefinition>());
this.attributesByGroup.put(null, new LinkedHashMap<>());
this.attributeGroups = new HashSet<>();
// Segregate attributes by group
for (AttributeDefinition ad : builder.attributeList) {
Expand Down 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.childrenBuilders) {
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 @@ -417,7 +418,18 @@ public void persistChildren(XMLExtendedStreamWriter writer, ModelNode model) thr
@SuppressWarnings("deprecation")
@Deprecated
public static PersistentResourceXMLBuilder builder(PersistentResourceDefinition resource) {
return new PersistentResourceXMLBuilder(resource);
return new PersistentResourceXMLBuilder(resource.getPathElement());
}

/**
* @param resource resource for which path we are creating builder
* @return PersistentResourceXMLBuilder
* @deprecated please use {@linkplain PersistentResourceXMLBuilder(PathElement, String)} variant
*/
@SuppressWarnings("deprecation")
@Deprecated
public static PersistentResourceXMLBuilder builder(ResourceDefinition resource) {
return new PersistentResourceXMLBuilder(resource.getPathElement());
}

/**
Expand All @@ -430,7 +442,7 @@ public static PersistentResourceXMLBuilder builder(PersistentResourceDefinition
@SuppressWarnings("deprecation")
@Deprecated
public static PersistentResourceXMLBuilder builder(PersistentResourceDefinition resource, String namespaceURI) {
return new PersistentResourceXMLBuilder(resource, namespaceURI);
return new PersistentResourceXMLBuilder(resource.getPathElement(), namespaceURI);
}

/**
Expand All @@ -453,55 +465,42 @@ public static PersistentResourceXMLBuilder builder(final PathElement pathElement
return new PersistentResourceXMLBuilder(pathElement, namespaceURI);
}

public static class PersistentResourceXMLBuilder {
public static final class PersistentResourceXMLBuilder {
protected final PathElement pathElement;
private final String namespaceURI;
protected String xmlElementName;
protected String xmlWrapperElement;
protected boolean useValueAsElementName;
protected boolean noAddOperation;
protected AdditionalOperationsGenerator additionalOperationsGenerator;
protected final LinkedList<AttributeDefinition> attributeList = new LinkedList<>();
protected final List<PersistentResourceXMLBuilder> children = new ArrayList<>();
protected final LinkedHashMap<String, AttributeParser> attributeParsers = new LinkedHashMap<>();
protected final LinkedHashMap<String, AttributeMarshaller> attributeMarshallers = new LinkedHashMap<>();
protected boolean useElementsForGroups = true;
protected String forcedName;
private String xmlElementName;
private String xmlWrapperElement;
private boolean useValueAsElementName;
private boolean noAddOperation;
private AdditionalOperationsGenerator additionalOperationsGenerator;
private final LinkedList<AttributeDefinition> attributeList = new LinkedList<>();
private final List<PersistentResourceXMLBuilder> childrenBuilders = new ArrayList<>();
private final List<PersistentResourceXMLDescription> children = new ArrayList<>();
private final LinkedHashMap<String, AttributeParser> attributeParsers = new LinkedHashMap<>();
private final LinkedHashMap<String, AttributeMarshaller> attributeMarshallers = new LinkedHashMap<>();
private boolean useElementsForGroups = true;
private String forcedName;
private boolean marshallDefaultValues = false;
private String nameAttributeName = NAME;

/**
* @deprecated please use {@link PersistentResourceXMLBuilder(PathElement) } instead
* @param resourceDefinition for which xml build is constructed
*/
@Deprecated
protected PersistentResourceXMLBuilder(final PersistentResourceDefinition resourceDefinition) {
this(resourceDefinition.getPathElement());
}

/**
* @param resourceDefinition for which xml build is constructed
* @param namespaceURI namespace for which we create this resource, usually only useful for top level resources
* @deprecated please use {@link PersistentResourceXMLBuilder(PathElement, String) } instead
*/
@Deprecated
protected PersistentResourceXMLBuilder(final PersistentResourceDefinition resourceDefinition, String namespaceURI) {
this(resourceDefinition.getPathElement(), namespaceURI);
}

protected PersistentResourceXMLBuilder(final PathElement pathElement) {
private PersistentResourceXMLBuilder(final PathElement pathElement) {
this.pathElement = pathElement;
this.namespaceURI = null;
this.xmlElementName = pathElement.isWildcard() ? pathElement.getKey() : pathElement.getValue();
}

protected PersistentResourceXMLBuilder(final PathElement pathElement, String namespaceURI) {
private PersistentResourceXMLBuilder(final PathElement pathElement, String namespaceURI) {
this.pathElement = pathElement;
this.namespaceURI = namespaceURI;
this.xmlElementName = pathElement.isWildcard() ? pathElement.getKey() : pathElement.getValue();
}

public PersistentResourceXMLBuilder addChild(PersistentResourceXMLBuilder builder) {
this.childrenBuilders.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,7 +23,7 @@
package org.jboss.as.controller.parsing;

import java.util.List;

import java.util.function.Supplier;

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

/**
* Set the parser for the profile-wide subsystem configuration XML element. The element is always
* called {@code "subsystem"}. The reader should populate the given model node with the appropriate
* "subsystem add" update, without the address or operation name as that information will be automatically
* populated.
* It is recommended that supplier always creates new instance of the {@link XMLElementReader}
* instead of caching and returning always same instance.
*
* @param subsystemName the name of the subsystem. Cannot be {@code null}
* @param namespaceUri the URI of the sussystem's XML namespace, in string form. Cannot be {@code null}
* @param supplier of the element reader. Cannot be {@code null}
*
* @throws IllegalStateException if another {@link org.jboss.as.controller.Extension} has already registered a subsystem with the given
* {@code subsystemName}
*/
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

0 comments on commit c4f2d7a

Please sign in to comment.