<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="urn:jboss:domain:singleton:1.0"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="urn:jboss:domain:singleton:1.0"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified"
            version="1.0">

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

    <xs:complexType name="subsystem">
        <xs:sequence>
            <xs:element name="singleton-policies" type="tns:singleton-policies">
                <xs:annotation>
                    <xs:documentation>Enumerates the singleton policies supported by this subsystem.</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="singleton-policies">
        <xs:sequence>
            <xs:element name="singleton-policy" type="tns:singleton-policy" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>Defines a singleton policy</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="default" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>Identifies the default singleton deployment policy of the server.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="singleton-policy">
        <xs:choice>
            <xs:element name="random-election-policy" type="tns:random-election-policy">
                <xs:annotation>
                    <xs:documentation>Defines a election policy that chooses a random member on which a given application will be deployed.</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="simple-election-policy" type="tns:simple-election-policy">
                <xs:annotation>
                    <xs:documentation>Defines a election policy that chooses a specific member (indicated by position) on which a given application will be deployed.</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:choice>
        <xs:attribute name="name" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>The name of this singleton policy.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="cache-container" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>Identifies the cache-container used to back the singleton deployment policy.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="cache" type="xs:string">
            <xs:annotation>
                <xs:documentation>
                    Identifies the cache within the given cache container used to back the singleton deployment policy.
                    If undefined, the default-cache of the specified cache container will be used.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="quorum" type="xs:integer" default="1">
            <xs:annotation>
                <xs:documentation>Defines the minimum number of group members required before a singleton election will run.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="simple-election-policy">
        <xs:complexContent>
            <xs:extension base="tns:election-policy">
                <xs:attribute name="position" type="xs:integer" default="0">
                    <xs:annotation>
                        <xs:documentation>
                            Indicates the index of the node to be elected from a list of candidates sorted by descending age.
                            0 would indicate the oldest node, 1 the second oldest, etc.  Whereas -1 indicates the youngest node, -2 the second youngest, etc.
                            If the specified position exceeds the number of candidates, a modulus operation is applied.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="random-election-policy">
        <xs:complexContent>
            <xs:extension base="tns:election-policy"/>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="election-policy" abstract="true">
        <xs:choice minOccurs="0">
            <xs:element name="name-preferences" type="tns:list">
                <xs:annotation>
                    <xs:documentation>Defines an order list of nodes, identified by name, to which to prefer when electing a new singleton provider.</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="socket-binding-preferences" type="tns:list">
                <xs:annotation>
                    <xs:documentation>Defines an order list of nodes, identified by outbound socket binding, to which to prefer when electing a new singleton provider.</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:choice>
    </xs:complexType>

    <xs:simpleType name="list">
        <xs:list itemType="xs:token"/>
    </xs:simpleType>
</xs:schema>
