Search in sources :

Example 1 with ThreadsParser

use of org.jboss.as.threads.ThreadsParser 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 2 with ThreadsParser

use of org.jboss.as.threads.ThreadsParser in project wildfly by wildfly.

the class BatchSubsystemWriter method writeContent.

@Override
public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
    final ThreadsParser threadsParser = ThreadsParser.getInstance();
    context.startSubsystemElement(Namespace.CURRENT.getUriString(), false);
    final ModelNode model = context.getModelNode();
    BatchSubsystemDefinition.DEFAULT_JOB_REPOSITORY.marshallAsElement(model, writer);
    BatchSubsystemDefinition.DEFAULT_THREAD_POOL.marshallAsElement(model, writer);
    BatchSubsystemDefinition.RESTART_JOBS_ON_RESUME.marshallAsElement(model, writer);
    BatchSubsystemDefinition.SECURITY_DOMAIN.marshallAsElement(model, writer);
    // Write the in-memory job repositories
    if (model.hasDefined(InMemoryJobRepositoryDefinition.NAME)) {
        final List<Property> repositories = model.get(InMemoryJobRepositoryDefinition.NAME).asPropertyList();
        for (Property property : repositories) {
            writer.writeStartElement(Element.JOB_REPOSITORY.getLocalName());
            writeNameAttribute(writer, property.getName());
            writer.writeEmptyElement(Element.IN_MEMORY.getLocalName());
            // end job-repository
            writer.writeEndElement();
        }
    }
    // Write the JDBC job repositories
    if (model.hasDefined(JdbcJobRepositoryDefinition.NAME)) {
        final List<Property> repositories = model.get(JdbcJobRepositoryDefinition.NAME).asPropertyList();
        for (Property property : repositories) {
            writer.writeStartElement(Element.JOB_REPOSITORY.getLocalName());
            writeNameAttribute(writer, property.getName());
            writer.writeStartElement(Element.JDBC.getLocalName());
            JdbcJobRepositoryDefinition.DATA_SOURCE.marshallAsAttribute(property.getValue(), writer);
            writer.writeEndElement();
            // end job-repository
            writer.writeEndElement();
        }
    }
    // Write the thread pool
    if (model.hasDefined(BatchThreadPoolResourceDefinition.NAME)) {
        final List<Property> threadPools = model.get(BatchThreadPoolResourceDefinition.NAME).asPropertyList();
        for (Property threadPool : threadPools) {
            threadsParser.writeUnboundedQueueThreadPool(writer, threadPool, Element.THREAD_POOL.getLocalName(), true);
        }
    }
    // Write out the thread factory
    if (model.hasDefined(BatchSubsystemDefinition.THREAD_FACTORY)) {
        final List<Property> threadFactories = model.get(BatchSubsystemDefinition.THREAD_FACTORY).asPropertyList();
        for (Property threadFactory : threadFactories) {
            threadsParser.writeThreadFactory(writer, threadFactory);
        }
    }
    writer.writeEndElement();
}
Also used : ThreadsParser(org.jboss.as.threads.ThreadsParser) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Aggregations

ThreadsParser (org.jboss.as.threads.ThreadsParser)2 ModelNode (org.jboss.dmr.ModelNode)2 AttributeParser (org.jboss.as.controller.AttributeParser)1 PathAddress (org.jboss.as.controller.PathAddress)1 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)1 Property (org.jboss.dmr.Property)1