aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/main/java/com/yahoo/messagebus/routing/ErrorDirective.java
blob: 1b814d71d2f6b53afc026490e9612668954ea495 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.routing;

/**
 * This class represents an error directive within a {@link Hop}'s selector. This means to stop whatever is being
 * resolved, and instead return a reply containing a specified error.
 *
 * @author Simon Thoresen Hult
 */
public class ErrorDirective implements HopDirective {

    private String msg;

    /**
     * Constructs a new error directive.
     *
     * @param msg The error message.
     */
    public ErrorDirective(String msg) {
        this.msg = msg;
    }

    /**
     * Returns the error string that is to be assigned to the reply.
     *
     * @return The error string.
     */
    public String getMessage() {
        return msg;
    }

    @Override
    public boolean matches(HopDirective dir) {
        return false;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ErrorDirective)) {
            return false;
        }
        ErrorDirective rhs = (ErrorDirective)obj;
        if (!msg.equals(rhs.msg)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "(" + msg + ")";
    }

    @Override
    public String toDebugString() {
        return "ErrorDirective(msg = '" + msg + "')";
    }

    @Override
    public int hashCode() {
        return msg != null ? msg.hashCode() : 0;
    }
}