Add s.Peers() and peer cloning.

pull/820/head
Ben Johnson 2013-06-26 12:25:22 -06:00
parent ff349bbe40
commit 46fb02f191
2 changed files with 27 additions and 0 deletions

15
peer.go
View File

@ -107,6 +107,21 @@ func (p *Peer) stop() {
p.heartbeatTimer.Stop()
}
//--------------------------------------
// Copying
//--------------------------------------
// Clones the state of the peer. The clone is not attached to a server and
// the heartbeat timer will not exist.
func (p *Peer) clone() *Peer {
p.mutex.Lock()
defer p.mutex.Unlock()
return &Peer{
name: p.name,
prevLogIndex: p.prevLogIndex,
}
}
//--------------------------------------
// Flush
//--------------------------------------

View File

@ -134,6 +134,18 @@ func (s *Server) Leader() string {
return s.leader
}
// Retrieves a copy of the peer data.
func (s *Server) Peers() map[string]*Peer {
s.mutex.Lock()
defer s.mutex.Unlock()
peers := make(map[string]*Peer)
for name, peer := range s.peers {
peers[name] = peer.clone()
}
return peers
}
// Retrieves the object that transports requests.
func (s *Server) Transporter() Transporter {
return s.transporter