com.ibasco.agql.core.util.ConnectOptions Maven / Gradle / Ivy
/*
* Copyright (c) 2022 Asynchronous Game Query Library
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibasco.agql.core.util;
import com.ibasco.agql.core.enums.RateLimitType;
import dev.failsafe.Failsafe;
/**
* Failsafe {@link Option}s to be used by the underlying connection factory
*
* @author Rafael Luis Ibasco
*/
@Shared
public class ConnectOptions extends AbstractOptions {
/**
* Enable {@link Failsafe} integration for Source Query module
*
* @see Failsafe
*/
public static final Option FAILSAFE_ENABLED = Option.create(FailsafeProperties.FAILSAFE_ENABLED, true);
//
/**
* Enable Rate Limiter (Failsafe)
*
* @see #FAILSAFE_RATELIMIT_MAX_EXEC
* @see #FAILSAFE_RATELIMIT_PERIOD
* @see #FAILSAFE_RATELIMIT_MAX_WAIT_TIME
* @see Failsafe's Rate Limiter
*/
public static final Option FAILSAFE_RATELIMIT_ENABLED = Option.create(FailsafeProperties.FAILSAFE_RATELIMIT_ENABLED, true);
//
//
/**
* Maximum number of executions within the specified period (Default is 650 executions per minute)
*
* @see #FAILSAFE_RATELIMIT_PERIOD
* @see Failsafe's Rate Limiter
*/
public static final Option FAILSAFE_RATELIMIT_MAX_EXEC = Option.create(FailsafeProperties.FAILSAFE_RATELIMIT_MAX_EXEC, 650L);
/**
* The period after which permitted executions are reset to the max executions. (Default is 60000 ms or 1 minute)
*
* @see #FAILSAFE_RATELIMIT_MAX_EXEC
* @see Failsafe's Rate Limiter
*/
public static final Option FAILSAFE_RATELIMIT_PERIOD = Option.create(FailsafeProperties.FAILSAFE_RATELIMIT_PERIOD, 5000L);
/**
* Maximum waiting time for permits to be available (Default is 10000 ms)
*
* @see Failsafe's Rate Limiter (Waiting)
*/
public static final Option FAILSAFE_RATELIMIT_MAX_WAIT_TIME = Option.create(FailsafeProperties.FAILSAFE_RATELIMIT_MAX_WAIT_TIME, 10000L);
/**
* Specifies the rate limiting method to use (Default is Smooth)
*
* @see RateLimitType
* @see Failsafe's Rate Limiter
* @see Failsafe's Rate Limiter
*/
public static final Option FAILSAFE_RATELIMIT_TYPE = Option.create(FailsafeProperties.FAILSAFE_RATELIMIT_TYPE, RateLimitType.SMOOTH);
/**
* Enable retry policy
*
* @see #FAILSAFE_RETRY_BACKOFF_ENABLED
* @see #FAILSAFE_RETRY_BACKOFF_DELAY
* @see #FAILSAFE_RETRY_BACKOFF_MAX_DELAY
* @see #FAILSAFE_RETRY_BACKOFF_DELAY_FACTOR
* @see #FAILSAFE_RETRY_MAX_ATTEMPTS
* @see Failsafe's Retry Policy
*/
public static final Option FAILSAFE_RETRY_ENABLED = Option.create(FailsafeProperties.FAILSAFE_RETRY_ENABLED, true);
//
//
/**
* Delay between retries (In milliseconds. Use -1 to disable. Default is 1000ms)
*
* @see Failsafe's Retry Policy
*/
public static final Option FAILSAFE_RETRY_DELAY = Option.create(FailsafeProperties.FAILSAFE_RETRY_DELAY, 1000L);
/**
* Enable Failsafe's Retry Backoff Feature
*
* @see #FAILSAFE_RETRY_BACKOFF_DELAY
* @see #FAILSAFE_RETRY_BACKOFF_MAX_DELAY
* @see #FAILSAFE_RETRY_BACKOFF_DELAY_FACTOR
* @see Failsafe's Retry Policy (Backoff)
*/
public static final Option FAILSAFE_RETRY_BACKOFF_ENABLED = Option.create(FailsafeProperties.FAILSAFE_RETRY_BACKOFF_ENABLED, true);
/**
* Sets the delay between retries (milliseconds), exponentially backing off to the maxDelay and multiplying successive delays by the delayFactor. Replaces any previously configured fixed or random delays.
*
* @see #FAILSAFE_RETRY_BACKOFF_MAX_DELAY
* @see #FAILSAFE_RETRY_BACKOFF_DELAY_FACTOR
* @see Failsafe's Retry Policy (Backoff)
*/
public static final Option FAILSAFE_RETRY_BACKOFF_DELAY = Option.create(FailsafeProperties.FAILSAFE_RETRY_BACKOFF_DELAY, 50L);
/**
* Sets the delay between retries (milliseconds), exponentially backing off to the maxDelay and multiplying successive delays by the delayFactor. Replaces any previously configured fixed or random delays. (Default is 5000 ms or 5 seconds)
*
* @see #FAILSAFE_RETRY_BACKOFF_ENABLED
* @see #FAILSAFE_RETRY_BACKOFF_DELAY
* @see #FAILSAFE_RETRY_BACKOFF_DELAY_FACTOR
* @see Failsafe's Retry Policy (Backoff)
*/
public static final Option FAILSAFE_RETRY_BACKOFF_MAX_DELAY = Option.create(FailsafeProperties.FAILSAFE_RETRY_BACKOFF_MAX_DELAY, 5000L);
/**
* Sets the delay between retries, exponentially backing off to the maxDelay and multiplying successive delays by the delayFactor. Replaces any previously configured fixed or random delays. (Default is 5.0)
*
* @see #FAILSAFE_RETRY_BACKOFF_ENABLED
* @see Failsafe's Retry Policy (Backoff)
*/
public static final Option FAILSAFE_RETRY_BACKOFF_DELAY_FACTOR = Option.create(FailsafeProperties.FAILSAFE_RETRY_BACKOFF_DELAY_FACTOR, 1.5d);
/**
* Sets the max number of execution attempts to perform. -1 indicates no limit (Default is 3 attempts)
*
* @see Failsafe's Retry Policy
*/
public static final Option FAILSAFE_RETRY_MAX_ATTEMPTS = Option.create(FailsafeProperties.FAILSAFE_RETRY_MAX_ATTEMPTS, 3);
/**
* Enable/disable Circuit breaker failsafe policy (Default: true)
*/
public static final Option FAILSAFE_CIRCBREAKER_ENABLED = Option.create(FailsafeProperties.FAILSAFE_CIRCBREAKER_ENABLED, true);
//
//
/**
* After opening, a breaker will delay for 1 second(s) by default before before transitioning to half-open.
* You can change to different delay by setting this configuration option. (Unit: milliseconds, Default: 1000 ms)
*
* @see Circuit Breaker - Half-opening
*/
public static final Option FAILSAFE_CIRCBREAKER_DELAY = Option.create(FailsafeProperties.FAILSAFE_CIRCBREAKER_DELAY, 1000);
/**
* The number of failures that must occur in order to open the circuit (Default: 3)
*
* @see Circuit Breaker - Opening
*/
public static final Option FAILSAFE_CIRCBREAKER_FAILURE_THRESHOLD = Option.create(FailsafeProperties.FAILSAFE_CIRCBREAKER_FAILURE_THRESHOLD, 3);
/**
* The capacity for storing execution results when performing failure thresholding (Default: 5)
*
* @see Circuit Breaker - Opening
*/
public static final Option FAILSAFE_CIRCBREAKER_FAILURE_THRESHOLDING_CAP = Option.create(FailsafeProperties.FAILSAFE_CIRCBREAKER_FAILURE_THRESHOLDING_CAP, 5);
/**
* Configures count based success thresholding by setting the number of consecutive successful transactions that must occur when in a HALF_OPEN state in order to close the circuit, else the circuit is re-opened when a failure occurs. (Default: 1)
*
* @see Circuit Breaker - Closing
*/
public static final Option FAILSAFE_CIRCBREAKER_SUCCESS_THRESHOLD = Option.create(FailsafeProperties.FAILSAFE_CIRCBREAKER_SUCCESS_THRESHOLD, 1);
private ConnectOptions() {
}
//
}