goraft/raft — pull request #141 by benbjohnson (2013-12-19 23:45:59+00:00)
Title: Event Dispatch

## Overview

This pull request includes an event dispatcher implementation that the `Server` uses. This gives applications the ability to hook into multiple event types using the observer pattern.

The `Event` includes the event type, the source of the event and the current and previous value related to the event.

## Event Types

The following event types are implemented:

```
stateChange - Dispatched when the state changes on the server.
leaderChange - Dispatched when the leader changes on the server.
termChange - Dispatched when the term changes on the server.
addPeer - Dispatched when a peer is added.
removePeer - Dispatched when a peer is removed.
```

## Server Interface Changes

Only one function is added to the `Server` interface:

```go
func AddEventListener(typ string, func(Event))
```

There is no `RemoveEventListener()` because you can't compare functions in Go. There are ways we could get around it but I'm going to wait until we actually need to remove event listeners before implementing it.

## Notes

We can easily add more types of events but I thought this was a good first cut. I mostly want to get feedback on the approach so far.

/cc: @philips @xiangli-cmu