本文整理汇总了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
})
}