v1.8.6-rc1 Latest Latest

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

Go to latest
Published: Nov 15, 2019 License: Apache-2.0 Imports: 7 Imported by: 8




View Source
const (
	// ScanAllPolicyTopic is for notifying the change of scanning all policy.
	ScanAllPolicyTopic = common.ScanAllPolicy

Define global topic names


This section is empty.


func Publish

func Publish(topic string, value interface{}) error

Publish is a wrapper utility method for NotificationWatcher.notify()

func Subscribe

func Subscribe(topic string, handler NotificationHandler) error

Subscribe is a wrapper utility method for NotificationWatcher.handle()

func UnSubscribe

func UnSubscribe(topic string, handler string) error

UnSubscribe is a wrapper utility method for NotificationWatcher.UnHandle()


type HandlerChannel

type HandlerChannel struct {
	// contains filtered or unexported fields

HandlerChannel provides not only the chan itself but also the count of handlers related with this chan.

type HandlerIndexer

type HandlerIndexer map[string]NotificationHandler

HandlerIndexer is setup the relationship between the handler type and instance.

type Notification

type Notification struct {
	// Topic of notification
	// Required
	Topic string

	// Value of notification.
	// Optional
	Value interface{}

Notification wraps the topic and related data value if existing.

type NotificationHandler

type NotificationHandler interface {
	// Handle the event when it coming.
	// value might be optional, it depends on usages.
	Handle(value interface{}) error

	// IsStateful returns whether the handler is stateful or not.
	// If handler is stateful, it will not be triggerred in parallel.
	// Otherwise, the handler will be triggered concurrently if more
	// than one same handler are matched the topics.
	IsStateful() bool

NotificationHandler defines what operations a notification handler should have.

type NotificationWatcher

type NotificationWatcher struct {
	// For handle concurrent scenario.
	// contains filtered or unexported fields

NotificationWatcher is defined to accept the events published by the sender and match it with pre-registered notification handler and then trigger the execution of the found handler.

func NewNotificationWatcher

func NewNotificationWatcher() *NotificationWatcher

NewNotificationWatcher is constructor of NotificationWatcher.

func (*NotificationWatcher) Handle

func (nw *NotificationWatcher) Handle(topic string, handler NotificationHandler) error

Handle the related topic with the specified handler.

func (*NotificationWatcher) Notify

func (nw *NotificationWatcher) Notify(notification Notification) error

Notify that notification is coming.

func (*NotificationWatcher) UnHandle

func (nw *NotificationWatcher) UnHandle(topic string, handler string) error

UnHandle is to revoke the registered handler with the specified topic. 'handler' is optional, the type name of the handler. If it's empty value, then revoke the whole topic, otherwise only revoke the specified handler.

Jump to

Keyboard shortcuts

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