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

com.github.phantomthief.failover.impl.GenericWeightFailoverBuilder Maven / Gradle / Ivy

There is a newer version: 0.1.32
Show newest version
package com.github.phantomthief.failover.impl;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Predicate;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;

import com.github.phantomthief.util.ThrowableFunction;
import com.github.phantomthief.util.ThrowablePredicate;

/**
 * @author w.vela
 */
public class GenericWeightFailoverBuilder {

    private final WeightFailoverBuilder builder;

    public GenericWeightFailoverBuilder(WeightFailoverBuilder builder) {
        this.builder = builder;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder name(String value) {
        builder.name(value);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder autoAddOnMissing(int weight) {
        builder.autoAddOnMissing(weight);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder failReduceRate(double rate) {
        builder.failReduceRate(rate);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder failReduce(int weight) {
        builder.failReduce(weight);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder onMinWeight(Consumer listener) {
        builder.onMinWeight(listener);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder onRecovered(Consumer listener) {
        builder.onRecovered(listener);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder successIncreaseRate(double rate) {
        builder.successIncreaseRate(rate);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder successIncrease(int weight) {
        builder.successIncrease(weight);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder minWeight(int weight) {
        builder.minWeight(weight);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder checkDuration(long time, TimeUnit unit) {
        builder.checkDuration(time, unit);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder
            checker(@Nonnull ThrowableFunction failChecker) {
        builder.checker(failChecker);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder checker(
            @Nonnull ThrowablePredicate failChecker,
            @Nonnegative double recoveredInitRate) {
        builder.checker(failChecker, recoveredInitRate);
        return this;
    }

    @CheckReturnValue
    @Nonnull
    public GenericWeightFailoverBuilder filter(Predicate filter) {
        builder.filter(filter);
        return this;
    }

    @Nonnull
    public WeightFailover build(Collection original) {
        return builder.build(original);
    }

    @Nonnull
    public WeightFailover build(Collection original, int initWeight) {
        return builder.build(original, initWeight);
    }

    @Nonnull
    public WeightFailover build(Map original) {
        return builder.build(original);
    }
}