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


Golang Graph.Lock方法代碼示例

本文整理匯總了Golang中github.com/skydive-project/skydive/topology/graph.Graph.Lock方法的典型用法代碼示例。如果您正苦於以下問題:Golang Graph.Lock方法的具體用法?Golang Graph.Lock怎麽用?Golang Graph.Lock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/skydive-project/skydive/topology/graph.Graph的用法示例。


在下文中一共展示了Graph.Lock方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: testCleanup

func testCleanup(t *testing.T, g *graph.Graph, cmds []helper.Cmd, names []string) {
	// cleanup side on the test
	testPassed := false
	onChange := func(ws *websocket.Conn) {
		g.Lock()
		defer g.Unlock()

		if !testPassed {
			clean := true
			for _, name := range names {
				n := g.LookupFirstNode(graph.Metadata{"Name": name})
				if n != nil {
					clean = false
					break
				}
			}

			if clean {
				testPassed = true

				ws.Close()
			}
		}
	}

	testTopology(t, g, cmds, onChange)
	if !testPassed {
		t.Error("test not executed or failed")
	}

	helper.CleanGraph(g)
}
開發者ID:skydive-project,項目名稱:skydive,代碼行數:32,代碼來源:topology_test.go

示例2: processGraphMessage

func processGraphMessage(g *graph.Graph, m []byte) error {
	g.Lock()
	defer g.Unlock()

	var msg shttp.WSMessage
	if err := json.Unmarshal(m, &msg); err != nil {
		return err
	}

	if msg.Namespace != "Graph" {
		return nil
	}

	msgType, obj, err := graph.UnmarshalWSMessage(msg)
	if err != nil {
		return err
	}

	switch msgType {
	case "NodeUpdated":
		n := obj.(*graph.Node)
		node := g.GetNode(n.ID)
		if node != nil {
			g.SetMetadata(node, n.Metadata())
		}
	case "NodeDeleted":
		g.DelNode(obj.(*graph.Node))
	case "NodeAdded":
		n := obj.(*graph.Node)
		if g.GetNode(n.ID) == nil {
			g.AddNode(n)
		}
	case "EdgeUpdated":
		e := obj.(*graph.Edge)
		edge := g.GetEdge(e.ID)
		if edge != nil {
			g.SetMetadata(edge, e.Metadata())
		}
	case "EdgeDeleted":
		g.DelEdge(obj.(*graph.Edge))
	case "EdgeAdded":
		e := obj.(*graph.Edge)
		if g.GetEdge(e.ID) == nil {
			g.AddEdge(e)
		}
	}

	return nil
}
開發者ID:skydive-project,項目名稱:skydive,代碼行數:49,代碼來源:topology_test.go

示例3: CleanGraph

func CleanGraph(g *graph.Graph) {
	g.Lock()
	defer g.Unlock()
	hostname, _ := os.Hostname()
	g.DelHostGraph(hostname)
}
開發者ID:skydive-project,項目名稱:skydive,代碼行數:6,代碼來源:helper.go


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