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

Side by Side Diff: mstate/unit.go

Issue 6489111: mstate: use Dead channels rather than Dying for watcher and presence
Patch Set: mstate: use Dead channels rather than Dying for watcher and presence Created 12 years, 6 months ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « mstate/presence/presence_test.go ('k') | mstate/watcher.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package mstate 1 package mstate
2 2
3 import ( 3 import (
4 "errors" 4 "errors"
5 "fmt" 5 "fmt"
6 "labix.org/v2/mgo" 6 "labix.org/v2/mgo"
7 "labix.org/v2/mgo/txn" 7 "labix.org/v2/mgo/txn"
8 "launchpad.net/juju-core/mstate/presence" 8 "launchpad.net/juju-core/mstate/presence"
9 "launchpad.net/juju-core/trivial" 9 "launchpad.net/juju-core/trivial"
10 "time" 10 "time"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 u.st.pwatcher.Watch(u.globalKey(), ch) 236 u.st.pwatcher.Watch(u.globalKey(), ch)
237 defer u.st.pwatcher.Unwatch(u.globalKey(), ch) 237 defer u.st.pwatcher.Unwatch(u.globalKey(), ch)
238 for i := 0; i < 2; i++ { 238 for i := 0; i < 2; i++ {
239 select { 239 select {
240 case change := <-ch: 240 case change := <-ch:
241 if change.Alive { 241 if change.Alive {
242 return nil 242 return nil
243 } 243 }
244 case <-time.After(timeout): 244 case <-time.After(timeout):
245 return fmt.Errorf("still not alive after timeout") 245 return fmt.Errorf("still not alive after timeout")
246 » » case <-u.st.pwatcher.Dying(): 246 » » case <-u.st.pwatcher.Dead():
247 return u.st.pwatcher.Err() 247 return u.st.pwatcher.Err()
248 } 248 }
249 } 249 }
250 panic(fmt.Sprintf("presence reported dead status twice in a row for unit %q", u)) 250 panic(fmt.Sprintf("presence reported dead status twice in a row for unit %q", u))
251 } 251 }
252 252
253 // SetAgentAlive signals that the agent for unit u is alive.· 253 // SetAgentAlive signals that the agent for unit u is alive.·
254 // It returns the started pinger. 254 // It returns the started pinger.
255 func (u *Unit) SetAgentAlive() (*presence.Pinger, error) { 255 func (u *Unit) SetAgentAlive() (*presence.Pinger, error) {
256 p := presence.NewPinger(u.st.presence, u.globalKey()) 256 p := presence.NewPinger(u.st.presence, u.globalKey())
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 467 }
468 468
469 // Config returns the configuration node for the unit. 469 // Config returns the configuration node for the unit.
470 func (u *Unit) Config() (config *ConfigNode, err error) { 470 func (u *Unit) Config() (config *ConfigNode, err error) {
471 config, err = readConfigNode(u.st, u.globalKey()) 471 config, err = readConfigNode(u.st, u.globalKey())
472 if err != nil { 472 if err != nil {
473 return nil, fmt.Errorf("cannot get configuration of unit %q: %v" , u, err) 473 return nil, fmt.Errorf("cannot get configuration of unit %q: %v" , u, err)
474 } 474 }
475 return config, nil 475 return config, nil
476 } 476 }
OLDNEW
« no previous file with comments | « mstate/presence/presence_test.go ('k') | mstate/watcher.go » ('j') | no next file with comments »

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