OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / go-kit / kit / sd / instancer.go
1 package sd
2
3 // Event represents a push notification generated from the underlying service discovery
4 // implementation. It contains either a full set of available resource instances, or
5 // an error indicating some issue with obtaining information from discovery backend.
6 // Examples of errors may include loosing connection to the discovery backend, or
7 // trying to look up resource instances using an incorrectly formatted key.
8 // After receiving an Event with an error the listenter should treat previously discovered
9 // resource instances as stale (although it may choose to continue using them).
10 // If the Instancer is able to restore connection to the discovery backend it must push
11 // another Event with the current set of resource instances.
12 type Event struct {
13         Instances []string
14         Err       error
15 }
16
17 // Instancer listens to a service discovery system and notifies registered
18 // observers of changes in the resource instances. Every event sent to the channels
19 // contains a complete set of instances known to the Instancer. That complete set is
20 // sent immediately upon registering the channel, and on any future updates from
21 // discovery system.
22 type Instancer interface {
23         Register(chan<- Event)
24         Deregister(chan<- Event)
25         Stop()
26 }
27
28 // FixedInstancer yields a fixed set of instances.
29 type FixedInstancer []string
30
31 // Register implements Instancer.
32 func (d FixedInstancer) Register(ch chan<- Event) { ch <- Event{Instances: d} }
33
34 // Deregister implements Instancer.
35 func (d FixedInstancer) Deregister(ch chan<- Event) {}
36
37 // Stop implements Instancer.
38 func (d FixedInstancer) Stop() {}