本文整理汇总了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
}
}
}
}
开发者ID:Pankov404,项目名称:juju,代码行数:24,代码来源:firewaller.go
示例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)
//.........这里部分代码省略.........
开发者ID:chrisjohnston,项目名称:juju,代码行数:101,代码来源:storageprovisioner.go
注:本文中的github.com/juju/juju/api/watcher.StringsWatcher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论