|
| 1 | +/* |
| 2 | +Copyright IBM Corp. 2016 All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package election |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/hyperledger/fabric/gossip/common" |
| 21 | + "github.com/hyperledger/fabric/gossip/proto" |
| 22 | +) |
| 23 | + |
| 24 | +// LeaderElectionAdapter is used by the leader election module |
| 25 | +// to send and receive messages, as well as notify a leader change |
| 26 | +type LeaderElectionAdapter interface { |
| 27 | + |
| 28 | + // Gossip gossips a message to other peers |
| 29 | + Gossip(msg *proto.GossipMessage) |
| 30 | + |
| 31 | + // Accept returns a channel that emits messages that fit |
| 32 | + // the given predicate |
| 33 | + Accept(common.MessageAcceptor) <-chan *proto.GossipMessage |
| 34 | +} |
| 35 | + |
| 36 | +// LeaderElectionService is the object that runs the leader election algorithm |
| 37 | +type LeaderElectionService interface { |
| 38 | + // IsLeader returns whether this peer is a leader or not |
| 39 | + IsLeader() bool |
| 40 | +} |
| 41 | + |
| 42 | +// LeaderElectionService is the implementation of LeaderElectionService |
| 43 | +type leaderElectionServiceImpl struct { |
| 44 | + adapter LeaderElectionAdapter |
| 45 | +} |
0 commit comments