serfer

package
v0.0.0-...-49e565d Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2015 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

README

serfer GoDoc Build Status Coverage Status

Serfer is a simple abstraction over Serf event handling

Documentation

Overview

Serfer is a simple library which provides interfaces for handling various Serf events.

This allows for an encapsulation of more complex event processing logic by using separate event handlers based on event type.

Index

Constants

View Source
const (
	// StatusReap is used to update the status of a node if we
	// are handling a EventMemberReap
	StatusReap = serf.MemberStatus(-1)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventHandler

type EventHandler interface {
	HandleEvent(serf.Event)
}

EventHandler processes generic Serf events. Depending on the event type, more processing may be needed.

type IsLeaderFunc

type IsLeaderFunc func() bool

IsLeaderFunc should return true if the local node is the cluster leader.

type MemberEventHandler

type MemberEventHandler interface {
	HandleMemberEvent(serf.MemberEvent)
}

MemberEventHandler handles membership change events.

type QueryEventHandler

type QueryEventHandler interface {
	HandleQueryEvent(serf.Query)
}

QueryEventHandler handles Serf query events.

type Reconciler

type Reconciler interface {
	Reconcile(serf.Member)
}

Reconciler is used to reconcile Serf events wilth an external process, like Raft.

type SerfEventHandler

type SerfEventHandler struct {

	// ServicePrefix is used to filter out unknown events.
	ServicePrefix string

	// ReconcileOnJoin determines if the Reconiler is called when a node joins the cluster.
	ReconcileOnJoin bool

	// ReconcileOnLeave determines if the Reconiler is called when a node leaves the cluster.
	ReconcileOnLeave bool

	// ReconcileOnFail determines if the Reconiler is called when a node fails.
	ReconcileOnFail bool

	// ReconcileOnUpdate determines if the Reconiler is called when a node updates.
	ReconcileOnUpdate bool

	// ReconcileOnReap determines if the Reconiler is called when a node is reaped from the cluster.
	ReconcileOnReap bool

	// IsLeader determines if the local node is the cluster leader.
	IsLeader IsLeaderFunc

	// IsLeaderEventFunc determines if an event is a leader election event based on the event name.
	IsLeaderEvent func(string) bool

	// LeaderElectionHandler processes leader election events.
	LeaderElectionHandler UserEventHandler

	// UserEvent processes known, non-leader election events.
	UserEvent UserEventHandler

	// UnknownEventHandler processes unkown events.
	UnknownEventHandler UserEventHandler

	// Called when a Member joins the cluster.
	NodeJoined MemberEventHandler

	// Called when a Member leaves the cluster by sending a leave message.
	NodeLeft MemberEventHandler

	// Called when a Member has been detected as failed.
	NodeFailed MemberEventHandler

	// Called when a Member has been Readed from the cluster.
	NodeReaped MemberEventHandler

	// Called when a Member has been updated.
	NodeUpdated MemberEventHandler

	// Called when a membership event occurs.
	Reconciler Reconciler

	// Called when a serf.Query is received.
	QueryHandler QueryEventHandler

	// Logs output
	Logger log.Logger
}

SerfEventHandler is used to dispatch various Serf events to separate event handlers.

func (SerfEventHandler) HandleEvent

func (s SerfEventHandler) HandleEvent(e serf.Event)

HandleEvent processes a generic Serf event and dispatches it to the appropriate destination.

type Serfer

type Serfer interface {

	// Start starts the serfer goroutine.
	Start()

	// Stop stops all event processing and blocks until finished.
	Stop() error
}

Serfer processes Serf.Events and is meant to be ran in a goroutine.

func NewSerfer

func NewSerfer(c chan serf.Event, handler EventHandler) Serfer

NewSerfer returns a new Serfer implementation that uses the given channel and event handlers.

type UserEventHandler

type UserEventHandler interface {
	HandleUserEvent(serf.UserEvent)
}

UserEventHandler handles user events.

Jump to

Keyboard shortcuts

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