use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.
the class EESubsystemXmlPersister method writeContextServices.
private void writeContextServices(final XMLExtendedStreamWriter writer, final ModelNode subModel) throws XMLStreamException {
writer.writeStartElement(Element.CONTEXT_SERVICES.getLocalName());
for (Property property : subModel.asPropertyList()) {
writer.writeStartElement(Element.CONTEXT_SERVICE.getLocalName());
writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
for (SimpleAttributeDefinition ad : ContextServiceResourceDefinition.ATTRIBUTES) {
ad.marshallAsAttribute(property.getValue(), writer);
}
writer.writeEndElement();
}
writer.writeEndElement();
}
use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.
the class DistributedWorkManagerStatisticsService method start.
@Override
public void start(StartContext context) throws StartException {
synchronized (this) {
DistributedWorkManager dwm = distributedWorkManager.getValue();
dwm.setDistributedStatisticsEnabled(statsEnabled);
if (dwm.getDistributedStatistics() != null) {
PathElement peDistributedWm = PathElement.pathElement(Constants.STATISTICS_NAME, "distributed");
ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create(peDistributedWm, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader()));
ManagementResourceRegistration dwmSubRegistration = overrideRegistration.registerSubModel(resourceBuilder.build());
OperationStepHandler metricHandler = new WorkManagerRuntimeAttributeReadHandler(dwm, dwm.getDistributedStatistics(), false);
for (SimpleAttributeDefinition metric : Constants.WORKMANAGER_METRICS) {
dwmSubRegistration.registerMetric(metric, metricHandler);
}
OperationStepHandler readHandler = new WorkManagerRuntimeAttributeReadHandler(dwm, dwm.getDistributedStatistics(), false);
OperationStepHandler writeHandler = new WorkManagerRuntimeAttributeWriteHandler(dwm, false, Constants.DISTRIBUTED_WORKMANAGER_RW_ATTRIBUTES);
for (SimpleAttributeDefinition attribute : Constants.DISTRIBUTED_WORKMANAGER_RW_ATTRIBUTES) {
dwmSubRegistration.registerReadWriteAttribute(attribute, readHandler, writeHandler);
}
dwmSubRegistration.registerOperationHandler(ClearWorkManagerStatisticsHandler.DEFINITION, new ClearWorkManagerStatisticsHandler(dwm));
}
}
}
use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.
the class WorkManagerStatisticsService method start.
@Override
public void start(StartContext context) throws StartException {
synchronized (this) {
WorkManager wm = workManager.getValue();
wm.setStatisticsEnabled(statsEnabled);
if (wm.getStatistics() != null) {
PathElement peLocaldWm = PathElement.pathElement(Constants.STATISTICS_NAME, "local");
ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create(peLocaldWm, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader()));
ManagementResourceRegistration wmSubRegistration = overrideRegistration.registerSubModel(resourceBuilder.build());
OperationStepHandler metricHandler = new WorkManagerRuntimeAttributeReadHandler(wm, wm.getStatistics(), false);
for (SimpleAttributeDefinition metric : Constants.WORKMANAGER_METRICS) {
wmSubRegistration.registerMetric(metric, metricHandler);
}
OperationStepHandler readHandler = new WorkManagerRuntimeAttributeReadHandler(wm, wm.getStatistics(), false);
OperationStepHandler writeHandler = new WorkManagerRuntimeAttributeWriteHandler(wm, false, Constants.WORKMANAGER_RW_ATTRIBUTES);
for (SimpleAttributeDefinition attribute : Constants.WORKMANAGER_RW_ATTRIBUTES) {
wmSubRegistration.registerReadWriteAttribute(attribute, readHandler, writeHandler);
}
wmSubRegistration.registerOperationHandler(ClearWorkManagerStatisticsHandler.DEFINITION, new ClearWorkManagerStatisticsHandler(wm));
}
}
}
use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.
the class BatchSubsystemParser_1_0 method readElement.
@Override
public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> ops) throws XMLStreamException {
final ThreadsParser threadsParser = ThreadsParser.getInstance();
final PathAddress subsystemAddress = PathAddress.pathAddress(BatchSubsystemDefinition.SUBSYSTEM_PATH);
// Add the subsystem
final ModelNode subsystemAddOp = Util.createAddOperation(subsystemAddress);
ops.add(subsystemAddOp);
// Find the required elements
final Set<Element> requiredElements = EnumSet.of(Element.JOB_REPOSITORY, Element.THREAD_POOL);
attributeElements.forEach((element, attribute) -> {
if (!attribute.isAllowNull() && attribute.getDefaultValue() == null) {
requiredElements.add(element);
}
});
final Namespace namespace = Namespace.forUri(reader.getNamespaceURI());
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final String localName = reader.getLocalName();
final Element element = Element.forName(localName);
final SimpleAttributeDefinition attribute = attributeElements.get(element);
if (attribute != null) {
final AttributeParser parser = attribute.getParser();
if (parser.isParseAsElement()) {
parser.parseElement(attribute, reader, subsystemAddOp);
} else {
// Assume this is an element with a single name attribute
parser.parseAndSetParameter(attribute, AttributeParsers.readNameAttribute(reader), subsystemAddOp, reader);
ParseUtils.requireNoContent(reader);
}
requiredElements.remove(element);
} else if (element == Element.JOB_REPOSITORY) {
final String name = AttributeParsers.readNameAttribute(reader);
parseJobRepository(reader, subsystemAddress, name, ops);
requiredElements.remove(Element.JOB_REPOSITORY);
} else if (element == Element.THREAD_POOL) {
threadsParser.parseUnboundedQueueThreadPool(reader, namespace.getUriString(), THREADS_1_1, subsystemAddress.toModelNode(), ops, BatchThreadPoolResourceDefinition.NAME, null);
requiredElements.remove(Element.THREAD_POOL);
} else if (element == Element.THREAD_FACTORY) {
threadsParser.parseThreadFactory(reader, namespace.getUriString(), THREADS_1_1, subsystemAddress.toModelNode(), ops, BatchSubsystemDefinition.THREAD_FACTORY, null);
} else {
throw ParseUtils.unexpectedElement(reader);
}
}
if (!requiredElements.isEmpty()) {
throw ParseUtils.missingRequired(reader, requiredElements);
}
ParseUtils.requireNoContent(reader);
}
use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.
the class JacORBSubsystemParser method parseAttributes.
/**
* <p>
* Parses all attributes from the current element and sets them in the specified {@code ModelNode}.
* </p>
*
* @param reader the {@code XMLExtendedStreamReader} used to read the configuration XML.
* @param node the {@code ModelNode} that will hold the parsed attributes.
* @param expectedAttributes an {@code EnumSet} containing all expected attributes. If the parsed attribute is not
* one of the expected attributes, an exception is thrown.
* @param requiredAttributes an {@code EnumSet} containing all required attributes. If a required attribute is not
* found, an exception is thrown.
* @throws XMLStreamException if an error occurs while parsing the XML, if an attribute is not one of the expected
* attributes or if one of the required attributes is not parsed.
*/
private void parseAttributes(XMLExtendedStreamReader reader, ModelNode node, EnumSet<Attribute> expectedAttributes, EnumSet<Attribute> requiredAttributes) throws XMLStreamException {
EnumSet<Attribute> parsedAttributes = EnumSet.noneOf(Attribute.class);
if (requiredAttributes == null) {
requiredAttributes = EnumSet.noneOf(Attribute.class);
}
for (int i = 0; i < reader.getAttributeCount(); i++) {
requireNoNamespaceAttribute(reader, i);
final String attrValue = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
// check for unexpected attributes.
if (!expectedAttributes.contains(attribute))
throw unexpectedAttribute(reader, i);
// check for duplicate attributes.
if (!parsedAttributes.add(attribute)) {
throw duplicateAttribute(reader, attribute.getLocalName());
}
requiredAttributes.remove(attribute);
((SimpleAttributeDefinition) JacORBSubsystemDefinitions.valueOf(attribute.getLocalName())).parseAndSetParameter(attrValue, node, reader);
}
// throw an exception if a required attribute wasn't found.
if (!requiredAttributes.isEmpty()) {
throw missingRequired(reader, requiredAttributes);
}
}
Aggregations