asdisc

package
v0.0.0-...-c29916c Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2015 License: BSD-2-Clause Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultEtcdAddresses used when no custom *etcd.Client is given
	DefaultEtcdAddresses = []string{`http://localhost:2379`}

	// DefaultClusterPrefix is using geertjohan.net to avoid collision. Chances are tiny anyone else will use this key.
	DefaultClusterPrefix = `/geertjohan.net/aerospike-discovery/default`

	// DefaultLogger discards logs
	DefaultLogger = log.New(ioutil.Discard, ``, 0)

	// DefaultAnnouncerConfig is used by NewAnnouncer when no custom *AnnouncerConfig is given.
	DefaultAnnouncerConfig = &AnnouncerConfig{
		TTL:      60,
		Interval: 45,
	}

	// DefaultWatcherConfig is used by NewWatcher when no custom *WatcherConfig is given
	DefaultWatcherConfig = &WatcherConfig{}
)
View Source
var (
	// ErrWatcherClosed is returned by (*Watcher).Next() when the Watcher was closed.
	ErrWatcherClosed = errors.New("watcher is closed")
)

Functions

This section is empty.

Types

type Announcement

type Announcement struct {
	Key         string `json:"-"`
	IP          string `json:"ip"`
	ServicePort uint16 `json:"servicePort"`
	MeshPort    uint16 `json:"meshPort"`
}

Announcement contains information about a single node in an Aerospike cluster. The Announcement is marshalled to json and stored in etcd.

type Announcer

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

Announcer announces a node at regular intervals.

func NewAnnouncer

func NewAnnouncer(announcement *Announcement, config *AnnouncerConfig) (*Announcer, error)

NewAnnouncer starts and returns a new Announcer instance. When AnnouncerConfig is nil, DefaultAnnouncerConfig is used. An announcer announces a single aerospike node at regular intervals, for this a goroutine is started. Use the Stop method to stop announcing.

func (*Announcer) Stop

func (a *Announcer) Stop()

Stop stops the announcer. This also removes the announcement from etcd. It is safe to call Stop multiple times.

type AnnouncerConfig

type AnnouncerConfig struct {
	// EtcdClient to use in announcement calls.
	// When nil, a new client with address http://localhost:2379 is used.
	// An etcd.Client should only be used once as it is not goroutine safe.
	EtcdClient *etcd.Client

	// ClusterPrefix to use in the etcd keys
	ClusterPrefix string

	// TTL and Interval for the announcement
	TTL      uint64
	Interval uint64

	// Logger for debug/info logs.
	// When nil, logs are discarded.
	Logger *log.Logger
}

AnnouncerConfig can be used to modify the Announcer behaviour.

type Watcher

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

Watcher watches aerospike-discovery announcements. The creator must either continiously receive from the Announcements channel or close the Watcher.

func NewWatcher

func NewWatcher(config *WatcherConfig) *Watcher

NewWatcher starts a new watcher. The config argument can be nil, in which case DefaultWatcherConfig will be used. Read all announcements and their updates by calling the Next() method.

func (*Watcher) Close

func (w *Watcher) Close()

Close stops the watcher

func (*Watcher) Next

func (w *Watcher) Next() (*Announcement, error)

Next gives a new announcement or an update to an announcement that was returned by Next() earlier. When an error occurred during watching, that error is returned. When the Watcher was closed, ErrWatcherClosed is returned.

type WatcherConfig

type WatcherConfig struct {
	// EtcdClient for Get and Watch calls. When nil a new etcd.Client is created with DefaultEtcdAddress as path.
	EtcdClient *etcd.Client

	// ClusterPrefix used in the etcd keys. DefaultClusterPrefix is used when empty.
	ClusterPrefix string

	// Logger to send info/debug logs on. When nil the DefaultLogger is used.
	Logger *log.Logger
}

WatcherConfig can be used to pass custom settings to NewWatcher

Jump to

Keyboard shortcuts

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