event

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DummyHeartbeat added in v0.7.0

type DummyHeartbeat struct{}

func (*DummyHeartbeat) Stop added in v0.7.0

func (*DummyHeartbeat) Stop()

Stop does nothing

type Handler

type Handler interface {
	HandleEvent(Type, ...interface{})
}

type Heartbeat added in v0.7.0

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

func NewHeartbeat added in v0.7.0

func NewHeartbeat(interval time.Duration, target Notifiable) *Heartbeat

NewHeartbeat creates a new heartbeat ticker.

On each heartbeat, target.NotifyHeartbeat will be called with the current timestamp. Note that this happens asynchronously from a separate goroutine.

func (*Heartbeat) Stop added in v0.7.0

func (heartbeat *Heartbeat) Stop()

type HeartbeatStopper added in v0.7.0

type HeartbeatStopper interface {
	Stop()
}

type Notifiable

type Notifiable interface {
	// NotifyConnect reports new connections (if connected is positive) or
	// disconnects (if connected is negative).
	//
	// Connects and disconnects should be reported separately.
	NotifyConnect(connected int)
	// NotifyHeartbeat is called periodically when enabled, to allow sending
	// keepalive messages to a monitoring system
	NotifyHeartbeat(when time.Time)
}

Notifiable defines the interface for a notification dispatcher.

Inidividual calls cause state changes, which may trigger events.

type Queue added in v0.10.0

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

Queue encapsulates state for a connection load reporting callback.

The hit/miss pairs define a hysteresis range to avoid "flapping" reports when the number of connections changes quickly around a limit.

func NewQueue added in v0.10.0

func NewQueue(limit int) *Queue

NewQueue creates a new connection load report notifier.

limit specifies the reporting threshold.

func (*Queue) NotifyConnect added in v0.10.0

func (reporter *Queue) NotifyConnect(connected int)

func (*Queue) NotifyHeartbeat added in v0.10.0

func (reporter *Queue) NotifyHeartbeat(when time.Time)

func (*Queue) RegisterEventHandler added in v0.10.0

func (reporter *Queue) RegisterEventHandler(typ Type, handler Handler)

func (*Queue) Shutdown added in v0.10.0

func (reporter *Queue) Shutdown()

Shutdown stops the load reporter and waits for completion.

You must not send any notifications after calling this method.

func (*Queue) Start added in v0.10.0

func (reporter *Queue) Start()

Start launches the reporting goroutine.

To stop the reporter, call Shutdown().

func (*Queue) UnregisterEventHandler added in v0.10.0

func (reporter *Queue) UnregisterEventHandler(typ Type, handler Handler)

type Type added in v0.10.0

type Type int
const (
	TypeLimitHit Type = iota
	TypeLimitMiss
	TypeHeartbeat
)

type UrlHandler

type UrlHandler struct {
	// Url is the parsed URL
	Url *url.URL
	// contains filtered or unexported fields
}

UrlHandler is an event handler that can send GET requests to a preconfigured HTTP URL.

func NewUrlHandler

func NewUrlHandler(urly string, userauth *auth.UserAuthenticator) (*UrlHandler, error)

func (*UrlHandler) HandleEvent

func (handler *UrlHandler) HandleEvent(typ Type, args ...interface{})

Jump to

Keyboard shortcuts

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