aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/message/internal.h
blob: 035f1a4ffebea48afc0751c97f50de1be8858d0b (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * @file internal.h
 *
 * Internal commands, used in storage. These are commands that don't need to
 * be serialized as they never leave a node, implemented within storage itself
 * to be able to include storage types not defined in the API.
 *
 * Historically these messages also existed so we could alter internal messages
 * without recompiling clients, but currently no clients use storage API for
 * communication anymore so this is no longer an issue.
 */
#pragma once

#include <vespa/storageapi/messageapi/storagecommand.h>
#include <vespa/storageapi/messageapi/storagereply.h>

namespace storage::api {

/**
 * @class InternalCommand
 * @ingroup message
 *
 * @brief Base class for commands local to a VDS node.
 *
 * This is the base class for internal server commands. They can not be
 * serialized, so any attempt of sending such a command away from a storage
 * node will fail.
 */
class InternalCommand : public StorageCommand {
    uint32_t _type;

public:
    InternalCommand(uint32_t type);
    ~InternalCommand() override;

    uint32_t getType() const { return _type; }

    bool callHandler(MessageHandler& h, const std::shared_ptr<StorageMessage> & m) const override {
        return h.onInternal(std::static_pointer_cast<InternalCommand>(m));
    }

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
};

/**
 * @class InternalReply
 * @ingroup message
 *
 * @brief Response of an internal command.
 */
class InternalReply : public StorageReply {
    uint32_t _type;

public:
    InternalReply(uint32_t type, const InternalCommand& cmd);
    ~InternalReply() override;

    uint32_t getType() const { return _type; }

    bool callHandler(MessageHandler& h, const std::shared_ptr<StorageMessage> & m) const override {
        return h.onInternalReply(std::static_pointer_cast<InternalReply>(m));
    }

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
};

}