event

package
v1.5.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package event manages events via a simple pub / sub mechanism. Events could be created by vic components or registered Collectors.

Basic Overview

The Event Manager provides basic pub / sub functionality. A subscription consists of a topic (any defined Event), a subscription name (string) and a callback function. When an event is published the event manager will determine the event type and check to see if any components have registered a callback for that event type. For all subscriptions the event manager will facilitate the callback. Publication of events can be accomplished by any component that has a pointer to the event manager or via the registered collectors.

Collectors are responsible for collecting events or data from external systems and then publishing relevant vic events to the event manager. In theory the collector could monitor anything and when certain criteria are meet publish vic events to the manager. Collectors are registered with the event manager which instructs the collector where to publish. Multiple collectors are allowed per event manager, but each collector has a single publish target.

An example of a collector is the vSphere Event Collector which uses the vSphere EventHistoryCollector to monitor the vSphere event stream and publish relevant events to vic. In the initial implementation the vSphere Event Collector is focused on a subset of VM Events that are then transformed to vic Events and published to the event manager.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventManager

type EventManager interface {

	// RegisterCollector a collector with the manager
	RegisterCollector(collector.Collector)

	// Collectors returns registered collectors
	Collectors() map[string]collector.Collector

	// Subscribe for event callbacks
	Subscribe(eventTopic string, caller string, callback func(events.Event)) Subscriber

	// Unsubscribe from event callbacks
	Unsubscribe(eventTopic string, caller string)

	// Subscribers will return the subscriber map
	Subscribers() map[string]map[string]Subscriber

	// Subscribed returns subscriber count
	Subscribed() int

	// Publish the event to the subscribers
	Publish(e events.Event)
}

EventManager will provide a basic event pub/sub implementation

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewEventManager

func NewEventManager(collectors ...collector.Collector) *Manager

func (*Manager) Collectors

func (mgr *Manager) Collectors() map[string]collector.Collector

func (*Manager) Publish

func (mgr *Manager) Publish(e events.Event)

Publish events to subscribers

func (*Manager) RegisterCollector

func (mgr *Manager) RegisterCollector(collector collector.Collector)

func (*Manager) Subscribe

func (mgr *Manager) Subscribe(eventTopic string, caller string, callback func(events.Event)) Subscriber

Subscribe to the event manager for callback

func (*Manager) Subscribed

func (mgr *Manager) Subscribed() int

RegistryCount returns the callback count

func (*Manager) Subscribers

func (mgr *Manager) Subscribers() map[string]map[string]Subscriber

func (*Manager) Unsubscribe

func (mgr *Manager) Unsubscribe(eventTopic string, caller string)

Unsubscribe from callbacks

type Subscriber

type Subscriber interface {
	// Topic returns the topic this subscriber is subscribed to
	Topic() string
	// Name returns the name of the subscriber
	Name() string

	// Suspend suspends processing events by the subscriber. If
	// queueEvents is true, the events are queued until Resume()
	// is called. If queueEvents is false, events passed into
	// onEvent() after this call are discarded.
	Suspend(queueEvents bool)
	// Resume resumes processing of events by the subscriber.
	// If Suspend() was called with queueEvents as true, any events
	// that were passed to onEvent() after Suspend() returned are
	// processed first.
	Resume()
	// IsSuspended returns true if the subscriber is suspended.
	IsSuspended() bool

	// Discarded returns the number of packets that were discarded by
	// the subscriber as a result of Pause() being called with
	// queueEvents as false.
	Discarded() uint64
	// Dropped returns the number of packets that were dropped when
	// the event queue overflows. This only happens when Pause()
	// is called with queueEvents as true.
	Dropped() uint64
	// contains filtered or unexported methods
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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