Skip to content
Snippets Groups Projects
Commit b30bea64 authored by Patrick's avatar Patrick
Browse files

Merge remote-tracking branch 'upstream/feature/dubbo-2.7.5' into align-2.7.5

# Conflicts:
#	common/observer/event_listener.go
#	registry/event.go
#	registry/service_discovery.go
parent 045f7f54
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ const (
TOKEN_KEY = "token"
LOCAL_ADDR = "local-addr"
REMOTE_ADDR = "remote-addr"
PATH_SEPARATOR = "/"
DUBBO_KEY = "dubbo"
RELEASE_KEY = "release"
ANYHOST_KEY = "anyhost"
......
......@@ -36,31 +36,31 @@ type Event interface {
GetTimestamp() time.Time
}
// baseEvent is the base implementation of Event
// BaseEvent is the base implementation of Event
// You should never use it directly
type BaseEvent struct {
source interface{}
timestamp time.Time
Source interface{}
Timestamp time.Time
}
// GetSource return the source
func (b *BaseEvent) GetSource() interface{} {
return b.source
return b.Source
}
// GetTimestamp return the timestamp when the event is created
// GetTimestamp return the Timestamp when the event is created
func (b *BaseEvent) GetTimestamp() time.Time {
return b.timestamp
return b.Timestamp
}
// String return a human readable string representing this event
func (b *BaseEvent) String() string {
return fmt.Sprintf("baseEvent[source = %#v]", b.source)
return fmt.Sprintf("BaseEvent[source = %#v]", b.Source)
}
func newBaseEvent(source interface{}) *BaseEvent {
return &BaseEvent{
source: source,
timestamp: time.Now(),
Source: source,
Timestamp: time.Now(),
}
}
......@@ -19,6 +19,7 @@ package registry
import (
"fmt"
"github.com/apache/dubbo-go/common/observer"
"math/rand"
"time"
)
......@@ -47,40 +48,26 @@ func (e ServiceEvent) String() string {
return fmt.Sprintf("ServiceEvent{Action{%s}, Path{%s}}", e.Action, e.Service)
}
// Event is align with Event interface in Java.
// it's the top abstraction
// Align with 2.7.5
type Event interface {
fmt.Stringer
GetSource() interface{}
GetTimestamp() time.Time
// ServiceInstancesChangedEvent represents service instances make some changing
type ServiceInstancesChangedEvent struct {
observer.BaseEvent
ServiceName string
Instances []ServiceInstance
}
// baseEvent is the base implementation of Event
// You should never use it directly
type baseEvent struct {
source interface{}
timestamp time.Time
// String return the description of the event
func (s *ServiceInstancesChangedEvent) String() string {
return fmt.Sprintf("ServiceInstancesChangedEvent[source=%s]", s.ServiceName)
}
// GetSource return the source
func (b *baseEvent) GetSource() interface{} {
return b.source
}
// GetTimestamp return the timestamp when the event is created
func (b *baseEvent) GetTimestamp() time.Time {
return b.timestamp
}
// String return a human readable string representing this event
func (b *baseEvent) String() string {
return fmt.Sprintf("baseEvent[source = %#v]", b.source)
}
func newBaseEvent(source interface{}) *baseEvent {
return &baseEvent{
source: source,
timestamp: time.Now(),
// NewServiceInstancesChangedEvent will create the ServiceInstanceChangedEvent instance
func NewServiceInstancesChangedEvent(serviceName string, instances []ServiceInstance) *ServiceInstancesChangedEvent {
return &ServiceInstancesChangedEvent{
BaseEvent: observer.BaseEvent{
Source: serviceName,
Timestamp: time.Now(),
},
ServiceName: serviceName,
Instances: instances,
}
}
......@@ -16,3 +16,29 @@
*/
package registry
import (
"reflect"
)
import (
"github.com/apache/dubbo-go/common/observer"
)
// TODO (implement ConditionalEventListener)
type ServiceInstancesChangedListener struct {
ServiceName string
observer.EventListener
}
func (sicl *ServiceInstancesChangedListener) OnEvent(e observer.Event) error {
return nil
}
func (sicl *ServiceInstancesChangedListener) GetPriority() int {
return -1
}
func (sicl *ServiceInstancesChangedListener) GetEventType() reflect.Type {
return reflect.TypeOf(&ServiceInstancesChangedEvent{})
}
......@@ -26,12 +26,6 @@ import (
gxpage "github.com/dubbogo/gost/page"
)
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/observer/event"
eventlistener "github.com/apache/dubbo-go/registry/listener"
)
const DefaultPageSize = 100
type ServiceDiscovery interface {
......@@ -79,7 +73,7 @@ type ServiceDiscovery interface {
// ----------------- event ----------------------
// AddListener adds a new ServiceInstancesChangedListener
// see addServiceInstancesChangedListener in Java
AddListener(listener *eventlistener.ServiceInstancesChangedListener) error
AddListener(listener *ServiceInstancesChangedListener) error
// DispatchEventByServiceName dispatches the ServiceInstancesChangedEvent to service instance whose name is serviceName
DispatchEventByServiceName(serviceName string) error
......@@ -88,5 +82,5 @@ type ServiceDiscovery interface {
DispatchEventForInstances(serviceName string, instances []ServiceInstance) error
// DispatchEvent dispatches the event
DispatchEvent(event *event.ServiceInstancesChangedEvent) error
DispatchEvent(event *ServiceInstancesChangedEvent) error
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment