|
|
|
@ -18,19 +18,31 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
registryInstance = Registry{
|
|
|
|
|
registry = Registry{
|
|
|
|
|
clusters: make(map[string]*cluster),
|
|
|
|
|
}
|
|
|
|
|
connManager = syncx.NewResourceManager()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// A Registry is a registry that manages the etcd client connections.
|
|
|
|
|
type Registry struct {
|
|
|
|
|
clusters map[string]*cluster
|
|
|
|
|
lock sync.Mutex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetRegistry returns a global Registry.
|
|
|
|
|
func GetRegistry() *Registry {
|
|
|
|
|
return ®istryInstance
|
|
|
|
|
return ®istry
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetConn returns an etcd client connection associated with given endpoints.
|
|
|
|
|
func (r *Registry) GetConn(endpoints []string) (EtcdClient, error) {
|
|
|
|
|
return r.getCluster(endpoints).getClient()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Monitor monitors the key on given etcd endpoints, notify with the given UpdateListener.
|
|
|
|
|
func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener) error {
|
|
|
|
|
return r.getCluster(endpoints).monitor(key, l)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Registry) getCluster(endpoints []string) *cluster {
|
|
|
|
@ -46,14 +58,6 @@ func (r *Registry) getCluster(endpoints []string) *cluster {
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Registry) GetConn(endpoints []string) (EtcdClient, error) {
|
|
|
|
|
return r.getCluster(endpoints).getClient()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener) error {
|
|
|
|
|
return r.getCluster(endpoints).monitor(key, l)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type cluster struct {
|
|
|
|
|
endpoints []string
|
|
|
|
|
key string
|
|
|
|
@ -288,6 +292,7 @@ func (c *cluster) watchConnState(cli EtcdClient) {
|
|
|
|
|
watcher.watch(cli.ActiveConnection())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DialClient dials an etcd cluster with given endpoints.
|
|
|
|
|
func DialClient(endpoints []string) (EtcdClient, error) {
|
|
|
|
|
return clientv3.New(clientv3.Config{
|
|
|
|
|
Endpoints: endpoints,
|
|
|
|
|