mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
*: add some comments to service Start/Shutdown methods
This commit is contained in:
parent
36d4c17a15
commit
3e2eda6752
8 changed files with 32 additions and 8 deletions
|
@ -67,8 +67,11 @@ type Service interface {
|
||||||
Name() string
|
Name() string
|
||||||
// Start initializes dBFT and starts event loop for consensus service.
|
// Start initializes dBFT and starts event loop for consensus service.
|
||||||
// It must be called only when the sufficient amount of peers are connected.
|
// It must be called only when the sufficient amount of peers are connected.
|
||||||
|
// The service only starts once, subsequent calls to Start are no-op.
|
||||||
Start()
|
Start()
|
||||||
// Shutdown stops dBFT event loop.
|
// Shutdown stops dBFT event loop. It can only be called once, subsequent calls
|
||||||
|
// to Shutdown on the same instance are no-op. The instance that was stopped can
|
||||||
|
// not be started again by calling Start (use a new instance if needed).
|
||||||
Shutdown()
|
Shutdown()
|
||||||
|
|
||||||
// OnPayload is a callback to notify the Service about a newly received payload.
|
// OnPayload is a callback to notify the Service about a newly received payload.
|
||||||
|
|
|
@ -233,7 +233,8 @@ func (s *Server) ID() uint32 {
|
||||||
return s.id
|
return s.id
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start will start the server and its underlying transport.
|
// Start will start the server and its underlying transport. Calling it twice
|
||||||
|
// is an error.
|
||||||
func (s *Server) Start(errChan chan error) {
|
func (s *Server) Start(errChan chan error) {
|
||||||
s.log.Info("node started",
|
s.log.Info("node started",
|
||||||
zap.Uint32("blockHeight", s.chain.BlockHeight()),
|
zap.Uint32("blockHeight", s.chain.BlockHeight()),
|
||||||
|
@ -251,7 +252,8 @@ func (s *Server) Start(errChan chan error) {
|
||||||
s.run()
|
s.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown disconnects all peers and stops listening.
|
// Shutdown disconnects all peers and stops listening. Calling it twice is an error,
|
||||||
|
// once stopped the same intance of the Server can't be started again by calling Start.
|
||||||
func (s *Server) Shutdown() {
|
func (s *Server) Shutdown() {
|
||||||
s.log.Info("shutting down server", zap.Int("peers", s.PeerCount()))
|
s.log.Info("shutting down server", zap.Int("peers", s.PeerCount()))
|
||||||
s.transport.Close()
|
s.transport.Close()
|
||||||
|
|
|
@ -215,6 +215,7 @@ func (s *Server) Name() string {
|
||||||
|
|
||||||
// Start creates a new JSON-RPC server listening on the configured port. It creates
|
// Start creates a new JSON-RPC server listening on the configured port. It creates
|
||||||
// goroutines needed internally and it returns its errors via errChan passed to New().
|
// goroutines needed internally and it returns its errors via errChan passed to New().
|
||||||
|
// The Server only starts once, subsequent calls to Start are no-op.
|
||||||
func (s *Server) Start() {
|
func (s *Server) Start() {
|
||||||
if !s.config.Enabled {
|
if !s.config.Enabled {
|
||||||
s.log.Info("RPC server is not enabled")
|
s.log.Info("RPC server is not enabled")
|
||||||
|
@ -260,7 +261,10 @@ func (s *Server) Start() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown stops the RPC server if it's running.
|
// Shutdown stops the RPC server if it's running. It can only be called once,
|
||||||
|
// subsequent calls to Shutdown on the same instance are no-op. The instance
|
||||||
|
// that was stopped can not be started again by calling Start (use a new
|
||||||
|
// instance if needed).
|
||||||
func (s *Server) Shutdown() {
|
func (s *Server) Shutdown() {
|
||||||
if !s.started.CAS(true, false) {
|
if !s.started.CAS(true, false) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -73,7 +73,8 @@ func (r *RPCBroadcaster) SendParams(params request.RawParams) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown implements oracle.Broadcaster.
|
// Shutdown implements oracle.Broadcaster. The same instance can't be Run again
|
||||||
|
// after the shutdown.
|
||||||
func (r *RPCBroadcaster) Shutdown() {
|
func (r *RPCBroadcaster) Shutdown() {
|
||||||
close(r.close)
|
close(r.close)
|
||||||
<-r.finished
|
<-r.finished
|
||||||
|
|
|
@ -164,6 +164,7 @@ func (n *Notary) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start runs a Notary module in a separate goroutine.
|
// Start runs a Notary module in a separate goroutine.
|
||||||
|
// The Notary only starts once, subsequent calls to Start are no-op.
|
||||||
func (n *Notary) Start() {
|
func (n *Notary) Start() {
|
||||||
if !n.started.CAS(false, true) {
|
if !n.started.CAS(false, true) {
|
||||||
return
|
return
|
||||||
|
@ -211,7 +212,9 @@ drainLoop:
|
||||||
close(n.done)
|
close(n.done)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown stops the Notary module.
|
// Shutdown stops the Notary module. It can only be called once, subsequent calls
|
||||||
|
// to Shutdown on the same instance are no-op. The instance that was stopped can
|
||||||
|
// not be started again by calling Start (use a new instance if needed).
|
||||||
func (n *Notary) Shutdown() {
|
func (n *Notary) Shutdown() {
|
||||||
if !n.started.CAS(true, false) {
|
if !n.started.CAS(true, false) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -181,7 +181,9 @@ func (o *Oracle) Name() string {
|
||||||
return "oracle"
|
return "oracle"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown shutdowns Oracle.
|
// Shutdown shutdowns Oracle. It can only be called once, subsequent calls
|
||||||
|
// to Shutdown on the same instance are no-op. The instance that was stopped can
|
||||||
|
// not be started again by calling Start (use a new instance if needed).
|
||||||
func (o *Oracle) Shutdown() {
|
func (o *Oracle) Shutdown() {
|
||||||
o.respMtx.Lock()
|
o.respMtx.Lock()
|
||||||
defer o.respMtx.Unlock()
|
defer o.respMtx.Unlock()
|
||||||
|
@ -195,6 +197,7 @@ func (o *Oracle) Shutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start runs the oracle service in a separate goroutine.
|
// Start runs the oracle service in a separate goroutine.
|
||||||
|
// The Oracle only starts once, subsequent calls to Start are no-op.
|
||||||
func (o *Oracle) Start() {
|
func (o *Oracle) Start() {
|
||||||
o.respMtx.Lock()
|
o.respMtx.Lock()
|
||||||
if o.running {
|
if o.running {
|
||||||
|
|
|
@ -33,7 +33,12 @@ type (
|
||||||
OnPayload(p *payload.Extensible) error
|
OnPayload(p *payload.Extensible) error
|
||||||
AddSignature(height uint32, validatorIndex int32, sig []byte) error
|
AddSignature(height uint32, validatorIndex int32, sig []byte) error
|
||||||
GetConfig() config.StateRoot
|
GetConfig() config.StateRoot
|
||||||
|
// Start runs service instance in a separate goroutine.
|
||||||
|
// The service only starts once, subsequent calls to Start are no-op.
|
||||||
Start()
|
Start()
|
||||||
|
// Shutdown stops the service. It can only be called once, subsequent calls
|
||||||
|
// to Shutdown on the same instance are no-op. The instance that was stopped can
|
||||||
|
// not be started again by calling Start (use a new instance if needed).
|
||||||
Shutdown()
|
Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ func (s *service) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start runs service instance in a separate goroutine.
|
// Start runs service instance in a separate goroutine.
|
||||||
|
// The service only starts once, subsequent calls to Start are no-op.
|
||||||
func (s *service) Start() {
|
func (s *service) Start() {
|
||||||
if !s.started.CAS(false, true) {
|
if !s.started.CAS(false, true) {
|
||||||
return
|
return
|
||||||
|
@ -63,7 +64,9 @@ drainloop:
|
||||||
close(s.done)
|
close(s.done)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown stops the service.
|
// Shutdown stops the service. It can only be called once, subsequent calls
|
||||||
|
// to Shutdown on the same instance are no-op. The instance that was stopped can
|
||||||
|
// not be started again by calling Start (use a new instance if needed).
|
||||||
func (s *service) Shutdown() {
|
func (s *service) Shutdown() {
|
||||||
if !s.started.CAS(true, false) {
|
if !s.started.CAS(true, false) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue