discovery.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package discovery
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. var (
  7. // ErrNotSupported is returned when a discovery service is not supported.
  8. ErrNotSupported = errors.New("discovery service not supported")
  9. // ErrNotImplemented is returned when discovery feature is not implemented
  10. // by discovery backend.
  11. ErrNotImplemented = errors.New("not implemented in this discovery service")
  12. )
  13. // Watcher provides watching over a cluster for nodes joining and leaving.
  14. type Watcher interface {
  15. // Watch the discovery for entry changes.
  16. // Returns a channel that will receive changes or an error.
  17. // Providing a non-nil stopCh can be used to stop watching.
  18. Watch(stopCh <-chan struct{}) (<-chan Entries, <-chan error)
  19. }
  20. // Backend is implemented by discovery backends which manage cluster entries.
  21. type Backend interface {
  22. // Watcher must be provided by every backend.
  23. Watcher
  24. // Initialize the discovery with URIs, a heartbeat, a ttl and optional settings.
  25. Initialize(string, time.Duration, time.Duration, map[string]string) error
  26. // Register to the discovery.
  27. Register(string) error
  28. }