Apache Mesos
contender.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_CONTENDER_HPP__
18 #define __MESOS_ZOOKEEPER_CONTENDER_HPP__
19 
20 #include <string>
21 
23 
24 #include <process/future.hpp>
25 
26 #include <stout/nothing.hpp>
27 #include <stout/option.hpp>
28 
29 namespace zookeeper {
30 
31 // Forward declaration.
32 class LeaderContenderProcess;
33 
34 
35 // Provides an abstraction for contending to be the leader of a
36 // ZooKeeper group.
37 // Note that the contender is NOT reusable, which means its methods
38 // are supposed to be called once and the client needs to create a
39 // new instance to contend again.
41 {
42 public:
43  // The specified 'group' is expected to outlive the contender. The
44  // specified 'data' is associated with the group membership created
45  // by this contender. 'label' indicates the label for the znode that
46  // stores the 'data'.
48  const std::string& data,
49  const Option<std::string>& label);
50 
51  // Note that the contender's membership, if obtained, is scheduled
52  // to be cancelled during destruction.
53  // NOTE: The client should call withdraw() to guarantee that the
54  // membership is cancelled when its returned future is satisfied.
55  virtual ~LeaderContender();
56 
57  // Returns a Future<Nothing> once the contender has achieved
58  // candidacy (by obtaining a membership) and a failure otherwise.
59  // The inner Future returns Nothing when the contender is out of
60  // the contest (i.e. its membership is lost) and a failure if it is
61  // unable to watch the membership.
62  // It should be called only once, otherwise a failure is returned.
64 
65  // Returns true if successfully withdrawn from the contest (either
66  // while contending or has already contended and is watching for
67  // membership loss).
68  // A false return value implies that there was no valid group
69  // membership to cancel, which may be a result of a race to cancel
70  // an expired membership or because there is nothing to withdraw.
71  // A failed future is returned if the contender is unable to
72  // withdraw.
74 
75 private:
76  LeaderContenderProcess* process;
77 };
78 
79 } // namespace zookeeper {
80 
81 #endif // __MESOS_ZOOKEEPER_CONTENDER_HPP__
process::Future< bool > withdraw()
Definition: authentication.hpp:33
Definition: contender.hpp:40
Definition: grp.hpp:26
Definition: group.hpp:49
process::Future< process::Future< Nothing > > contend()
Definition: executor.hpp:48
LeaderContender(Group *group, const std::string &data, const Option< std::string > &label)
Definition: future.hpp:58