summaryrefslogtreecommitdiff
path: root/cpp/src/IceStorm/Observers.h
blob: a35deae6154b4558243beb482637c298d8603288 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef OBSERVERS_H
#define OBSERVERS_H

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

#ifdef __SUNPRO_CC
#  pragma error_messages(off,hidef)
#endif


namespace IceStorm
{
class Instance;
typedef IceUtil::Handle<Instance> InstancePtr;
class TraceLevels;
typedef IceUtil::Handle<TraceLevels> TraceLevelsPtr;
}

namespace IceStormElection
{

class Observers : public IceUtil::Shared, public IceUtil::Mutex
{
public:
    Observers(const IceStorm::InstancePtr&);

    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 IceStorm::TraceLevelsPtr _traceLevels;
    unsigned int _majority;
    struct ObserverInfo
    {
        ObserverInfo(int i, const ReplicaObserverPrx& o) :
            id(i), observer(o) {}
        int id;
        ReplicaObserverPrx observer;
        ::Ice::AsyncResultPtr result;
    };
    std::vector<ObserverInfo> _observers;
    IceUtil::Mutex _reapedMutex;
    std::vector<int> _reaped;
};
typedef IceUtil::Handle<Observers> ObserversPtr;

}

#ifdef __SUNPRO_CC
#  pragma error_messages(default,hidef)
#endif

#endif // OBSERVERS_H