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

move global dispatcher to extension package

parent 38ca186a
No related branches found
No related tags found
No related merge requests found
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package extension
import (
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/common/observer"
)
var globalEventDispatcher observer.EventDispatcher
var initEventListeners []observer.EventListener
var (
dispatchers = make(map[string]func() observer.EventDispatcher, 8)
)
// SetEventDispatcher by name
func SetEventDispatcher(name string, v func() observer.EventDispatcher) {
dispatchers[name] = v
}
// SetAndInitGlobalDispatcher
func SetAndInitGlobalDispatcher(name string) {
if len(name) == 0 {
name = "direct"
}
if globalEventDispatcher != nil {
logger.Warnf("EventDispatcher already init. It will be replaced")
}
if dp, ok := dispatchers[name]; !ok || dp == nil {
panic("EventDispatcher for " + name + " is not existing, make sure you have import the package.")
}
globalEventDispatcher = dispatchers[name]()
globalEventDispatcher.AddEventListeners(initEventListeners)
}
// GetGlobalDispatcher
func GetGlobalDispatcher() observer.EventDispatcher {
return globalEventDispatcher
}
// AddEventListener it will be added in global event dispatcher
func AddEventListener(listener observer.EventListener) {
initEventListeners = append(initEventListeners, listener)
}
......@@ -22,12 +22,13 @@ import (
)
import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/common/observer"
)
func init() {
observer.SetEventDispatcher("direct", NewDirectEventDispatcher)
extension.SetEventDispatcher("direct", NewDirectEventDispatcher)
}
// DirectEventDispatcher is align with DirectEventDispatcher interface in Java.
......
......@@ -17,14 +17,6 @@
package observer
import (
"github.com/apache/dubbo-go/common/logger"
)
var globalEventDispatcher EventDispatcher
var allEventListeners []EventListener
// EventDispatcher is align with EventDispatcher interface in Java.
// it's the top abstraction
// Align with 2.7.5
......@@ -33,37 +25,3 @@ type EventDispatcher interface {
// Dispatch event
Dispatch(event Event)
}
var (
dispatchers = make(map[string]func() EventDispatcher, 8)
)
// SetEventDispatcher by name
func SetEventDispatcher(name string, v func() EventDispatcher) {
dispatchers[name] = v
}
// SetAndInitGlobalDispatcher
func SetAndInitGlobalDispatcher(name string) {
if len(name) == 0 {
name = "direct"
}
if globalEventDispatcher != nil {
logger.Warnf("EventDispatcher already init. It will be replaced")
}
if dp, ok := dispatchers[name]; !ok || dp == nil {
panic("EventDispatcher for " + name + " is not existing, make sure you have import the package.")
}
globalEventDispatcher = dispatchers[name]()
globalEventDispatcher.AddEventListeners(allEventListeners)
}
// GetGlobalDispatcher
func GetGlobalDispatcher() EventDispatcher {
return globalEventDispatcher
}
// AddEventListener it will be added in global event dispatcher
func AddEventListener(listener EventListener) {
allEventListeners = append(allEventListeners, listener)
}
......@@ -33,7 +33,6 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/common/observer"
_ "github.com/apache/dubbo-go/common/observer/dispatcher"
)
......@@ -102,7 +101,7 @@ func Load() {
eventDispatcherType = providerConfig.eventDispatcherType
}
// init EventDispatcher should before everything
observer.SetAndInitGlobalDispatcher(eventDispatcherType)
extension.SetAndInitGlobalDispatcher(eventDispatcherType)
// reference config
if consumerConfig == nil {
......
......@@ -26,10 +26,6 @@ import (
"github.com/apache/dubbo-go/common/observer/event"
)
func init() {
observer.AddEventListener(&ServiceInstancesChangedListener{})
}
// TODO (implement ConditionalEventListener)
type ServiceInstancesChangedListener struct {
observer.EventListener
......
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