All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.resourcemanager.cosmos.models.FailoverPolicy Maven / Gradle / Ivy

Go to download

This package contains Microsoft Azure CosmosDB SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt

There is a newer version: 2.46.0
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.cosmos.models;

import com.azure.core.annotation.Fluent;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
 * The failover policy for a given region of a database account.
 */
@Fluent
public final class FailoverPolicy implements JsonSerializable {
    /*
     * The unique identifier of the region in which the database account replicates to. Example:
     * <accountName>-<locationName>.
     */
    private String id;

    /*
     * The name of the region in which the database account exists.
     */
    private String locationName;

    /*
     * The failover priority of the region. A failover priority of 0 indicates a write region. The maximum value for a
     * failover priority = (total number of regions - 1). Failover priority values must be unique for each of the
     * regions in which the database account exists.
     */
    private Integer failoverPriority;

    /**
     * Creates an instance of FailoverPolicy class.
     */
    public FailoverPolicy() {
    }

    /**
     * Get the id property: The unique identifier of the region in which the database account replicates to. Example:
     * &lt;accountName&gt;-&lt;locationName&gt;.
     * 
     * @return the id value.
     */
    public String id() {
        return this.id;
    }

    /**
     * Get the locationName property: The name of the region in which the database account exists.
     * 
     * @return the locationName value.
     */
    public String locationName() {
        return this.locationName;
    }

    /**
     * Set the locationName property: The name of the region in which the database account exists.
     * 
     * @param locationName the locationName value to set.
     * @return the FailoverPolicy object itself.
     */
    public FailoverPolicy withLocationName(String locationName) {
        this.locationName = locationName;
        return this;
    }

    /**
     * Get the failoverPriority property: The failover priority of the region. A failover priority of 0 indicates a
     * write region. The maximum value for a failover priority = (total number of regions - 1). Failover priority values
     * must be unique for each of the regions in which the database account exists.
     * 
     * @return the failoverPriority value.
     */
    public Integer failoverPriority() {
        return this.failoverPriority;
    }

    /**
     * Set the failoverPriority property: The failover priority of the region. A failover priority of 0 indicates a
     * write region. The maximum value for a failover priority = (total number of regions - 1). Failover priority values
     * must be unique for each of the regions in which the database account exists.
     * 
     * @param failoverPriority the failoverPriority value to set.
     * @return the FailoverPolicy object itself.
     */
    public FailoverPolicy withFailoverPriority(Integer failoverPriority) {
        this.failoverPriority = failoverPriority;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("locationName", this.locationName);
        jsonWriter.writeNumberField("failoverPriority", this.failoverPriority);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of FailoverPolicy from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of FailoverPolicy if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IOException If an error occurs while reading the FailoverPolicy.
     */
    public static FailoverPolicy fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            FailoverPolicy deserializedFailoverPolicy = new FailoverPolicy();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("id".equals(fieldName)) {
                    deserializedFailoverPolicy.id = reader.getString();
                } else if ("locationName".equals(fieldName)) {
                    deserializedFailoverPolicy.locationName = reader.getString();
                } else if ("failoverPriority".equals(fieldName)) {
                    deserializedFailoverPolicy.failoverPriority = reader.getNullable(JsonReader::getInt);
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedFailoverPolicy;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy