001package com.box.sdk;
002
003/**
004 * Global settings to apply to all API requests.
005 */
006public final class BoxGlobalSettings {
007    private static int connectTimeout = 0;
008    private static int readTimeout = 0;
009    private static int maxRetryAttempts = BoxAPIConnection.DEFAULT_MAX_RETRIES;
010
011    private BoxGlobalSettings() {
012    }
013
014    /**
015     * Returns the current global connect timeout.
016     *
017     * @return connect timeout
018     */
019    public static int getConnectTimeout() {
020        return connectTimeout;
021    }
022
023    /**
024     * Sets the global connect timeout.
025     *
026     * @param connectTimeout timeout in milliseconds
027     */
028    public static void setConnectTimeout(int connectTimeout) {
029        BoxGlobalSettings.connectTimeout = connectTimeout;
030    }
031
032    /**
033     * Returns the current global read timeout.
034     *
035     * @return read timeout
036     */
037    public static int getReadTimeout() {
038        return readTimeout;
039    }
040
041    /**
042     * Sets the global read timeout.
043     *
044     * @param readTimeout timeout in milliseconds
045     */
046    public static void setReadTimeout(int readTimeout) {
047        BoxGlobalSettings.readTimeout = readTimeout;
048    }
049
050    /**
051     * Returns the global total maximum number of times an API request will be tried when error responses
052     * are received.
053     *
054     * @return max number of request attempts
055     * @deprecated getMaxRetryAttempts is preferred because it more clearly gets the number
056     * of times a request should be retried after an error response is received.
057     */
058    @Deprecated
059    public static int getMaxRequestAttempts() {
060        return maxRetryAttempts + 1;
061    }
062
063    /**
064     * Sets the global total maximum number of times an API request will be tried when error responses
065     * are received.
066     *
067     * @param attempts maximum number of request attempts
068     * @deprecated setMaxRetryAttempts is preferred because it more clearly sets the number
069     * of times a request should be retried after an error response is received.
070     */
071    @Deprecated
072    public static void setMaxRequestAttempts(int attempts) {
073        BoxGlobalSettings.maxRetryAttempts = attempts - 1;
074    }
075
076    /**
077     * Returns the global maximum number of times an API request will be retried after an error response
078     * is received.
079     *
080     * @return max number of request attempts
081     */
082    public static int getMaxRetryAttempts() {
083        return maxRetryAttempts;
084    }
085
086    /**
087     * Sets the global maximum number of times an API request will be retried after an error response
088     * is received.
089     *
090     * @param attempts maximum number of request attempts
091     */
092    public static void setMaxRetryAttempts(int attempts) {
093        BoxGlobalSettings.maxRetryAttempts = attempts;
094    }
095}