<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright The WildFly Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="urn:jboss:domain:jca:6.0"
           xmlns="urn:jboss:domain:jca:6.0"
           xmlns:threads="urn:jboss:domain:threads:1.1"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="2.0">

    <xs:import namespace="urn:jboss:domain:threads:1.1" schemaLocation="jboss-as-threads_1_1.xsd"/>

    <xs:element name="subsystem" type="subsystemType"/>

    <xs:complexType name="subsystemType">
        <xs:sequence>
            <xs:element name="archive-validation"
                type="archive-validationType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Toggle archive validation for the deployment
                        units. If it's not present it's considered true
                        with default attributes.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="bean-validation"
                type="bean-validationType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Toggle bean validation (JSR-303) for the
                        deployment units. If it's not present it's
                        considered true
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="tracer"
                        type="tracer-Type" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Toggle Tracer for the
                        deployment units. If it's not present it's
                        considered false
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="default-workmanager" type="defaultWorkmanagerType" minOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        The default work manager and its thread pools
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="workmanager" type="workmanagerType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        A custom work manager definition and its thread pools
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element name="distributed-workmanager" type="distributedWorkmanagerType" minOccurs="0"
                        maxOccurs="unbounded">
              <xs:annotation>
                <xs:documentation>
                  A distributed work manager definition and its thread pools
                </xs:documentation>
              </xs:annotation>
            </xs:element>

            <xs:element name="bootstrap-contexts" type="bootstrap-contextsType" minOccurs="0">
              <xs:annotation>
                <xs:documentation>
                  Definition of custom bootstrap contexts
                </xs:documentation>
              </xs:annotation>
            </xs:element>

            <xs:element name="cached-connection-manager" type="cached-connection-managerType" minOccurs="0" maxOccurs="1"></xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="archive-validationType">
        <xs:attribute name="enabled" type="xs:boolean" default="true" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Specify whether archive validation is enabled.  Default: true
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="fail-on-error" type="xs:boolean" default="true" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Should an archive validation error report fail the deployment. Default: true
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="fail-on-warn" type="xs:boolean" default="false" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Should an archive validation warning report fail the deployment. Default: false
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="bean-validationType">
        <xs:attribute name="enabled" type="xs:boolean" use="required">
            <xs:annotation>
                <xs:documentation>
                    Specify whether bean validation is enabled.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="tracer-Type">
        <xs:attribute name="enabled" type="xs:boolean" use="required">
            <xs:annotation>
                <xs:documentation>
                    Specify whether tracer is enabled.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="defaultWorkmanagerType">
        <xs:all>
            <xs:element name="short-running-threads" type="thread-pool" maxOccurs="1" minOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        Thread pool for short running jobs.
                        Long running jobs are identified by the HintsContext.LONGRUNNING_HINT with a value of true.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="long-running-threads" type="thread-pool" maxOccurs="1" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Thread pool for long running jobs.
                        Long running jobs are identified by the HintsContext.LONGRUNNING_HINT with a value of true.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="elytron-enabled" type="xs:boolean" maxOccurs="1" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        <![CDATA[[
                Indicates that Elytron is responsible for security for this workmanager. Default is true
                ]]>
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="workmanagerType">
        <xs:all>
            <xs:element name="short-running-threads" type="thread-pool" maxOccurs="1" minOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        Thread pool for short running jobs.
                        Long running jobs are identified by the HintsContext.LONGRUNNING_HINT with a value of true.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="long-running-threads" type="thread-pool" maxOccurs="1" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Thread pool for long running jobs.
                        Long running jobs are identified by the HintsContext.LONGRUNNING_HINT with a value of true.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="elytron-enabled" type="xs:boolean" maxOccurs="1" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        <![CDATA[[
                Indicates that Elytron is responsible for security for this workmanager. Default is true
                ]]>
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:all>
        <xs:attribute name="name" type="xs:token" use="required">
            <xs:annotation>
                <xs:documentation>
                   Specifies the name of the work manager.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

  <xs:complexType name="distributedWorkmanagerType">
          <xs:all>
              <xs:element name="short-running-threads" type="thread-pool" maxOccurs="1" minOccurs="1">
                  <xs:annotation>
                      <xs:documentation>
                          Thread pool for short running jobs.
                          Long running jobs are identified by the HintsContext.LONGRUNNING_HINT with a value of true.
                      </xs:documentation>
                  </xs:annotation>
              </xs:element>
              <xs:element name="long-running-threads" type="thread-pool" maxOccurs="1" minOccurs="0">
                  <xs:annotation>
                      <xs:documentation>
                          Thread pool for long running jobs.
                          Long running jobs are identified by the HintsContext.LONGRUNNING_HINT with a value of true.
                      </xs:documentation>
                  </xs:annotation>
              </xs:element>
              <xs:element name="policy" type="policyType" maxOccurs="1" minOccurs="0" />
              <xs:element name="selector" type="selectorType" maxOccurs="1" minOccurs="0" />
              <xs:element name="elytron-enabled" type="xs:boolean" maxOccurs="1" minOccurs="0">
                  <xs:annotation>
                      <xs:documentation>
                          <![CDATA[[
                Indicates that Elytron is responsible for security for this workmanager. Default is false
                ]]>
                      </xs:documentation>
                  </xs:annotation>
              </xs:element>
          </xs:all>
          <xs:attribute name="name" type="xs:token" use="required">
              <xs:annotation>
                  <xs:documentation>
                     Specifies the name of the work manager. Note, that custom work managers need
                     to have a name defined.
                  </xs:documentation>
              </xs:annotation>
          </xs:attribute>
      </xs:complexType>

    <xs:complexType name="bootstrap-contextsType">
        <xs:sequence>
            <xs:element name="bootstrap-context" type="bootstrap-contextType" maxOccurs="unbounded" minOccurs="1"></xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="bootstrap-contextType">
        <xs:annotation>
            <xs:documentation>
                This provides a mechanism to pass a bootstrap context to a resource adapter instance when it is bootstrapped.
                The bootstrap context contains references to useful facilities that could be used by the resource adapter instance.
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="name" type="xs:token" use="required">
            <xs:annotation>
                <xs:documentation>
                   Specifies the name of the bootstrap context.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="workmanager" type="xs:token" use="required">
            <xs:annotation>
                <xs:documentation>
                   Specifies the name of the work manager to use for this context.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="cached-connection-managerType">
        <xs:attribute name="debug" type="xs:boolean" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Enable/disable debug information logging
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="error" type="xs:boolean" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Enable/disable error information logging
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="ignore-unknown-connections" type="xs:boolean" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Do not cache unknown connections
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

     <xs:complexType name="thread-pool">
        <xs:annotation>
            <xs:documentation>
            <![CDATA[
                See threads:blocking-bounded-queue-thread-pool.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="core-threads" type="threads:countType" minOccurs="0"/>
            <xs:element name="queue-length" type="threads:countType"/>
            <xs:element name="max-threads" type="threads:countType"/>
            <xs:element name="keepalive-time" type="threads:time" minOccurs="0"/>
            <xs:element name="thread-factory" type="threads:ref" minOccurs="0"/>
        </xs:all>
        <xs:attribute name="allow-core-timeout" use="optional" type="xs:boolean"/>
    </xs:complexType>

    <xs:complexType name="policyType">
        <xs:sequence>
          <xs:element name="option" type="optionType" maxOccurs="unbounded" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="name" use="required">
                <xs:annotation>
                    <xs:documentation>
                        When to distribute the work instance
                        Supported policies
                        - NEVER
                        Never distribute the Work instance to another node.
                        - ALWAYS
                        Always distribute the Work instance to another node.
                        - WATERMARK
                        Distribute the Work instance to another node based on how many free worker threads the current
                        node has available.

                        Default is WATERMARK with a watermark of 0
                    </xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:token">
                        <xs:enumeration value="NEVER"/>
                        <xs:enumeration value="ALWAYS"/>
                        <xs:enumeration value="WATERMARK"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>


      </xs:complexType>
      <xs:complexType name="selectorType">
          <xs:sequence>
                  <xs:element name="option" type="optionType" maxOccurs="unbounded" minOccurs="0"/>
          </xs:sequence>
          <xs:attribute name="name" use="required">
                <xs:annotation>
                    <xs:documentation>
                        To which work manager instance should the Work instance be distributed to
                        Supported selectors
                        - FIRST_AVAILABLE
                            Select the first available node in the list
                        - PING_TIME
                            Select the node with the lowest ping time
                        - MAX_FREE_THREADS
                            Select the node with highest number of free worker threads

                        Default is PING_TIME
                    </xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:token">
                        <xs:enumeration value="FIRST_AVAILABLE"/>
                        <xs:enumeration value="PING_TIME"/>
                        <xs:enumeration value="MAX_FREE_THREADS"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>

        <xs:complexType name="optionType">
              <xs:attribute name="name" use="required">
                  <xs:annotation>
                      <xs:documentation>
                          Name of the option to be set
                      </xs:documentation>
                  </xs:annotation>
              </xs:attribute>
          </xs:complexType>
</xs:schema>