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

io.servicetalk.client.api.internal.ReservableRequestConcurrencyControllers Maven / Gradle / Ivy

/*
 * Copyright © 2018 Apple Inc. and the ServiceTalk project authors
 *
 * 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 io.servicetalk.client.api.internal;

import io.servicetalk.client.api.ConsumableEvent;
import io.servicetalk.concurrent.api.Completable;
import io.servicetalk.concurrent.api.Publisher;

/**
 * Factory for common {@link ReservableRequestConcurrencyController}s.
 *
 * @deprecated This class is not used by ServiceTalk internal code anymore and will be removed in the future releases.
 * If you depend on it, consider replicating this implementation in your codebase.
 */
@Deprecated
public final class ReservableRequestConcurrencyControllers {
    private ReservableRequestConcurrencyControllers() { // FIXME: 0.43 - remove deprecated class
        // no instances
    }

    /**
     * Create a new instance of {@link ReservableRequestConcurrencyController}.
     * @param maxConcurrency A {@link Publisher} that provides the maximum allowed concurrency updates.
     * @param onClosing A {@link Completable} that when terminated no more calls to
     * {@link RequestConcurrencyController#tryRequest()} are expected to succeed.
     * @param initialMaxConcurrency The initial maximum value for concurrency, until {@code maxConcurrencySetting}
     * provides data.
     * @return a new instance of {@link ReservableRequestConcurrencyController}.
     */
    public static ReservableRequestConcurrencyController newController(
            final Publisher> maxConcurrency, final Completable onClosing,
            final int initialMaxConcurrency) {
        return new ReservableRequestConcurrencyControllerMulti(maxConcurrency, onClosing, initialMaxConcurrency);
    }

    /**
     * Create a {@link ReservableRequestConcurrencyController} that only allows a single outstanding request. Even
     * if {@code maxConcurrencySetting} increases beyond {@code 1} only a single
     * {@link RequestConcurrencyController#tryRequest()} will succeed at any given time. The initial value is assumed
     * to be {@code 1} and only lesser values from {@code maxConcurrencySetting} will impact behavior.
     * @param maxConcurrency A {@link Publisher} that provides the maximum allowed concurrency updates.
     * Only values of {@code <1} will impact behavior.
     * @param onClosing A {@link Completable} that when terminated no more calls to
     * {@link RequestConcurrencyController#tryRequest()} are expected to succeed.
     * @return a {@link ReservableRequestConcurrencyController} that only allows a single outstanding request.
     */
    public static ReservableRequestConcurrencyController newSingleController(
            final Publisher> maxConcurrency, final Completable onClosing) {
        return new ReservableRequestConcurrencyControllerOnlySingle(maxConcurrency, onClosing);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy