<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ Copyright 2016 Red Hat, Inc.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="urn:jboss:domain:batch-jberet:2.0"
           targetNamespace="urn:jboss:domain:batch-jberet:2.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"/>

    <!-- The batch subsystem root element -->
    <xs:element name="subsystem" type="batch-subsystemType"/>

    <xs:complexType name="batch-subsystemType">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The configuration of the batch subsystem.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="default-job-repository" type="namedType" minOccurs="1" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        Defines the default job-repository for the batch environment.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="default-thread-pool" type="namedType" minOccurs="1" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        Defines the default thread-pool for the batch environment.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="restart-jobs-on-resume" type="booleanType" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        If set to true when a resume operation has be invoked after a suspend operation any jobs stopped
                        during the suspend will be restarted. A value of false will leave the jobs in a stopped state.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="security-domain" type="namedType" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation>
                        Defines the name of the default security domain to use as a default for batch jobs.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="job-repository" type="job-repositoryType" minOccurs="1" maxOccurs="unbounded"/>
            <xs:element name="thread-pool" type="thread-poolType" minOccurs="1" maxOccurs="unbounded"/>
            <xs:element name="thread-factory" type="threads:thread-factory" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="namedType">
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="booleanType">
        <xs:attribute name="value" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="job-repositoryType">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                The name of the job repository to use
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="in-memory" type="in-memoryType"/>
            <xs:element name="jdbc" type="jdbcType"/>
        </xs:choice>
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="in-memoryType">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                        Used to describe an in-memory job repository.
                ]]>
            </xs:documentation>
        </xs:annotation>
    </xs:complexType>

    <xs:complexType name="jdbcType">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                        Used to describe how the job repository should connect to a database.
                ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="data-source" type="xs:token" use="required"/>
    </xs:complexType>

    <xs:complexType name="thread-poolType">
        <xs:annotation>
            <xs:documentation>
                <![CDATA[
                A thread pool executor with an unbounded queue.  Such a thread pool has a core size and a queue with no
                upper bound.  When a task is submitted, if the number of running threads is less than the core size,
                a new thread is created.  Otherwise, the task is placed in queue.  If too many tasks are allowed to be
                submitted to this type of executor, an out of memory condition may occur.

                The "max-threads" attribute must be used to specify the thread pool size.  The nested
                "keepalive-time" element may used to specify the amount of time that pool threads should
                be kept running when idle; if not specified, threads will run until the executor is shut down.
                The "thread-factory" element specifies the bean name of a specific thread factory to use to create worker
                threads.
            ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <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="name" use="required" type="xs:string"/>
    </xs:complexType>
</xs:schema>