aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/network/rpcserviceaddress.h
blob: 2ca57474a80d2ba4337a0c18077c8b48d997aa5d (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <string>
#include "iserviceaddress.h"
#include "rpctarget.h"

namespace mbus {

/**
 * An RPCServiceAddress contains the service name, connection spec and
 * session name of a concrete remote rpc service.
 **/
class RPCServiceAddress : public IServiceAddress {
private:
    string   _serviceName;
    string   _sessionName;
    string   _connectionSpec;
    RPCTarget::SP _target;

public:
    /**
     * Convenience typedefs.
     */
    using UP = std::unique_ptr<RPCServiceAddress>;

    /**
     * Constructs a service address from the given specifications. The last component of the service is stored
     * as the session name.
     *
     * @param serviceName    The full service name of the address.
     * @param connectionSpec The connection specification.
     */
    RPCServiceAddress(const string &serviceName, const string &connectionSpec);
    ~RPCServiceAddress() override;

    /**
     * Returns whether or not this service address is malformed.
     *
     * @return True if malformed.
     */
    bool isMalformed();

    /**
     * Returns the name of the remove service.
     *
     * @return The service name.
     */
    const string &getServiceName() const { return _serviceName; }

    /**
     * Returns the name of the remote session.
     *
     * @return The session name.
     */
    const string &getSessionName() const { return _sessionName; }

    /**
     * Returns the connection spec for the remote service.
     *
     * @return The connection spec.
     */
    const string &getConnectionSpec() const { return _connectionSpec; }

    /**
     * Sets the RPC target to be used when communicating with the remove service.
     *
     * @param target The target to set.
     */
    void setTarget(RPCTarget::SP target) { _target = std::move(target); }

    /**
     * Returns the RPC target to be used when communicating with the remove service. Make sure that {@link
     * hasTarget()} returns true before calling this method, or you will be deref'ing null.
     *
     * @return The target to use.
     */
    RPCTarget &getTarget() { return *_target; }

    /**
     * Returns whether or not this has an RPC target set.
     *
     * @return True if target is set.
     */
    bool hasTarget() const { return bool(_target); }
};

} // namespace mbus