Skip to content
Snippets Groups Projects
service_discovery_event.go 3.91 KiB
Newer Older
Patrick's avatar
Patrick committed
/*
 * 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 common

import (
	"github.com/apache/dubbo-go/common/observer"
	"github.com/apache/dubbo-go/registry"
)

type ServiceDiscoveryEvent struct {
	observer.BaseEvent
	original registry.ServiceDiscovery
}

func NewServiceDiscoveryEvent(discovery registry.ServiceDiscovery, original registry.ServiceDiscovery) *ServiceDiscoveryEvent {
Patrick's avatar
Patrick committed
	return &ServiceDiscoveryEvent{
		BaseEvent: *observer.NewBaseEvent(discovery),
		original:  original,
	}
}

func (sde *ServiceDiscoveryEvent) GetServiceDiscovery() registry.ServiceDiscovery {
	return sde.GetSource().(registry.ServiceDiscovery)
}

func (sde *ServiceDiscoveryEvent) GetOriginal() registry.ServiceDiscovery {
	return sde.original
}

// ServiceDiscoveryDestroyingEvent
// this event will be dispatched before service discovery be destroyed
type ServiceDiscoveryDestroyingEvent struct {
	ServiceDiscoveryEvent
}
Patrick's avatar
Patrick committed

// ServiceDiscoveryExceptionEvent
// this event will be dispatched when the error occur in service discovery
type ServiceDiscoveryExceptionEvent struct {
	ServiceDiscoveryEvent
	err error
}
Patrick's avatar
Patrick committed

// ServiceDiscoveryInitializedEvent
// this event will be dispatched after service discovery initialize
type ServiceDiscoveryInitializedEvent struct {
	ServiceDiscoveryEvent
}
Patrick's avatar
Patrick committed

// ServiceDiscoveryInitializingEvent
// this event will be dispatched before service discovery initialize
type ServiceDiscoveryInitializingEvent struct {
	ServiceDiscoveryEvent
}
Patrick's avatar
Patrick committed

// ServiceDiscoveryDestroyedEvent
// this event will be dispatched after service discovery be destroyed
type ServiceDiscoveryDestroyedEvent struct {
	ServiceDiscoveryEvent
}
Patrick's avatar
Patrick committed

// NewServiceDiscoveryDestroyingEvent create a ServiceDiscoveryDestroyingEvent
func NewServiceDiscoveryDestroyingEvent(discovery registry.ServiceDiscovery, original registry.ServiceDiscovery) *ServiceDiscoveryDestroyingEvent {
	return &ServiceDiscoveryDestroyingEvent{*NewServiceDiscoveryEvent(discovery, original)}
Patrick's avatar
Patrick committed
}

// NewServiceDiscoveryExceptionEvent create a ServiceDiscoveryExceptionEvent
func NewServiceDiscoveryExceptionEvent(discovery registry.ServiceDiscovery, original registry.ServiceDiscovery, err error) *ServiceDiscoveryExceptionEvent {
	return &ServiceDiscoveryExceptionEvent{*NewServiceDiscoveryEvent(discovery, original), err}
Patrick's avatar
Patrick committed
}

// NewServiceDiscoveryInitializedEvent create a ServiceDiscoveryInitializedEvent
func NewServiceDiscoveryInitializedEvent(discovery registry.ServiceDiscovery, original registry.ServiceDiscovery) *ServiceDiscoveryInitializedEvent {
	return &ServiceDiscoveryInitializedEvent{*NewServiceDiscoveryEvent(discovery, original)}
Patrick's avatar
Patrick committed
}

// NewServiceDiscoveryInitializingEvent create a ServiceDiscoveryInitializingEvent
func NewServiceDiscoveryInitializingEvent(discovery registry.ServiceDiscovery, original registry.ServiceDiscovery) *ServiceDiscoveryInitializingEvent {
	return &ServiceDiscoveryInitializingEvent{*NewServiceDiscoveryEvent(discovery, original)}
Patrick's avatar
Patrick committed
}

// NewServiceDiscoveryDestroyedEvent create a ServiceDiscoveryDestroyedEvent
func NewServiceDiscoveryDestroyedEvent(discovery registry.ServiceDiscovery, original registry.ServiceDiscovery) *ServiceDiscoveryDestroyedEvent {
	return &ServiceDiscoveryDestroyedEvent{*NewServiceDiscoveryEvent(discovery, original)}
Patrick's avatar
Patrick committed
}