Skip to content

Commit

Permalink
WFLY-5143 JGroups subsystem parser should not allow thread pool to be…
Browse files Browse the repository at this point in the history
… defined per protocol
  • Loading branch information
pferraro committed Aug 21, 2015
1 parent 2a2a904 commit e769c36
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 28 deletions.
Expand Up @@ -49,7 +49,6 @@ public class JGroupsSubsystemXMLReader implements XMLElementReader<List<ModelNod
this.schema = schema; this.schema = schema;
} }


@SuppressWarnings("deprecation")
@Override @Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> result) throws XMLStreamException { public void readElement(XMLExtendedStreamReader reader, List<ModelNode> result) throws XMLStreamException {


Expand Down Expand Up @@ -218,7 +217,6 @@ private void parseFork(XMLExtendedStreamReader reader, PathAddress channelAddres
} }
} }


@SuppressWarnings("deprecation")
private void parseStacks(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException { private void parseStacks(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {


ModelNode operation = operations.get(address); ModelNode operation = operations.get(address);
Expand Down Expand Up @@ -339,8 +337,42 @@ private void parseTransport(XMLExtendedStreamReader reader, PathAddress stackAdd
} }
} }


for (ThreadPoolResourceDefinition pool : ThreadPoolResourceDefinition.values()) {
PathAddress poolAddress = address.append(pool.getPathElement());
operations.put(poolAddress, Util.createAddOperation(poolAddress));
}

while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) { while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations); XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case DEFAULT_THREAD_POOL: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.DEFAULT, reader, address, operations);
break;
}
}
case INTERNAL_THREAD_POOL: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.INTERNAL, reader, address, operations);
break;
}
}
case OOB_THREAD_POOL: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.OOB, reader, address, operations);
break;
}
}
case TIMER_THREAD_POOL: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.TIMER, reader, address, operations);
break;
}
}
default: {
this.parseProtocolElement(reader, address, operations);
}
}
} }
} }


Expand Down Expand Up @@ -390,18 +422,6 @@ private void parseProtocolElement(XMLExtendedStreamReader reader, PathAddress ad
this.parseProperty(reader, address, operations); this.parseProperty(reader, address, operations);
break; break;
} }
case DEFAULT_THREAD_POOL:
parseThreadPool(ThreadPoolResourceDefinition.DEFAULT, reader, address, operations);
break;
case INTERNAL_THREAD_POOL:
parseThreadPool(ThreadPoolResourceDefinition.INTERNAL, reader, address, operations);
break;
case OOB_THREAD_POOL:
parseThreadPool(ThreadPoolResourceDefinition.OOB, reader, address, operations);
break;
case TIMER_THREAD_POOL:
parseThreadPool(ThreadPoolResourceDefinition.TIMER, reader, address, operations);
break;
default: { default: {
throw ParseUtils.unexpectedElement(reader); throw ParseUtils.unexpectedElement(reader);
} }
Expand All @@ -416,8 +436,7 @@ private void parseProperty(XMLExtendedStreamReader reader, PathAddress address,


private void parseThreadPool(ThreadPoolResourceDefinition pool, XMLExtendedStreamReader reader, PathAddress parentAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException { private void parseThreadPool(ThreadPoolResourceDefinition pool, XMLExtendedStreamReader reader, PathAddress parentAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = parentAddress.append(pool.getPathElement()); PathAddress address = parentAddress.append(pool.getPathElement());
ModelNode operation = Util.createAddOperation(address); ModelNode operation = operations.get(address);
operations.put(address, operation);


for (int i = 0; i < reader.getAttributeCount(); i++) { for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i)); XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
Expand Down
Expand Up @@ -22,11 +22,13 @@


package org.jboss.as.clustering.jgroups.subsystem; package org.jboss.as.clustering.jgroups.subsystem;


import java.util.Collection;
import java.util.EnumSet; import java.util.EnumSet;


import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;


import org.jboss.as.clustering.controller.Attribute; import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property; import org.jboss.dmr.Property;
Expand Down Expand Up @@ -132,11 +134,14 @@ private static void writeProtocolAttributes(XMLExtendedStreamWriter writer, Prop
} }


private static void writeThreadPoolElements(XMLElement element, ThreadPoolResourceDefinition pool, XMLExtendedStreamWriter writer, ModelNode transport) throws XMLStreamException { private static void writeThreadPoolElements(XMLElement element, ThreadPoolResourceDefinition pool, XMLExtendedStreamWriter writer, ModelNode transport) throws XMLStreamException {
if (transport.get(pool.getPathElement().getKey()).hasDefined(pool.getPathElement().getValue())) { PathElement path = pool.getPathElement();
ModelNode threadPool = transport.get(pool.getPathElement().getKeyValuePair()); if (transport.get(path.getKey()).hasDefined(path.getValue())) {
writer.writeStartElement(element.getLocalName()); ModelNode threadPool = transport.get(path.getKeyValuePair());
writeAttributes(writer, threadPool, pool.getAttributes()); if (hasDefined(threadPool, pool.getAttributes())) {
writer.writeEndElement(); writer.writeStartElement(element.getLocalName());
writeAttributes(writer, threadPool, pool.getAttributes());
writer.writeEndElement();
}
} }
} }


Expand All @@ -154,11 +159,15 @@ private static void writeRelay(XMLExtendedStreamWriter writer, ModelNode relay)
writer.writeEndElement(); writer.writeEndElement();
} }


private static boolean hasDefined(ModelNode model, Collection<? extends Attribute> attributes) {
return attributes.stream().anyMatch(attribute -> model.hasDefined(attribute.getDefinition().getName()));
}

private static <A extends Enum<A> & Attribute> void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Class<A> attributeClass) throws XMLStreamException { private static <A extends Enum<A> & Attribute> void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Class<A> attributeClass) throws XMLStreamException {
writeAttributes(writer, model, EnumSet.allOf(attributeClass)); writeAttributes(writer, model, EnumSet.allOf(attributeClass));
} }


private static void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Iterable<? extends Attribute> attributes) throws XMLStreamException { private static void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Collection<? extends Attribute> attributes) throws XMLStreamException {
for (Attribute attribute : attributes) { for (Attribute attribute : attributes) {
writeAttribute(writer, model, attribute); writeAttribute(writer, model, attribute);
} }
Expand Down
Expand Up @@ -23,6 +23,7 @@
package org.jboss.as.clustering.jgroups.subsystem; package org.jboss.as.clustering.jgroups.subsystem;


import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;


Expand Down Expand Up @@ -148,7 +149,7 @@ public void register(ManagementResourceRegistration registration) {
registration.registerSubModel(this); registration.registerSubModel(this);
} }


Iterable<Attribute> getAttributes() { Collection<Attribute> getAttributes() {
return Arrays.asList(this.minThreads, this.maxThreads, this.queueLength, this.keepAliveTime); return Arrays.asList(this.minThreads, this.maxThreads, this.queueLength, this.keepAliveTime);
} }


Expand Down
Expand Up @@ -70,10 +70,10 @@ public SubsystemParsingTestCase(JGroupsSchema schema, int expectedOperationCount
@Parameters @Parameters
public static Collection<Object[]> data() { public static Collection<Object[]> data() {
Object[][] data = new Object[][] { Object[][] data = new Object[][] {
{ JGroupsSchema.VERSION_1_1, 20 }, { JGroupsSchema.VERSION_1_1, 28 },
{ JGroupsSchema.VERSION_2_0, 22 }, { JGroupsSchema.VERSION_2_0, 30 },
{ JGroupsSchema.VERSION_3_0, 29 }, { JGroupsSchema.VERSION_3_0, 33 },
{ JGroupsSchema.VERSION_4_0, 29 }, { JGroupsSchema.VERSION_4_0, 33 },
}; };
return Arrays.asList(data); return Arrays.asList(data);
} }
Expand Down

0 comments on commit e769c36

Please sign in to comment.