本文整理汇总了Golang中github.com/control-center/serviced/coordinator/client.Connection.GetW方法的典型用法代码示例。如果您正苦于以下问题:Golang Connection.GetW方法的具体用法?Golang Connection.GetW怎么用?Golang Connection.GetW使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/control-center/serviced/coordinator/client.Connection
的用法示例。
在下文中一共展示了Connection.GetW方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: wait
// wait waits for an individual service state to reach its desired state
func wait(shutdown <-chan interface{}, conn client.Connection, serviceID, stateID string, dstate service.DesiredState) error {
for {
var node ServiceStateNode
event, err := conn.GetW(servicepath(serviceID, stateID), &node)
if err == client.ErrNoNode {
// if the node no longer exists, then there is nothing to watch, so we are done
return nil
} else if err != nil {
glog.Errorf("Got an error while looking for %s (%s): %s", stateID, serviceID, err)
return err
}
switch dstate {
case service.SVCStop:
// pass through, because the node needs to be deleted to be considered Stopped
case service.SVCRun, service.SVCRestart:
if node.IsRunning() {
// instance reached the desired state
return nil
}
case service.SVCPause:
if node.IsPaused() {
// instance reached the desired state
return nil
}
}
// wait for something to change on the node or shutdown
select {
case <-event:
case <-shutdown:
return zzk.ErrShutdown
}
}
}
示例2: watchItem
func (r *registryType) watchItem(conn client.Connection, path string, nodeType client.Node, cancel <-chan bool, processNode func(conn client.Connection,
node client.Node), errorHandler WatchError) error {
exists, err := zzk.PathExists(conn, path)
if err != nil {
return err
}
if !exists {
return client.ErrNoNode
}
for {
event, err := conn.GetW(path, nodeType)
if err != nil {
glog.Errorf("Could not watch %s: %s", path, err)
defer errorHandler(path, err)
return err
}
processNode(conn, nodeType)
//This blocks until a change happens under the key
select {
case ev := <-event:
glog.V(2).Infof("watch event %+v at path: %s", ev, path)
case <-cancel:
return nil
}
}
return nil
}
示例3: MonitorResourcePool
func MonitorResourcePool(shutdown <-chan interface{}, conn client.Connection, poolID string) <-chan *pool.ResourcePool {
monitor := make(chan *pool.ResourcePool)
go func() {
defer close(monitor)
if err := zzk.Ready(shutdown, conn, poolpath(poolID)); err != nil {
glog.V(2).Infof("Could not watch pool %s: %s", poolID, err)
return
}
for {
var node PoolNode
event, err := conn.GetW(poolpath(poolID), &node)
if err != nil {
glog.V(2).Infof("Could not get pool %s: %s", poolID, err)
return
}
select {
case monitor <- node.ResourcePool:
case <-shutdown:
return
}
select {
case <-event:
case <-shutdown:
return
}
}
}()
return monitor
}