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

io.axoniq.flowcontrol.producer.grpc.ActiveSubscriptions Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
/*
 * Copyright (c) 2021. AxonIQ
 *
 * 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.axoniq.flowcontrol.producer.grpc;

import java.util.Optional;

/**
 * A collection of subscription used to request new items from publishers.
 *
 * @author Sara Pellegrini
 * @author Milan Savic
 * @since 1.0
 */
public interface ActiveSubscriptions {

    /**
     * Adds a new subscription.
     * @param subscription
     */
    void add(ActiveSubscription subscription);

    /**
     * Remove a subscription.
     * @param subscription
     */
    void remove(ActiveSubscription subscription);

    /**
     * Returns {@code true} if there is no subscription. //TODO rename method
     * @return
     */
    boolean hasNext();

    /**
     * Returns the next subscription that should be used to request next item. It doesn't iterate over all subscriptions
     * in a specific order, as it can return for many times the same subscription if this has a greater priority,
     * depending on the implementation.
     *
     * @return the next subscription that should be requested for next item.
     */
    Optional next();

    /**
     * Functional interface to request a new item from a publisher.
     *
     * @author Sara Pellegrini
     * @author Milan Savic
     * @since 1.0
     */
    interface ActiveSubscription {

        /**
         * Requests a new item from a publisher.
         */
        void request();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy