本文整理匯總了Golang中github.com/cockroachdb/cockroach/rpc.Server.AddCloseCallback方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.AddCloseCallback方法的具體用法?Golang Server.AddCloseCallback怎麽用?Golang Server.AddCloseCallback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/rpc.Server
的用法示例。
在下文中一共展示了Server.AddCloseCallback方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: start
// start initializes the infostore with the rpc server address and
// then begins processing connecting clients in an infinite select
// loop via goroutine. Periodically, clients connected and awaiting
// the next round of gossip are awoken via the conditional variable.
func (s *server) start(rpcServer *rpc.Server, stopper *stop.Stopper) {
addr := rpcServer.Addr()
s.is.NodeAddr = util.MakeUnresolvedAddr(addr.Network(), addr.String())
if err := rpcServer.Register("Gossip.Gossip", s.Gossip, &Request{}); err != nil {
log.Fatalf("unable to register gossip service with RPC server: %s", err)
}
rpcServer.AddCloseCallback(s.onClose)
updateCallback := func(_ string, _ roachpb.Value) {
// Wakeup all pending clients.
s.ready.Broadcast()
}
unregister := s.is.registerCallback(".*", updateCallback)
stopper.RunWorker(func() {
// Periodically wakeup blocked client gossip requests.
for {
select {
case <-stopper.ShouldStop():
s.stop(unregister)
return
}
}
})
}
示例2: newServer
// newServer creates and returns a server struct.
func newServer(rpcServer *rpc.Server, interval time.Duration) *server {
s := &server{
interval: interval,
is: newInfoStore(rpcServer.Addr()),
incoming: newAddrSet(MaxPeers),
clientAddrMap: make(map[string]net.Addr),
}
rpcServer.RegisterName("Gossip", s)
rpcServer.AddCloseCallback(s.onClose)
s.ready = sync.NewCond(&s.mu)
return s
}
示例3: start
// start initializes the infostore with the rpc server address and
// then begins processing connecting clients in an infinite select
// loop via goroutine. Periodically, clients connected and awaiting
// the next round of gossip are awoken via the conditional variable.
func (s *server) start(rpcServer *rpc.Server) {
s.is.NodeAddr = rpcServer.Addr()
rpcServer.RegisterName("Gossip", s)
rpcServer.AddCloseCallback(s.onClose)
go func() {
// Periodically wakeup blocked client gossip requests.
gossipTimeout := time.Tick(s.jitteredGossipInterval())
for {
select {
case <-gossipTimeout:
// Wakeup all blocked gossip requests.
s.ready.Broadcast()
}
}
}()
}
示例4: start
// start initializes the infostore with the rpc server address and
// then begins processing connecting clients in an infinite select
// loop via goroutine. Periodically, clients connected and awaiting
// the next round of gossip are awoken via the conditional variable.
func (s *server) start(rpcServer *rpc.Server) {
s.is.NodeAddr = rpcServer.Addr()
if err := rpcServer.RegisterName("Gossip", s); err != nil {
log.Fatalf("unable to register gossip service with RPC server: %s", err)
}
rpcServer.AddCloseCallback(s.onClose)
go func() {
// Periodically wakeup blocked client gossip requests.
gossipTimeout := time.Tick(s.jitteredGossipInterval())
for {
select {
case <-gossipTimeout:
// Wakeup all blocked gossip requests.
s.ready.Broadcast()
}
}
}()
}
示例5: start
// start initializes the infostore with the rpc server address and
// then begins processing connecting clients in an infinite select
// loop via goroutine. Periodically, clients connected and awaiting
// the next round of gossip are awoken via the conditional variable.
func (s *server) start(rpcServer *rpc.Server, stopper *stop.Stopper) {
s.is.NodeAddr = rpcServer.Addr()
if err := rpcServer.RegisterName("Gossip", s); err != nil {
log.Fatalf("unable to register gossip service with RPC server: %s", err)
}
rpcServer.AddCloseCallback(s.onClose)
stopper.RunWorker(func() {
// Periodically wakeup blocked client gossip requests.
for {
select {
case <-time.After(s.jitteredGossipInterval()):
// Wakeup all blocked gossip requests.
s.ready.Broadcast()
case <-stopper.ShouldStop():
s.stop()
return
}
}
})
}
示例6: start
// start initializes the infostore with the rpc server address and
// then begins processing connecting clients in an infinite select
// loop via goroutine. Periodically, clients connected and awaiting
// the next round of gossip are awoken via the conditional variable.
func (s *server) start(rpcServer *rpc.Server, addr net.Addr) {
s.is.NodeAddr = util.MakeUnresolvedAddr(addr.Network(), addr.String())
if err := rpcServer.Register("Gossip.Gossip", s.Gossip, &Request{}); err != nil {
log.Fatalf("unable to register gossip service with RPC server: %s", err)
}
rpcServer.AddOpenCallback(s.onOpen)
rpcServer.AddCloseCallback(s.onClose)
updateCallback := func(_ string, _ roachpb.Value) {
// Wakeup all pending clients.
s.ready.Broadcast()
}
unregister := s.is.registerCallback(".*", updateCallback)
s.stopper.RunWorker(func() {
<-s.stopper.ShouldStop()
s.mu.Lock()
defer s.mu.Unlock()
unregister()
s.ready.Broadcast() // wake up clients
})
}