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

<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2013, Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file in the
  ~ distribution for a full listing of individual contributors.
  ~
  ~ This is free software; you can redistribute it and/or modify it
  ~ under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2.1 of
  ~ the License, or (at your option) any later version.
  ~
  ~ This software is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  ~ Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with this software; if not, write to the Free
  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="urn:jboss:domain:batch:1.0"
           targetNamespace="urn:jboss:domain:batch:1.0"
           xmlns:threads="urn:jboss:domain:threads:1.1"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="1.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="job-repository" type="job-repositoryType" minOccurs="1" maxOccurs="1"/>
            <xs:element name="thread-pool" type="thread-poolType" minOccurs="1" maxOccurs="1"/>
            <xs:element name="thread-factory" type="threads:thread-factory" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </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: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. If the jndi-name attribute
                        is not defined, the default JNDI name will be used.
                ]]>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="jndi-name" type="xs:token" use="optional"/>
    </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:complexType>
</xs:schema>
