summaryrefslogtreecommitdiffstats
path: root/config/src/vespa/config/frt/frtconnection.h
blob: 8eb963dc8789231ee20b37b95b530d332d9794ae (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <string>
#include <vespa/vespalib/util/sync.h>
#include <vespa/vespalib/stllike/string.h>
#include <vespa/config/common/timingvalues.h>
#include "connection.h"

class FRT_Supervisor;
class FRT_Target;

namespace config {

class FRTConnection : public Connection {

private:
    FRTConnection(const FRTConnection&);
    FRTConnection& operator=(const FRTConnection&);

    const vespalib::string _address;
    FRT_Supervisor& _supervisor;
    FRT_Target* _target;
    int64_t _suspendedUntil;
    int64_t _suspendWarned;
    int _transientFailures;
    int _fatalFailures;
    int64_t _transientDelay;
    int64_t _fatalDelay;

    FRT_Target * getTarget();

public:
    typedef std::shared_ptr<FRTConnection> SP;
    enum ErrorType { TRANSIENT, FATAL };

    FRTConnection(const vespalib::string & address, FRT_Supervisor & supervisor, const TimingValues & timingValues);
    ~FRTConnection();

    FRT_RPCRequest * allocRPCRequest() override;
    void invoke(FRT_RPCRequest * req, double timeout, FRT_IRequestWait * waiter) override;
    const vespalib::string & getAddress() const override { return _address; }
    int64_t getSuspendedUntil() { return _suspendedUntil; }
    void setError(int errorCode) override;
    void setSuccess();
    void calculateSuspension(ErrorType type);
    int64_t getTransientDelay() { return _transientDelay; }
    int64_t getMaxTransientDelay() { return getTransientDelay() * 6; }
    void setTransientDelay(int64_t delay) override { _transientDelay = delay; }
    int64_t getFatalDelay() { return _fatalDelay; }
    int64_t getMaxFatalDelay() { return getFatalDelay() * 6; }
    void setFatalDelay(int64_t delay) { _fatalDelay = delay; }
};

} // namespace config