summaryrefslogtreecommitdiff
path: root/cpp/src/IceStorm/Observers.h
blob: ed7a6d535fa88ad0afae309cd28c24f92f5db216 (plain)
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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

#ifndef OBSERVERS_H
#define OBSERVERS_H

#include <Ice/Ice.h>
#include <IceUtil/IceUtil.h>
#include <IceStorm/Election.h>
#include <IceStorm/Replica.h>

namespace IceStorm
{
class TraceLevels;
}

namespace IceStormElection
{

class Observers
{
public:
    Observers(std::shared_ptr<IceStorm::TraceLevels>);

    void setMajority(unsigned int);

    // Check that we have enough nodes for replication.
    bool check();
    void clear();

    void init(const std::set<IceStormElection::GroupNodeInfo>&, const LogUpdate&, const TopicContentSeq&);
    void createTopic(const LogUpdate&, const std::string&);
    void destroyTopic(const LogUpdate&, const std::string&);
    void addSubscriber(const LogUpdate&, const std::string&, const IceStorm::SubscriberRecord&);
    void removeSubscriber(const LogUpdate&, const std::string&, const Ice::IdentitySeq&);
    void getReapedSlaves(std::vector<int>&);

private:

    void wait(const std::string&);

    const std::shared_ptr<IceStorm::TraceLevels> _traceLevels;
    unsigned int _majority;
    struct ObserverInfo
    {
        int id;
        std::shared_ptr<ReplicaObserverPrx> observer;
        std::future<void> future;
    };
    std::vector<ObserverInfo> _observers;

    std::mutex _reapedMutex;
    std::vector<int> _reaped;

    std::mutex _mutex;
};

}

#endif // OBSERVERS_H