Search in sources :

Example 11 with SimpleAttributeDefinition

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();
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) Property(org.jboss.dmr.Property)

Example 12 with SimpleAttributeDefinition

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));
        }
    }
}
Also used : ResourceBuilder(org.jboss.as.controller.ResourceBuilder) DistributedWorkManager(org.jboss.jca.core.api.workmanager.DistributedWorkManager) PathElement(org.jboss.as.controller.PathElement) WorkManagerRuntimeAttributeWriteHandler(org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeWriteHandler) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) WorkManagerRuntimeAttributeReadHandler(org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeReadHandler) ClearWorkManagerStatisticsHandler(org.jboss.as.connector.dynamicresource.ClearWorkManagerStatisticsHandler)

Example 13 with SimpleAttributeDefinition

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));
        }
    }
}
Also used : ResourceBuilder(org.jboss.as.controller.ResourceBuilder) PathElement(org.jboss.as.controller.PathElement) WorkManagerRuntimeAttributeWriteHandler(org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeWriteHandler) WorkManager(org.jboss.jca.core.api.workmanager.WorkManager) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) WorkManagerRuntimeAttributeReadHandler(org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeReadHandler) ClearWorkManagerStatisticsHandler(org.jboss.as.connector.dynamicresource.ClearWorkManagerStatisticsHandler)

Example 14 with SimpleAttributeDefinition

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);
}
Also used : ThreadsParser(org.jboss.as.threads.ThreadsParser) AttributeParser(org.jboss.as.controller.AttributeParser) PathAddress(org.jboss.as.controller.PathAddress) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 15 with SimpleAttributeDefinition

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);
    }
}
Also used : ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.duplicateAttribute(org.jboss.as.controller.parsing.ParseUtils.duplicateAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition)

Aggregations

SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)45 ModelNode (org.jboss.dmr.ModelNode)15 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)9 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)9 SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)8 Property (org.jboss.dmr.Property)6 OperationContext (org.jboss.as.controller.OperationContext)4 AbstractAttributeDefinitionBuilder (org.jboss.as.controller.AbstractAttributeDefinitionBuilder)3 PathAddress (org.jboss.as.controller.PathAddress)3 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)3 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)3 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)3 SimpleMapAttributeDefinition (org.jboss.as.controller.SimpleMapAttributeDefinition)3 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)3 ClearWorkManagerStatisticsHandler (org.jboss.as.connector.dynamicresource.ClearWorkManagerStatisticsHandler)2 WorkManagerRuntimeAttributeReadHandler (org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeReadHandler)2 WorkManagerRuntimeAttributeWriteHandler (org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeWriteHandler)2 AbstractWriteAttributeHandler (org.jboss.as.controller.AbstractWriteAttributeHandler)2 ListAttributeDefinition (org.jboss.as.controller.ListAttributeDefinition)2