本文整理汇总了Golang中github.com/juju/juju/api/watcher.StringsWatcher类的典型用法代码示例。如果您正苦于以下问题:Golang StringsWatcher类的具体用法?Golang StringsWatcher怎么用?Golang StringsWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringsWatcher类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: watchLoop
// watchLoop watches the machine for units added or removed.
func (md *machineData) watchLoop(unitw apiwatcher.StringsWatcher) {
defer md.tomb.Done()
defer watcher.Stop(unitw, &md.tomb)
for {
select {
case <-md.tomb.Dying():
return
case change, ok := <-unitw.Changes():
if !ok {
_, err := md.machine()
if !params.IsCodeNotFound(err) {
md.fw.tomb.Kill(watcher.EnsureErr(unitw))
}
return
}
select {
case md.fw.unitsChange <- &unitsChange{md, change}:
case <-md.tomb.Dying():
return
}
}
}
}
示例2: loop
func (w *storageprovisioner) loop() error {
var environConfigChanges <-chan struct{}
var volumesWatcher apiwatcher.StringsWatcher
var filesystemsWatcher apiwatcher.StringsWatcher
var volumesChanges <-chan []string
var filesystemsChanges <-chan []string
var volumeAttachmentsWatcher apiwatcher.MachineStorageIdsWatcher
var filesystemAttachmentsWatcher apiwatcher.MachineStorageIdsWatcher
var volumeAttachmentsChanges <-chan []params.MachineStorageId
var filesystemAttachmentsChanges <-chan []params.MachineStorageId
var machineBlockDevicesWatcher apiwatcher.NotifyWatcher
var machineBlockDevicesChanges <-chan struct{}
machineChanges := make(chan names.MachineTag)
environConfigWatcher, err := w.environ.WatchForEnvironConfigChanges()
if err != nil {
return errors.Annotate(err, "watching environ config")
}
defer watcher.Stop(environConfigWatcher, &w.tomb)
environConfigChanges = environConfigWatcher.Changes()
// Machine-scoped provisioners need to watch block devices, to create
// volume-backed filesystems.
if machineTag, ok := w.scope.(names.MachineTag); ok {
machineBlockDevicesWatcher, err = w.volumes.WatchBlockDevices(machineTag)
if err != nil {
return errors.Annotate(err, "watching block devices")
}
defer watcher.Stop(machineBlockDevicesWatcher, &w.tomb)
machineBlockDevicesChanges = machineBlockDevicesWatcher.Changes()
}
// The other watchers are started dynamically; stop only if started.
defer w.maybeStopWatcher(volumesWatcher)
defer w.maybeStopWatcher(volumeAttachmentsWatcher)
defer w.maybeStopWatcher(filesystemsWatcher)
defer w.maybeStopWatcher(filesystemAttachmentsWatcher)
startWatchers := func() error {
var err error
volumesWatcher, err = w.volumes.WatchVolumes()
if err != nil {
return errors.Annotate(err, "watching volumes")
}
filesystemsWatcher, err = w.filesystems.WatchFilesystems()
if err != nil {
return errors.Annotate(err, "watching filesystems")
}
volumeAttachmentsWatcher, err = w.volumes.WatchVolumeAttachments()
if err != nil {
return errors.Annotate(err, "watching volume attachments")
}
filesystemAttachmentsWatcher, err = w.filesystems.WatchFilesystemAttachments()
if err != nil {
return errors.Annotate(err, "watching filesystem attachments")
}
volumesChanges = volumesWatcher.Changes()
filesystemsChanges = filesystemsWatcher.Changes()
volumeAttachmentsChanges = volumeAttachmentsWatcher.Changes()
filesystemAttachmentsChanges = filesystemAttachmentsWatcher.Changes()
return nil
}
ctx := context{
scope: w.scope,
storageDir: w.storageDir,
volumeAccessor: w.volumes,
filesystemAccessor: w.filesystems,
life: w.life,
machineAccessor: w.machines,
statusSetter: w.status,
time: w.clock,
volumes: make(map[names.VolumeTag]storage.Volume),
volumeAttachments: make(map[params.MachineStorageId]storage.VolumeAttachment),
volumeBlockDevices: make(map[names.VolumeTag]storage.BlockDevice),
filesystems: make(map[names.FilesystemTag]storage.Filesystem),
filesystemAttachments: make(map[params.MachineStorageId]storage.FilesystemAttachment),
machines: make(map[names.MachineTag]*machineWatcher),
machineChanges: machineChanges,
schedule: schedule.NewSchedule(w.clock),
pendingVolumeBlockDevices: make(set.Tags),
incompleteVolumeParams: make(map[names.VolumeTag]storage.VolumeParams),
incompleteVolumeAttachmentParams: make(map[params.MachineStorageId]storage.VolumeAttachmentParams),
pendingFilesystems: make(map[names.FilesystemTag]storage.FilesystemParams),
pendingFilesystemAttachments: make(map[params.MachineStorageId]storage.FilesystemAttachmentParams),
pendingDyingFilesystemAttachments: make(map[params.MachineStorageId]storage.FilesystemAttachmentParams),
}
ctx.managedFilesystemSource = newManagedFilesystemSource(
ctx.volumeBlockDevices, ctx.filesystems,
)
defer func() {
for _, w := range ctx.machines {
w.stop()
}
}()
for {
// Check if any pending operations can be fulfilled.
if err := processPending(&ctx); err != nil {
return errors.Trace(err)
//.........这里部分代码省略.........