Apache Mesos
detector.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License
16 
17 #ifndef __MESOS_ZOOKEEPER_DETECTOR_HPP__
18 #define __MESOS_ZOOKEEPER_DETECTOR_HPP__
19 
20 #include <string>
21 
23 
24 #include <stout/result.hpp>
25 
26 #include <process/future.hpp>
27 
28 namespace zookeeper {
29 
30 // Forward declaration.
31 class LeaderDetectorProcess;
32 
33 // Provides an abstraction for detecting the leader of a ZooKeeper
34 // group.
36 {
37 public:
38  // The specified 'group' is expected to outlive the detector.
39  explicit LeaderDetector(Group* group);
40  virtual ~LeaderDetector();
41 
42  // Returns some membership after an election has occurred and a
43  // leader (membership) is elected, or none if an election occurs and
44  // no leader is elected (e.g., all memberships are lost).
45  // A failed future is returned if the detector is unable to detect
46  // the leading master due to a non-retryable error.
47  // Note that the detector transparently tries to recover from
48  // retryable errors until the group session expires, in which case
49  // the Future returns None.
50  // The future is never discarded unless it stays pending when the
51  // detector destructs.
52  //
53  // The 'previous' result (if any) should be passed back if this
54  // method is called repeatedly so the detector only returns when it
55  // gets a different result.
56  //
57  // TODO(xujyan): Use a Stream abstraction instead.
59  const Option<Group::Membership>& previous = None());
60 
61 private:
62  LeaderDetectorProcess* process;
63 };
64 
65 } // namespace zookeeper {
66 
67 #endif // __MESOS_ZOOKEEPER_DETECTOR_HPP__
process::Future< Option< Group::Membership > > detect(const Option< Group::Membership > &previous=None())
Definition: option.hpp:29
LeaderDetector(Group *group)
Definition: authentication.hpp:33
Definition: grp.hpp:26
Definition: none.hpp:27
Definition: group.hpp:49
Definition: executor.hpp:48
Definition: detector.hpp:35
Definition: future.hpp:58