Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1278)

Unified Diff: state/watcher.go

Issue 6447054: state: implement MachineInfoWatcher
Patch Set: state: implement MachineInfoWatcher Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « state/util.go ('k') | version/version.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: state/watcher.go
=== modified file 'state/watcher.go'
--- state/watcher.go 2012-07-26 15:14:40 +0000
+++ state/watcher.go 2012-07-30 17:07:26 +0000
@@ -431,6 +431,47 @@
close(w.changeChan)
}
+// MachineWatcher observes changes to the settings of a machine.
+type MachineWatcher struct {
+ contentWatcher
+ m *Machine
+ changeChan chan *Machine
+}
+
+// newMachineWatcher creates and starts a watcher to watch information
+// about the machine.
+func newMachineWatcher(m *Machine) *MachineWatcher {
+ w := &MachineWatcher{
+ m: m,
+ contentWatcher: newContentWatcher(m.st, m.zkPath()),
+ changeChan: make(chan *Machine),
+ }
+ go w.loop(w)
+ return w
+}
+
+// Changes returns a channel that will receive the new
+// *Machine when a change is detected. Note that multiple
+// changes may be observed as a single event in the channel.
+// The first event on the channel holds the initial state
+// as returned by Machine.Info.
+func (w *MachineWatcher) Changes() <-chan *Machine {
+ return w.changeChan
+}
+
+func (w *MachineWatcher) update(change watcher.ContentChange) error {
+ select {
+ case <-w.tomb.Dying():
+ return tomb.ErrDying
+ case w.changeChan <- w.m:
+ }
+ return nil
+}
+
+func (w *MachineWatcher) done() {
+ close(w.changeChan)
+}
+
// ServicesWatcher observes the addition and removal of services.
type ServicesWatcher struct {
contentWatcher
« no previous file with comments | « state/util.go ('k') | version/version.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b