summaryrefslogtreecommitdiffstats
path: root/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp
blob: 3e886ac872ee6f9702472017bbe583a7d8a569a0 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "storagecommand.h"
#include <vespa/vespalib/util/exceptions.h>
#include <ostream>

namespace storage::api {

StorageCommand::StorageCommand(const StorageCommand& other)
    : StorageMessage(other, generateMsgId()),
      _timeout(other._timeout),
      _sourceIndex(other._sourceIndex)
{
    if ( !other.getTrace().isEmpty()) {
        setTrace(other.getTrace());
    } else {
        getTrace().setLevel(other.getTrace().getLevel());
    }
}

StorageCommand::StorageCommand(const MessageType& type, Priority p)
    : StorageMessage(type, generateMsgId()),
        // Default timeout is unlimited. Set from mbus message. Some internal
        // use want unlimited timeout, (such as readbucketinfo, repair bucket
        // etc)
      _timeout(duration::max()),
      _sourceIndex(0xFFFF)
{
    setPriority(p);
}

StorageCommand::~StorageCommand() = default;

void
StorageCommand::print(std::ostream& out, bool verbose,
                      const std::string& indent) const
{
    (void) verbose; (void) indent;
    out << "StorageCommand(" << _type.getName();
    if (_priority != NORMAL) out << ", priority = " << static_cast<int>(_priority);
    if (_sourceIndex != 0xFFFF) out << ", source = " << _sourceIndex;
    out << ", timeout = " << vespalib::count_ms(_timeout) << " ms";
    out << ")";
}

}