Debian Codegraph @

api/v0/detector/interface.go

raw symbols SCIP
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package detector
20
21 import (
22 mesos "github.com/mesos/mesos-go/api/v0/mesosproto"
23 )
24
25 type MasterChanged interface {
26 // Invoked when the master changes
27 OnMasterChanged(*mesos.MasterInfo)
28 }
29
30 // AllMasters defines an optional interface that, if implemented by the same
31 // struct as implements MasterChanged, will receive an additional callbacks
32 // independently of leadership changes. it's possible that, as a result of a
33 // leadership change, both the OnMasterChanged and UpdatedMasters callbacks
34 // would be invoked.
35 //
36 // **NOTE:** Detector implementations are not required to support this optional
37 // interface. Please RTFM of the detector implementation that you want to use.
38 type AllMasters interface {
39 // UpdatedMasters is invoked upon a change in the membership of mesos
40 // masters, and is useful to clients that wish to know the entire set
41 // of Mesos masters currently running.
42 UpdatedMasters([]*mesos.MasterInfo)
43 }
44
45 // func/interface adapter
46 type OnMasterChanged func(*mesos.MasterInfo)
47
48 func (f OnMasterChanged) OnMasterChanged(mi *mesos.MasterInfo) {
49 f(mi)
50 }
51
52 // An abstraction of a Master detector which can be used to
53 // detect the leading master from a group.
54 type Master interface {
55 // Detect new master election. Every time a new master is elected, the
56 // detector will alert the observer. The first call to Detect is expected
57 // to kickstart any background detection processing (and not before then).
58 // If detection startup fails, or the listener cannot be added, then an
59 // error is returned.
60 Detect(MasterChanged) error
61
62 // returns a chan that, when closed, indicates the detector has terminated
63 Done() <-chan struct{}
64
65 // cancel the detector. it's ok to call this multiple times, or even if
66 // Detect() hasn't been invoked yet.
67 Cancel()
68 }
69
70 // functional option type for detectors
71 type Option func(interface{}) Option