notifier

package
v1.5.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: Apache-2.0 Imports: 13 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.
	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.

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