Documentation ¶
Index ¶
- Constants
- Variables
- type BaseRegistry
- func (r *BaseRegistry) Destroy()
- func (r *BaseRegistry) Done() chan struct{}
- func (r *BaseRegistry) GetUrl() common.URL
- func (r *BaseRegistry) InitBaseRegistry(url *common.URL, facadeRegistry FacadeBasedRegistry) Registry
- func (r *BaseRegistry) IsAvailable() bool
- func (r *BaseRegistry) Register(conf *common.URL) error
- func (r *BaseRegistry) RestartCallBack() bool
- func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
- func (r *BaseRegistry) UnRegister(conf *common.URL) error
- func (r *BaseRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
- func (r *BaseRegistry) WaitGroup() *sync.WaitGroup
- type ConditionalEventListener
- type DefaultServiceInstance
- func (d *DefaultServiceInstance) GetHost() string
- func (d *DefaultServiceInstance) GetId() string
- func (d *DefaultServiceInstance) GetMetadata() map[string]string
- func (d *DefaultServiceInstance) GetPort() int
- func (d *DefaultServiceInstance) GetServiceName() string
- func (d *DefaultServiceInstance) IsEnable() bool
- func (d *DefaultServiceInstance) IsHealthy() bool
- type Event
- type EventListener
- type FacadeBasedRegistry
- type Listener
- type MockRegistry
- func (r *MockRegistry) Destroy()
- func (r *MockRegistry) GetUrl() common.URL
- func (r *MockRegistry) IsAvailable() bool
- func (r *MockRegistry) MockEvent(event *ServiceEvent)
- func (*MockRegistry) Register(url *common.URL) error
- func (r *MockRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
- func (r *MockRegistry) UnRegister(conf *common.URL) error
- func (r *MockRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
- type NotifyListener
- type Registry
- type ServiceDiscovery
- type ServiceEvent
- type ServiceInstance
- type ServiceInstancesChangedEvent
- type ServiceInstancesChangedListener
Constants ¶
const ( // RegistryConnDelay connection delay RegistryConnDelay = 3 // MaxWaitInterval max wait interval MaxWaitInterval = 3 * time.Second )
const DefaultPageSize = 100
Variables ¶
var (
RegisteredError = errors.New("already registered")
)
Functions ¶
This section is empty.
Types ¶
type BaseRegistry ¶
BaseRegistry is a common logic abstract for registry. It implement Registry interface.
func (*BaseRegistry) Done ¶
func (r *BaseRegistry) Done() chan struct{}
Done open for outside to listen the event of registry Destroy() called.
func (*BaseRegistry) GetUrl ¶
func (r *BaseRegistry) GetUrl() common.URL
GetUrl for get registry's url
func (*BaseRegistry) InitBaseRegistry ¶
func (r *BaseRegistry) InitBaseRegistry(url *common.URL, facadeRegistry FacadeBasedRegistry) Registry
InitBaseRegistry for init some local variables and set BaseRegistry's subclass to it
func (*BaseRegistry) IsAvailable ¶
func (r *BaseRegistry) IsAvailable() bool
IsAvailable judge to is registry not closed by chan r.done
func (*BaseRegistry) Register ¶
func (r *BaseRegistry) Register(conf *common.URL) error
Register implement interface registry to register
func (*BaseRegistry) RestartCallBack ¶
func (r *BaseRegistry) RestartCallBack() bool
RestartCallBack for reregister when reconnect
func (*BaseRegistry) Subscribe ¶
func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
Subscribe :subscribe from registry, event will notify by notifyListener
func (*BaseRegistry) UnRegister ¶
func (r *BaseRegistry) UnRegister(conf *common.URL) error
UnRegister implement interface registry to unregister
func (*BaseRegistry) UnSubscribe ¶
func (r *BaseRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
UnSubscribe URL
func (*BaseRegistry) WaitGroup ¶
func (r *BaseRegistry) WaitGroup() *sync.WaitGroup
WaitGroup open for outside add the waitgroup to add some logic before registry destroyed over(graceful down)
type ConditionalEventListener ¶
type ConditionalEventListener interface { EventListener // Accept will make the decision whether it should handle this event Accept(e Event) bool }
ConditionalEventListener only handle the event which it can handle
type DefaultServiceInstance ¶
type DefaultServiceInstance struct { Id string ServiceName string Host string Port int Enable bool Healthy bool Metadata map[string]string }
DefaultServiceInstance the default implementation of ServiceInstance or change the ServiceInstance to be struct???
func (*DefaultServiceInstance) GetHost ¶
func (d *DefaultServiceInstance) GetHost() string
GetHost will return the hostname
func (*DefaultServiceInstance) GetId ¶
func (d *DefaultServiceInstance) GetId() string
GetId will return this instance's id. It should be unique.
func (*DefaultServiceInstance) GetMetadata ¶
func (d *DefaultServiceInstance) GetMetadata() map[string]string
GetMetadata will return the metadata
func (*DefaultServiceInstance) GetPort ¶
func (d *DefaultServiceInstance) GetPort() int
GetPort will return the port.
func (*DefaultServiceInstance) GetServiceName ¶
func (d *DefaultServiceInstance) GetServiceName() string
GetServiceName will return the serviceName
func (*DefaultServiceInstance) IsEnable ¶
func (d *DefaultServiceInstance) IsEnable() bool
IsEnable will return the enable status of this instance
func (*DefaultServiceInstance) IsHealthy ¶
func (d *DefaultServiceInstance) IsHealthy() bool
IsHealthy will return the value represent the instance whether healthy or not
type EventListener ¶
type EventListener interface { gxsort.Prioritizer // OnEvent handle this event OnEvent(e Event) error }
EventListener is an new interface used to align with dubbo 2.7.5 It contains the Prioritized means that the listener has its priority
type FacadeBasedRegistry ¶
type FacadeBasedRegistry interface { Registry // CreatePath create the path in the registry CreatePath(string) error // DoRegister actually do the register job DoRegister(string, string) error // DoUnregister do the unregister job DoUnregister(string, string) error // DoSubscribe actually subscribe the URL DoSubscribe(conf *common.URL) (Listener, error) // DoUnsubscribe does unsubscribe the URL DoUnsubscribe(conf *common.URL) (Listener, error) // CloseAndNilClient close the client and then reset the client in registry to nil // you should notice that this method will be invoked inside a lock. // So you should implement this method as light weighted as you can. CloseAndNilClient() // CloseListener close listeners CloseListener() // InitListeners init listeners InitListeners() }
* FacadeBasedRegistry interface is subclass of Registry, and it is designed for registry who want to inherit BaseRegistry. * You have to implement the interface to inherit BaseRegistry.
type Listener ¶
type Listener interface { Next() (*ServiceEvent, error) Close() }
Listener Deprecated!
type MockRegistry ¶
type MockRegistry struct {
// contains filtered or unexported fields
}
MockRegistry ...
func (*MockRegistry) MockEvent ¶
func (r *MockRegistry) MockEvent(event *ServiceEvent)
MockEvent ...
func (*MockRegistry) Subscribe ¶
func (r *MockRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
Subscribe ...
func (*MockRegistry) UnRegister ¶
func (r *MockRegistry) UnRegister(conf *common.URL) error
UnRegister
func (*MockRegistry) UnSubscribe ¶
func (r *MockRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
UnSubscribe :
type Registry ¶
type Registry interface { common.Node //used for service provider calling , register services to registry //And it is also used for service consumer calling , register services cared about ,for dubbo's admin monitoring. Register(url *common.URL) error // UnRegister is required to support the contract: // 1. If it is the persistent stored data of dynamic=false, the registration data can not be found, then the IllegalStateException is thrown, otherwise it is ignored. // 2. Unregister according to the full url match. // url Registration information , is not allowed to be empty, e.g: dubbo://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylin UnRegister(url *common.URL) error //Will relace mode1 in dubbogo version v1.1.0 //mode2 : callback mode, subscribe with notify(notify listener). Subscribe(*common.URL, NotifyListener) error // UnSubscribe is required to support the contract: // 1. If don't subscribe, ignore it directly. // 2. Unsubscribe by full URL match. // url Subscription condition, not allowed to be empty, e.g. consumer://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylin // listener A listener of the change event, not allowed to be empty UnSubscribe(*common.URL, NotifyListener) error }
- -----------------------------------NOTICE---------------------------------------------
- If there is no special case, you'd better inherit BaseRegistry and implement the
- FacadeBasedRegistry interface instead of directly implementing the Registry interface.
- --------------------------------------------------------------------------------------
Registry Extension - Registry
type ServiceDiscovery ¶
type ServiceDiscovery interface { fmt.Stringer // Destroy will destroy the service discovery. // If the discovery cannot be destroy, it will return an error. Destroy() error // Register will register an instance of ServiceInstance to registry Register(instance ServiceInstance) error // Update will update the data of the instance in registry Update(instance ServiceInstance) error // Unregister will unregister this instance from registry Unregister(instance ServiceInstance) error // ----------------- discovery ------------------- // GetDefaultPageSize will return the default page size GetDefaultPageSize() int // GetServices will return the all service names. GetServices() *gxset.HashSet // GetInstances will return all service instances with serviceName GetInstances(serviceName string) []ServiceInstance // GetInstancesByPage will return a page containing instances of ServiceInstance with the serviceName // the page will start at offset GetInstancesByPage(serviceName string, offset int, pageSize int) gxpage.Pager // GetHealthyInstancesByPage will return a page containing instances of ServiceInstance. // The param healthy indices that the instance should be healthy or not. // The page will start at offset GetHealthyInstancesByPage(serviceName string, offset int, pageSize int, healthy bool) gxpage.Pager // Batch get all instances by the specified service names GetRequestInstances(serviceNames []string, offset int, requestedSize int) map[string]gxpage.Pager // ----------------- event ---------------------- // AddListener adds a new ServiceInstancesChangedListener // see addServiceInstancesChangedListener in Java AddListener(listener *ServiceInstancesChangedListener) error // DispatchEventByServiceName dispatches the ServiceInstancesChangedEvent to service instance whose name is serviceName DispatchEventByServiceName(serviceName string) error // DispatchEventForInstances dispatches the ServiceInstancesChangedEvent to target instances DispatchEventForInstances(serviceName string, instances []ServiceInstance) error // DispatchEvent dispatches the event DispatchEvent(event *ServiceInstancesChangedEvent) error }
type ServiceEvent ¶
ServiceEvent ...
func (ServiceEvent) String ¶
func (e ServiceEvent) String() string
String return the description of event
type ServiceInstance ¶
type ServiceInstance interface { // GetId will return this instance's id. It should be unique. GetId() string // GetServiceName will return the serviceName GetServiceName() string // GetHost will return the hostname GetHost() string // GetPort will return the port. GetPort() int // IsEnable will return the enable status of this instance IsEnable() bool // IsHealthy will return the value represent the instance whether healthy or not IsHealthy() bool // GetMetadata will return the metadata GetMetadata() map[string]string }
type ServiceInstancesChangedEvent ¶
type ServiceInstancesChangedEvent struct { ServiceName string Instances []ServiceInstance // contains filtered or unexported fields }
ServiceInstancesChangedEvent represents service instances make some changing
func NewServiceInstancesChangedEvent ¶
func NewServiceInstancesChangedEvent(serviceName string, instances []ServiceInstance) *ServiceInstancesChangedEvent
NewServiceInstancesChangedEvent will create the ServiceInstanceChangedEvent instance
func (*ServiceInstancesChangedEvent) GetSource ¶
func (b *ServiceInstancesChangedEvent) GetSource() interface{}
GetSource return the source
func (*ServiceInstancesChangedEvent) GetTimestamp ¶
GetTimestamp return the timestamp when the event is created
func (*ServiceInstancesChangedEvent) String ¶
func (s *ServiceInstancesChangedEvent) String() string
String return the description of the event
type ServiceInstancesChangedListener ¶
type ServiceInstancesChangedListener struct {
ServiceName string
}
TODO (implement ConditionalEventListener)