本文整理匯總了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)
}
示例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
}
示例3: CleanGraph
func CleanGraph(g *graph.Graph) {
g.Lock()
defer g.Unlock()
hostname, _ := os.Hostname()
g.DelHostGraph(hostname)
}