Add Server.LastCommandName().

pull/820/head
Ben Johnson 2013-06-03 15:13:38 -04:00
parent 894eb08592
commit ba9b7739e4
2 changed files with 26 additions and 0 deletions

12
log.go
View File

@ -73,6 +73,18 @@ func (l *Log) IsEmpty() bool {
return (len(l.entries) == 0) return (len(l.entries) == 0)
} }
// The name of the last command in the log.
func (l *Log) LastCommandName() string {
l.mutex.Lock()
defer l.mutex.Unlock()
if len(l.entries) > 0 {
if command := l.entries[len(l.entries)-1].Command; command != nil {
return command.CommandName()
}
}
return ""
}
//-------------------------------------- //--------------------------------------
// Log Terms // Log Terms
//-------------------------------------- //--------------------------------------

View File

@ -150,17 +150,31 @@ func (s *Server) VotedFor() string {
// Retrieves whether the server's log has no entries. // Retrieves whether the server's log has no entries.
func (s *Server) IsLogEmpty() bool { func (s *Server) IsLogEmpty() bool {
s.mutex.Lock()
defer s.mutex.Unlock()
return s.log.IsEmpty() return s.log.IsEmpty()
} }
// A list of all the log entries. This should only be used for debugging purposes. // A list of all the log entries. This should only be used for debugging purposes.
func (s *Server) LogEntries() []*LogEntry { func (s *Server) LogEntries() []*LogEntry {
s.mutex.Lock()
defer s.mutex.Unlock()
if s.log != nil { if s.log != nil {
return s.log.entries return s.log.entries
} }
return nil return nil
} }
// A reference to the command name of the last entry.
func (s *Server) LastCommandName() string {
s.mutex.Lock()
defer s.mutex.Unlock()
if s.log != nil {
return s.log.LastCommandName()
}
return ""
}
//-------------------------------------- //--------------------------------------
// Membership // Membership
//-------------------------------------- //--------------------------------------