observer

package
v1.5.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEvent

type BaseEvent struct {
	Source    interface{}
	Timestamp time.Time
}

BaseEvent is the base implementation of Event You should never use it directly

func NewBaseEvent

func NewBaseEvent(source interface{}) *BaseEvent

NewBaseEvent create an BaseEvent instance and the Timestamp will be current timestamp

func (*BaseEvent) GetSource

func (b *BaseEvent) GetSource() interface{}

GetSource return the source

func (*BaseEvent) GetTimestamp

func (b *BaseEvent) GetTimestamp() time.Time

GetTimestamp return the Timestamp when the event is created

func (*BaseEvent) String

func (b *BaseEvent) String() string

String return a human readable string representing this event

type BaseListener

type BaseListener struct {
	Listenable
	ListenersCache map[reflect.Type][]EventListener
	Mutex          sync.RWMutex
}

BaseListener base listenable

func NewBaseListener

func NewBaseListener() BaseListener

NewBaseListener a constructor of base listenable

func (*BaseListener) AddEventListener

func (bl *BaseListener) AddEventListener(listener EventListener)

AddEventListener add event listener

func (*BaseListener) AddEventListeners

func (bl *BaseListener) AddEventListeners(listenersSlice []EventListener)

AddEventListeners add the slice of event listener

func (*BaseListener) GetAllEventListeners

func (bl *BaseListener) GetAllEventListeners() []EventListener

GetAllEventListeners get all listener using RLock

func (*BaseListener) RemoveAllEventListeners

func (bl *BaseListener) RemoveAllEventListeners()

RemoveAllEventListeners remove all using Lock

func (*BaseListener) RemoveEventListener

func (bl *BaseListener) RemoveEventListener(listener EventListener)

RemoveEventListener remove the event listener

func (*BaseListener) RemoveEventListeners

func (bl *BaseListener) RemoveEventListeners(listenersSlice []EventListener)

RemoveEventListeners remove the slice of event listener it will iterate all listener and remove it one by one

type ChangedNotify

type ChangedNotify interface {
	Notify(e Event)
}

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 Event

type Event interface {
	fmt.Stringer
	GetSource() interface{}
	GetTimestamp() time.Time
}

Event is align with Event interface in Java. it's the top abstraction Align with 2.7.5

type EventDispatcher

type EventDispatcher interface {
	Listenable
	// Dispatch event
	Dispatch(event Event)
}

EventDispatcher is align with EventDispatcher interface in Java. it's the top abstraction Align with 2.7.5

type EventListener

type EventListener interface {
	gxsort.Prioritizer
	// OnEvent handle this event
	OnEvent(e Event) error
	// GetEventType listen which event type
	GetEventType() reflect.Type
}

EventListener is an new interface used to align with dubbo 2.7.5 It contains the Prioritized means that the listener has its priority Usually the priority of your custom implementation should be between [100, 9000] the number outside the range will be though as system reserve number usually implementation should be singleton

type Listenable

type Listenable interface {
	AddEventListener(listener EventListener)
	AddEventListeners(listenersSlice []EventListener)
	RemoveEventListener(listener EventListener)
	RemoveEventListeners(listenersSlice []EventListener)
	GetAllEventListeners() []EventListener
	RemoveAllEventListeners()
}

Listenable could add and remove the event listener

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL