當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Connection.GetW方法代碼示例

本文整理匯總了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
		}
	}
}
開發者ID:eval01-tts,項目名稱:serviced,代碼行數:36,代碼來源:servicestate.go

示例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
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:28,代碼來源:registry.go

示例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
}
開發者ID:eval01-tts,項目名稱:serviced,代碼行數:31,代碼來源:pool.go


注:本文中的github.com/control-center/serviced/coordinator/client.Connection.GetW方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。