aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/examples/02_discovery/services.h
blob: 266517c577213f9af19b352efff7c30093b67d50 (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
#pragma once
#include <library/cpp/actors/examples/02_discovery/protocol.pb.h>

#include <library/cpp/actors/core/actor.h>
#include <library/cpp/actors/core/events.h>
#include <library/cpp/actors/core/event_pb.h>
#include <library/cpp/actors/core/event_local.h>

#include <util/generic/vector.h>

using namespace NActors;

struct TExampleStorageConfig : public TThrRefBase {
    TVector<TActorId> Replicas;
};

struct TEvExample {
    enum EEv {
        EvReplicaLookup = EventSpaceBegin(TEvents::ES_USERSPACE + 1),
        EvReplicaPublish,

        EvReplicaInfo = EventSpaceBegin(TEvents::ES_USERSPACE + 2),
        EvReplicaPublishAck,

        EvInfo = EventSpaceBegin(TEvents::ES_USERSPACE + 3),
    };

    struct TEvReplicaLookup : public TEventPB<TEvReplicaLookup, NActorsExample::TEvReplicaLookup, EvReplicaLookup> {
        TEvReplicaLookup()
        {}

        TEvReplicaLookup(const TString &key)
        {
            Record.SetKey(key);
        }
    };

    struct TEvReplicaPublish : public TEventPB<TEvReplicaPublish, NActorsExample::TEvReplicaPublish, EvReplicaPublish> {
        TEvReplicaPublish()
        {}

        TEvReplicaPublish(const TString &key, const TString &payload)
        {
            Record.SetKey(key);
            Record.SetPayload(payload);
        }
    };

    struct TEvReplicaInfo : public TEventPB<TEvReplicaInfo, NActorsExample::TEvReplicaInfo, EvReplicaInfo> {
        TEvReplicaInfo()
        {}

        TEvReplicaInfo(const TString &key)
        {
            Record.SetKey(key);
        }
    };

    struct TEvReplicaPublishAck : public TEventPB<TEvReplicaPublishAck, NActorsExample::TEvReplicaPublishAck, EvReplicaPublishAck> {
        TEvReplicaPublishAck()
        {}

        TEvReplicaPublishAck(const TString &key)
        {
            Record.SetKey(key);
        }
    };

    struct TEvInfo : public TEventLocal<TEvInfo, EvInfo> {
        const TString Key;
        const TVector<TString> Payloads;

        TEvInfo(const TString &key, TVector<TString> &&payloads)
            : Key(key)
            , Payloads(payloads)
        {}
    };
};

IActor* CreateReplica();
IActor* CreatePublishActor(TExampleStorageConfig *config, const TString &key, const TString &what);
IActor* CreateLookupActor(TExampleStorageConfig *config, const TString &key, TActorId replyTo);
IActor* CreateEndpointActor(TExampleStorageConfig *config, const TString &publishKey, ui16 httpPort);

TActorId MakeReplicaId(ui32 nodeid);