aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/main/java/com/yahoo/messagebus/routing/RetryPolicy.java
blob: 8b0abe3f1273668292a3b1353aafe7a6d9aaeb6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.routing;

/**
 * When a {@link com.yahoo.messagebus.Reply} containing errors is returned to a {@link com.yahoo.messagebus.MessageBus},
 * an object implementing this interface is consulted on whether or not to resend the corresponding {@link
 * com.yahoo.messagebus.Message}. The policy is passed to the message bus at creation time using the {@link
 * com.yahoo.messagebus.MessageBusParams#setRetryPolicy(RetryPolicy)} method.
 *
 * @author Simon Thoresen Hult
 */
public interface RetryPolicy {

    /**
     * Returns whether or not a {@link com.yahoo.messagebus.Reply} containing an {@link com.yahoo.messagebus.Error} with
     * the given error code can be retried. This method is invoked once for each error in a reply.
     *
     * @param errorCode The code to check.
     * @return True if the message can be resent.
     */
    public boolean canRetry(int errorCode);

    /**
     * Returns the number of seconds to delay resending a message.
     *
     * @param retry The retry attempt.
     * @return The delay in seconds.
     */
    public double getRetryDelay(int retry);
}