Skip to content

Commit

Permalink
Merge pull request #32 from mavenugo/master
Browse files Browse the repository at this point in the history
Added Disconnected Notification to the clients
  • Loading branch information
mavenugo committed Feb 19, 2015
2 parents 555a561 + 523a16b commit 58cf012
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
15 changes: 12 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type NotificationHandler interface {

// RFC 7047 section 4.1.11 Echo Notification
Echo([]interface{})

Disconnected(*OvsdbClient)
}

// RFC 7047 : Section 4.1.6 : Echo
Expand Down Expand Up @@ -174,9 +176,9 @@ func (ovs OvsdbClient) Transact(database string, operation ...Operation) ([]Oper
args := NewTransactArgs(database, operation...)
err := ovs.rpcClient.Call("transact", args, &reply)
if err != nil {
log.Fatal("transact failure", err)
return nil, err
}
return reply, err
return reply, nil
}

// Convenience method to monitor every table/column
Expand Down Expand Up @@ -231,7 +233,14 @@ func getTableUpdatesFromRawUnmarshal(raw map[string]map[string]RowUpdate) TableU
}

func clearConnection(c *rpc2.Client) {
connections[c] = nil
if _, ok := connections[c]; ok {
for _, handler := range connections[c].handlers {
if handler != nil {
handler.Disconnected(connections[c])
}
}
}
delete(connections, c)
}

func handleDisconnectNotification(c *rpc2.Client) {
Expand Down
3 changes: 3 additions & 0 deletions example/play_with_ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func play(ovs *libovsdb.OvsdbClient) {
name := newRow.Fields["name"].(string)
if name == "stop" {
fmt.Println("Bridge stop detected : ", uuid)
ovs.Disconnect()
quit <- true
}
}
Expand Down Expand Up @@ -160,3 +161,5 @@ func (n Notifier) Stolen([]interface{}) {
}
func (n Notifier) Echo([]interface{}) {
}
func (n Notifier) Disconnected(client *libovsdb.OvsdbClient) {
}
2 changes: 2 additions & 0 deletions ovs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ func (n Notifier) Stolen([]interface{}) {
func (n Notifier) Echo([]interface{}) {
n.echoChan <- true
}
func (n Notifier) Disconnected(client *OvsdbClient) {
}

func TestDBSchemaValidation(t *testing.T) {

Expand Down

0 comments on commit 58cf012

Please sign in to comment.