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

com.bazaarvoice.ostrich.AsyncServicePool Maven / Gradle / Ivy

package com.bazaarvoice.ostrich;

import java.io.Closeable;
import java.util.Collection;
import java.util.concurrent.Future;

/**
 * An asynchronous service pool.  This mimics the behavior of a {@link ServicePool}, but instead of executing its
 * callbacks synchronously, it will run them in the background.
 *
 * @param  The service interface that this pool keeps track of end points for.
 */
public interface AsyncServicePool extends Closeable {
    /**
     * Execute a request asynchronously against one of the remote services in this {@code ServicePool}, returning
     * a future representing the asynchronous call.
     *
     * @param retryPolicy The retry policy for the operation.
     * @param callback    The user provided callback to invoke.
     * @param          The return type for the call.
     * @return            A future representing the call.
     */
     Future execute(RetryPolicy retryPolicy, ServiceCallback callback);

    /**
     * Execute a request asynchronously against one of the remote services in this {@code ServicePool} using the
     * specified partition information to narrow down the suitable service end points.
     *
     * @param partitionContext The partition context.
     * @param retryPolicy      The retry policy for the operation.
     * @param callback         The user provided callback to invoke with a service end point.
     * @param               The return type for the call.
     * @return                 A future representing the call.
     */
     Future execute(PartitionContext partitionContext, RetryPolicy retryPolicy, ServiceCallback callback);

    /**
     * Execute a request asynchronously against ALL of the remote services in this {@code ServicePool},
     * returning a future for each asynchronous call.
     * 

* NOTE: It is undefined how the implementation handles the situation where an end point is discovered or removed * while the {@code executeOnAll} operation is executing. * * @param retryPolicy The retry policy for each operation. * @param callback The user provided callback to invoke. * @param The return type for the call. * @return A collection with one future for each end point being called. */ Collection> executeOnAll(RetryPolicy retryPolicy, ServiceCallback callback); /** * Execute a request asynchronously against some of the remote services in this {@code ServicePool}, * returning a future for each asynchronous call. *

* NOTE: It is undefined how the implementation handles the situation where an end point is discovered or removed * while the {@code executeOn} operation is executing. * * @param predicate A predicate indicating which service end points the request should be executed against. If * the predicate returns {@code true} then the request will be executed against that end point. * @param retryPolicy The retry policy for each operation. * @param callback The user provided callback to invoke. * @param The return type for the call. * @return A collection with one future for each end point being called. */ Collection> executeOn(ServiceEndPointPredicate predicate, RetryPolicy retryPolicy, ServiceCallback callback); /** * Return the number of valid end points that this service pool knows about. This will include end points that have * never thrown exceptions during execution (even those that have never been interacted with) and end points that * were previously known as bad but have since had a successful health check. If this method returns non-zero, then * a call to execute should not fail with an {@link com.bazaarvoice.ostrich.exceptions.OnlyBadHostsException} or * {@link com.bazaarvoice.ostrich.exceptions.NoAvailableHostsException} exception. */ int getNumValidEndPoints(); /** * Return the number of end points that this service pool considers to be in a bad state. A bad end point is one * that a previous operation was attempted on and the attempt failed. An end point could be considered bad prior to * its health check being called. *

* This combined with {@link #getNumValidEndPoints()} gives visibility into the total number of end points that the * {@code ServicePool} knows about. */ int getNumBadEndPoints(); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy