core

package
v0.6.992 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2019 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package core provides components useful for containing and retrieving entities, i.e. Sources, using a defined strategy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer

type Balancer struct {
	Strategy
	// contains filtered or unexported fields
}

Balancer distributes work to set of sources, using a particular strategy. The zero value of the Balancer is ready to use and safe to be used by multiple gorountines.

func (*Balancer) Del

func (b *Balancer) Del(ss ...Source)

Del removes ss from the list of sources stored by the balancer.

func (*Balancer) Do

func (b *Balancer) Do(f func(Source))

Do executes f on each source stored in the balancer.

func (*Balancer) Get

func (b *Balancer) Get(ctx context.Context, blacklist ...Source) (Source, error)

Get returns a Source from the balancer's source list using the predefined Strategy. If no Strategy was provided, Get returns a Source using RoundRobin.

func (*Balancer) Len

func (b *Balancer) Len() int

Len reports the size of the set of sources stored in the balancer.

func (*Balancer) Put

func (b *Balancer) Put(ss ...Source)

Put adds ss as sources to the current balancer ring. If ss.len() == 0, Put silently returns, otherwise it constracts a Ring with the provided sources. If the balancer has already a ring, pointing lets say to 0, it adds the ring at position -1, preserving the balancer's ring position. If the balancer does not have a ring yet, the new ring will be used, making it point to the first source provided in the list.

type Dialer

type Dialer interface {
	// DialContext dials connections with address using the specified network.
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

Dialer is a wrapper around the DialContext function.

type Ring

type Ring struct {
	*ring.Ring
}

Ring is a proxy struct around a container/ring. It forces to use Source as Value instead of bare interface{}.

func NewRing

func NewRing(n int) *Ring

NewRing creates a new ring with size n.

func NewRingSources

func NewRingSources(ss ...Source) *Ring

func (*Ring) Do

func (r *Ring) Do(f func(Source))

Do executes f on each value of the ring.

func (r *Ring) Link(s *Ring) *Ring

func (*Ring) Next

func (r *Ring) Next() *Ring

func (*Ring) Prev

func (r *Ring) Prev() *Ring

func (*Ring) Set

func (r *Ring) Set(s Source)

Set sets the Value of the ring at this position to s.

func (*Ring) Source

func (r *Ring) Source() Source

Source retrives the Value of the ring at this position.

func (r *Ring) Unlink(n int) *Ring

type Source

type Source interface {
	Dialer

	// ID uniquely identifies a source.
	ID() string

	// Tells the receiver to cleanup and close all connections.
	Close() error
}

Source represents an entity that is able to provide network connections and keep a set of metrics regarding the operations that is performing, or has performed.

func RoundRobin

func RoundRobin(ctx context.Context, r *Ring) (Source, error)

RoundRobin is a naive strategy that iterates and returns each element contained in r.

type Strategy

type Strategy func(ctx context.Context, r *Ring) (Source, error)

Strategy chooses a source from a ring of sources.

Jump to

Keyboard shortcuts

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