本文整理匯總了Golang中github.com/control-center/serviced/coordinator/client.Connection.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Connection.Close方法的具體用法?Golang Connection.Close怎麽用?Golang Connection.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/control-center/serviced/coordinator/client.Connection
的用法示例。
在下文中一共展示了Connection.Close方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: monitor
// monitor checks for changes in a path-based connection
func (zconn *zconn) monitor(path string) {
var (
connC chan<- client.Connection
conn client.Connection
err error
)
defer func() {
if conn != nil {
conn.Close()
}
}()
for {
// wait for someone to request a connection, or shutdown
select {
case connC = <-zconn.connC:
case <-zconn.shutdownC:
return
}
retry:
// create a connection if it doesn't exist or ping the existing connection
if conn == nil {
conn, err = zconn.client.GetCustomConnection(path)
if err != nil {
glog.Warningf("Could not obtain a connection to %s: %s", path, err)
}
} else if _, err := conn.Children("/"); err == client.ErrConnectionClosed {
glog.Warningf("Could not ping connection to %s: %s", path, err)
conn = nil
}
// send the connection back
if conn != nil {
connC <- conn
continue
}
// if conn is nil, try to create a new connection
select {
case <-time.After(time.Second):
glog.Infof("Refreshing connection to zookeeper")
goto retry
case <-zconn.shutdownC:
return
}
}
}