本文整理匯總了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
}