aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/main/java/com/yahoo/messagebus/SourceSessionParams.java
blob: bce2c9f29dd055c3adaa1e9e75b89ca7d4bd0037 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus;

/**
 * To facilitate several configuration parameters to the {@link MessageBus#createSourceSession(ReplyHandler,
 * SourceSessionParams)}, all parameters are held by this class. This class has reasonable default values for each
 * parameter.
 *
 * @author Simon Thoresen Hult
 */
public class SourceSessionParams {

    private ReplyHandler replyHandler = null;
    private ThrottlePolicy throttlePolicy = new DynamicThrottlePolicy();
    private double timeout = 180.0;

    /**
     * Instantiates a parameter object with default values.
     */
    public SourceSessionParams() {
        // empty
    }

    /**
     * Implements the copy constructor.
     *
     * @param params the object to copy
     */
    public SourceSessionParams(SourceSessionParams params) {
        throttlePolicy = params.throttlePolicy;
        timeout = params.timeout;
        replyHandler = params.replyHandler;
    }

    /** Returns the policy to use for throttling output. */
    public ThrottlePolicy getThrottlePolicy() {
        return throttlePolicy;
    }

    /**
     * Sets the policy to use for throttling output.
     *
     * @param throttlePolicy The policy to set.
     * @return this, to allow chaining
     */
    public SourceSessionParams setThrottlePolicy(ThrottlePolicy throttlePolicy) {
        this.throttlePolicy = throttlePolicy;
        return this;
    }

    /**
     * Returns the number of seconds a message can spend trying to succeed.
     *
     * @return the timeout in seconds
     */
    public double getTimeout() {
        return timeout;
    }

    /**
     * Sets the number of seconds a message can be attempted sent until it times out. This is the maximum allowed time
     * for any message bus operation.
     *
     * @param timeout The numer of seconds allowed.
     * @return this, to allow chaining
     */
    public SourceSessionParams setTimeout(double timeout) {
        this.timeout = timeout;
        return this;
    }

    /**
     * Returns whether or not a reply handler has been assigned to this.
     *
     * @return true if a handler is set
     */
    boolean hasReplyHandler() {
        return replyHandler != null;
    }

    /**
     * Returns the handler to receive incoming replies.
     *
     * @return the handler
     */
    public ReplyHandler getReplyHandler() {
        return replyHandler;
    }

    /**
     * Sets the handler to recive incoming replies.
     *
     * @param handler The handler to set.
     * @return this, to allow chaining
     */
    public SourceSessionParams setReplyHandler(ReplyHandler handler) {
        replyHandler = handler;
        return this;
    }

}