aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/feedstate.h
blob: 050b296eeb63520b53673000bf04adfe64bd3660 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchcore/proton/common/feedtoken.h>
#include <vespa/vespalib/stllike/string.h>

namespace vespalib {
    class Executor;
}
namespace proton {

class FeedOperation;
struct PacketWrapper;

/**
 * Class representing the current state of a feed handler.
 */
class FeedState {
public:
    enum Type { NORMAL, REPLAY_TRANSACTION_LOG, INIT };

private:
    Type _type;

protected:
    using FeedOperationUP = std::unique_ptr<FeedOperation>;
    using PacketWrapperSP = std::shared_ptr<PacketWrapper>;
    void throwExceptionInReceive(const vespalib::string &docType, uint64_t serialRangeFrom,
                                 uint64_t serialRangeTo, size_t packetSize);
    void throwExceptionInHandleOperation(const vespalib::string &docType, const FeedOperation &op);

public:
    FeedState(Type type) : _type(type) {}
    virtual ~FeedState() = default;

    Type getType() const { return _type; }
    vespalib::string getName() const;

    virtual void handleOperation(FeedToken token, FeedOperationUP op) = 0;
    virtual void receive(const PacketWrapperSP &wrap, vespalib::Executor &executor) = 0;
};

}  // namespace proton