mirror of
https://github.com/moby/moby.git
synced 2026-07-19 05:50:57 +00:00
Relevant changes; - swarmkit#2681 Handle an edge case in CA rotation where we reclaim CA service from an external CA - swarmkit#2750 Use gometalinter; switch from x/net/context -> context Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
57 lines
967 B
Go
57 lines
967 B
Go
package watchapi
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sync"
|
|
|
|
"github.com/docker/swarmkit/manager/state/store"
|
|
)
|
|
|
|
var (
|
|
errAlreadyRunning = errors.New("broker is already running")
|
|
errNotRunning = errors.New("broker is not running")
|
|
)
|
|
|
|
// Server is the store API gRPC server.
|
|
type Server struct {
|
|
store *store.MemoryStore
|
|
mu sync.Mutex
|
|
pctx context.Context
|
|
cancelAll func()
|
|
}
|
|
|
|
// NewServer creates a store API server.
|
|
func NewServer(store *store.MemoryStore) *Server {
|
|
return &Server{
|
|
store: store,
|
|
}
|
|
}
|
|
|
|
// Start starts the watch server.
|
|
func (s *Server) Start(ctx context.Context) error {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
if s.cancelAll != nil {
|
|
return errAlreadyRunning
|
|
}
|
|
|
|
s.pctx, s.cancelAll = context.WithCancel(ctx)
|
|
return nil
|
|
}
|
|
|
|
// Stop stops the watch server.
|
|
func (s *Server) Stop() error {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
if s.cancelAll == nil {
|
|
return errNotRunning
|
|
}
|
|
s.cancelAll()
|
|
s.cancelAll = nil
|
|
|
|
return nil
|
|
}
|