~fwereade/juju-core/uniter-relations-firmer-sketch

« back to all changes in this revision

Viewing changes to worker/uniter/relationer.go

  • Committer: William Reade
  • Date: 2012-10-11 14:28:47 UTC
  • Revision ID: fwereade@gmail.com-20121011142847-uos31ggk3hhu2i15
decent relations sketch?

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
// NewRelationer creates a new Relationer. The unit will not join the
21
21
// relation until explicitly requested.
22
 
func NewRelationer(ru *state.RelationUnit, dir *relation.StateDir, hooks chan<- hook.Info) *Relationer {
23
 
        return &Relationer{
 
22
func NewRelationer(ru *state.RelationUnit, dir *relation.StateDir, hooks chan<- hook.Info) (*Relationer, error) {
 
23
        r := &Relationer{
24
24
                ctx:   NewContextRelation(ru, dir.State().Members),
25
25
                ru:    ru,
26
26
                dir:   dir,
27
27
                hooks: hooks,
28
 
        }
 
28
                dying: ru.Relation().Life() == state.Dying,
 
29
        }
 
30
        if err := r.Join(); err != nil {
 
31
                return nil, err
 
32
        }
 
33
        return r, nil
29
34
}
30
35
 
31
36
// Context returns the ContextRelation associated with r.
50
55
// and that the only hooks it should send henceforth are -departed hooks,
51
56
// until the relation is empty, followed by a -broken hook.
52
57
func (r *Relationer) SetDying() error {
 
58
        if r.dying {
 
59
                return nil
 
60
        }
53
61
        if r.queue != nil {
54
62
                if err := r.StopHooks(); err != nil {
55
63
                        return err