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

org.kiwiproject.consul.option.TransactionOptions Maven / Gradle / Ivy

package org.kiwiproject.consul.option;

import org.immutables.value.Value;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * Container for common transaction options used by the Consul API.
 */
@Value.Immutable
@Value.Style(jakarta = true)
public abstract class TransactionOptions implements ParamAdder {

    public static final TransactionOptions BLANK = ImmutableTransactionOptions.builder().build();

    public abstract Optional getDatacenter();

    @Value.Default
    public ConsistencyMode getConsistencyMode() {
        return ConsistencyMode.DEFAULT;
    }

    @Override
    public Map toQuery() {
        Map result = new HashMap<>();

        Optional consistencyMode = getConsistencyMode().toParam();
        consistencyMode.ifPresent(s -> result.put(s, "true"));

        Options.optionallyAdd(result, "dc", getDatacenter());

        return result;
    }

    @Override
    public Map toHeaders() {
        var consistencyMode = getConsistencyMode();
        return new HashMap<>(consistencyMode.getAdditionalHeaders());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy