本文整理匯總了Golang中github.com/juju/juju/api/watcher.NotifyWatcher.Stop方法的典型用法代碼示例。如果您正苦於以下問題:Golang NotifyWatcher.Stop方法的具體用法?Golang NotifyWatcher.Stop怎麽用?Golang NotifyWatcher.Stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/api/watcher.NotifyWatcher
的用法示例。
在下文中一共展示了NotifyWatcher.Stop方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: stopWatcher
func stopWatcher(c *gc.C, w apiwatcher.NotifyWatcher) {
err := w.Stop()
c.Check(err, jc.ErrorIsNil)
}
示例2: loop
func (f *filter) loop(unitTag string) (err error) {
// TODO(dfc) named return value is a time bomb
defer func() {
if params.IsCodeNotFoundOrCodeUnauthorized(err) {
err = worker.ErrTerminateAgent
}
}()
tag, err := names.ParseUnitTag(unitTag)
if err != nil {
return err
}
if f.unit, err = f.st.Unit(tag); err != nil {
return err
}
if err = f.unitChanged(); err != nil {
return err
}
f.service, err = f.unit.Service()
if err != nil {
return err
}
if err = f.serviceChanged(); err != nil {
return err
}
unitw, err := f.unit.Watch()
if err != nil {
return err
}
defer f.maybeStopWatcher(unitw)
servicew, err := f.service.Watch()
if err != nil {
return err
}
defer f.maybeStopWatcher(servicew)
// configw and relationsw can get restarted, so we need to use
// their eventual values in the defer calls.
var configw apiwatcher.NotifyWatcher
var configChanges <-chan struct{}
curl, err := f.unit.CharmURL()
if err == nil {
configw, err = f.unit.WatchConfigSettings()
if err != nil {
return err
}
configChanges = configw.Changes()
f.upgradeFrom.url = curl
} else if err != uniter.ErrNoCharmURLSet {
filterLogger.Errorf("unit charm: %v", err)
return err
}
defer func() {
if configw != nil {
watcher.Stop(configw, &f.tomb)
}
}()
actionsw, err := f.unit.WatchActions()
if err != nil {
return err
}
f.actionsPending = make([]string, 0)
defer func() {
if actionsw != nil {
watcher.Stop(actionsw, &f.tomb)
}
}()
relationsw, err := f.service.WatchRelations()
if err != nil {
return err
}
defer func() {
if relationsw != nil {
watcher.Stop(relationsw, &f.tomb)
}
}()
var addressChanges <-chan struct{}
addressesw, err := f.unit.WatchAddresses()
if err != nil {
return err
}
defer watcher.Stop(addressesw, &f.tomb)
// Config events cannot be meaningfully discarded until one is available;
// once we receive the initial change, we unblock discard requests by
// setting this channel to its namesake on f.
var discardConfig chan struct{}
for {
var ok bool
select {
case <-f.tomb.Dying():
return tomb.ErrDying
// Handle watcher changes.
case _, ok = <-unitw.Changes():
filterLogger.Debugf("got unit change")
if !ok {
return watcher.MustErr(unitw)
}
if err = f.unitChanged(); err != nil {
return err
}
//.........這裏部分代碼省略.........
示例3: loop
func (f *filter) loop(unitTag names.UnitTag) (err error) {
// TODO(dfc) named return value is a time bomb
defer func() {
if params.IsCodeNotFoundOrCodeUnauthorized(err) {
err = worker.ErrTerminateAgent
}
}()
if f.unit, err = f.st.Unit(unitTag); err != nil {
return err
}
if err = f.unitChanged(); err != nil {
return err
}
if err = f.meterStatusChanged(); err != nil {
return err
}
f.service, err = f.unit.Service()
if err != nil {
return err
}
if err = f.serviceChanged(); err != nil {
return err
}
unitw, err := f.unit.Watch()
if err != nil {
return err
}
defer f.maybeStopWatcher(unitw)
servicew, err := f.service.Watch()
if err != nil {
return err
}
defer f.maybeStopWatcher(servicew)
// configw and relationsw can get restarted, so we need to use
// their eventual values in the defer calls.
var configw apiwatcher.NotifyWatcher
var configChanges <-chan struct{}
curl, err := f.unit.CharmURL()
if err == nil {
configw, err = f.unit.WatchConfigSettings()
if err != nil {
return err
}
configChanges = configw.Changes()
f.upgradeFrom.url = curl
} else if err != uniter.ErrNoCharmURLSet {
filterLogger.Errorf("unit charm: %v", err)
return err
}
defer f.maybeStopWatcher(configw)
actionsw, err := f.unit.WatchActionNotifications()
if err != nil {
return err
}
f.actionsPending = make([]string, 0)
defer f.maybeStopWatcher(actionsw)
relationsw, err := f.service.WatchRelations()
if err != nil {
return err
}
defer f.maybeStopWatcher(relationsw)
meterStatusw, err := f.unit.WatchMeterStatus()
if err != nil {
return err
}
defer f.maybeStopWatcher(meterStatusw)
addressesw, err := f.unit.WatchAddresses()
if err != nil {
return err
}
defer watcher.Stop(addressesw, &f.tomb)
storagew, err := f.unit.WatchStorage()
if err != nil {
return err
}
defer watcher.Stop(storagew, &f.tomb)
leaderSettingsw, err := f.st.LeadershipSettings.WatchLeadershipSettings(f.service.Tag().Id())
if err != nil {
return err
}
defer watcher.Stop(leaderSettingsw, &f.tomb)
// Ignore external requests for leader settings behaviour until we see the first change.
var discardLeaderSettings <-chan struct{}
var wantLeaderSettings <-chan bool
// By default we send all leaderSettings onwards.
sendLeaderSettings := true
// Config events cannot be meaningfully discarded until one is available;
// once we receive the initial config and address changes, we unblock
// discard requests by setting this channel to its namesake on f.
var discardConfig chan struct{}
var seenConfigChange bool
var seenAddressChange bool
maybePrepareConfigEvent := func() {
if !seenAddressChange {
filterLogger.Debugf("no address change seen yet, skipping config event")
return
}
if !seenConfigChange {
//.........這裏部分代碼省略.........