notifier

package
v0.0.0-...-977965f Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PolicyTypeDaily specify the policy type is "daily"
	PolicyTypeDaily = "daily"
	// PolicyTypeNone specify the policy type is "none"
	PolicyTypeNone = "none"
)
View Source
const (
	// ScanAllPolicyTopic is for notifying the change of scanning all policy.
	ScanAllPolicyTopic = common.ScanAllPolicy
)

Define global topic names

Variables

This section is empty.

Functions

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()

func WatchConfigChanges

func WatchConfigChanges(cfg map[string]interface{}) error

WatchConfigChanges is used to watch the configuration changes. 监听前端配置的变化

Types

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.
	// 检测 handler 是否为有状态的,如果是。这些 handler 不会并行的去执行。
	IsStateful() bool
}

NotificationHandler defines what operations a notification handler should have.

type NotificationWatcher

type NotificationWatcher struct {
	// For handle concurrent scenario.
	*sync.RWMutex
	// 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. 监控发布的事件,如果此事件与注册在 handlers 中的事件相匹配,触发此事件的 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.

type ScanPolicyNotification

type ScanPolicyNotification struct {
	// Type is used to keep the scan policy type: "none","daily" and "refresh".
	Type string

	// DailyTime is used when the type is 'daily', the offset with UTC time 00:00.
	DailyTime int64
}

ScanPolicyNotification is defined for pass the policy change data.

type ScanPolicyNotificationHandler

type ScanPolicyNotificationHandler struct{}

ScanPolicyNotificationHandler is defined to handle the changes of scanning policy.

func (*ScanPolicyNotificationHandler) Handle

func (s *ScanPolicyNotificationHandler) Handle(value interface{}) error

Handle the policy change notification.

func (*ScanPolicyNotificationHandler) IsStateful

func (s *ScanPolicyNotificationHandler) IsStateful() bool

IsStateful to indicate this handler is stateful.

Jump to

Keyboard shortcuts

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