mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed 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
|
|
|
|
https://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 events
|
|
|
|
import (
|
|
"github.com/hanzozt/zt/v2/controller/event"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (self *Dispatcher) AddClusterEventHandler(handler event.ClusterEventHandler) {
|
|
self.clusterEventHandlers.Append(handler)
|
|
}
|
|
|
|
func (self *Dispatcher) RemoveClusterEventHandler(handler event.ClusterEventHandler) {
|
|
self.clusterEventHandlers.Delete(handler)
|
|
}
|
|
|
|
func (self *Dispatcher) AcceptClusterEvent(event *event.ClusterEvent) {
|
|
event.EventSrcId = self.ctrlId
|
|
go func() {
|
|
for _, handler := range self.clusterEventHandlers.Value() {
|
|
handler.AcceptClusterEvent(event)
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (self *Dispatcher) registerClusterEventHandler(_ string, val interface{}, _ map[string]interface{}) error {
|
|
handler, ok := val.(event.ClusterEventHandler)
|
|
|
|
if !ok {
|
|
return errors.Errorf("type %v doesn't implement the event.ClusterEventHandler interface", val)
|
|
}
|
|
|
|
self.clusterEventHandlers.Append(handler)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (self *Dispatcher) unregisterClusterEventHandler(val interface{}) {
|
|
if handler, ok := val.(event.ClusterEventHandler); ok {
|
|
self.RemoveClusterEventHandler(handler)
|
|
}
|
|
}
|