client

package
Version: v0.0.0-...-0e8e39a Latest Latest
Warning

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

Go to latest
Published: May 15, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotReady = errors.New("client not ready")

ErrNotReady is the error returned by client.Ready when the client is not ready.

View Source
var TimeNowInMillis = func() int64 { return time.Now().UnixNano() / int64(time.Millisecond) }

TimeNowInMillis returns current time in milliseconds.

Functions

func MetadataFromCallOptions

func MetadataFromCallOptions(opts ...CallOption) metadata.MD

MetadataFromCallOptions creates gRPC metadata from call options.

Types

type CallOption

type CallOption func(*callOptions)

CallOption adds an option to a method call.

func WithBarrier

func WithBarrier() CallOption

WithBarrier is used to block a call until all preceding have been applied to the Raft Cluster.

func WithTTL

func WithTTL(d time.Duration) CallOption

WithTTL is used to set the element's TTL.

func WithWaitingBarrier

func WithWaitingBarrier(d time.Duration) CallOption

WithWaitingBarrier is used to block a call until all preceding have been applied to the Raft Cluster. An optional timeout limits the amount of time we wait for the command to be started.

type Client

type Client interface {
	// Queue returns a Queue with the name n.
	Queue(n string) Queue

	// Dictionary returns a Dictionary with the name n.
	Dictionary(n string) Dictionary

	// Mutex returns a Mutex with the name n.
	Mutex(n string) Mutex

	// State returns a channel which reports the Client state changes.
	State() StateChan
}

Client defines Stoa client methods.

func New

func New(ctx context.Context, opts ...Option) (Client, error)

New creates and returns a new Client instance.

type Collection

type Collection interface {

	// Name returns the Collection name
	Name() string

	// Size returns the collection size
	Size(ctx context.Context, opts ...CallOption) (uint32, error)

	// Clear clears the collection
	Clear(ctx context.Context, opts ...CallOption) error
}

Collection is a generic collection

type Dictionary

type Dictionary interface {
	Collection

	// Put puts a new key-value pair into the dictionary.
	// If the key already exists overwrites the existing value with the new one.
	// Returns the previous value associated with key, or nil if there was no mapping
	// for key.
	Put(ctx context.Context, k, v []byte, opts ...CallOption) ([]byte, error)

	// PutIfAbsent puts the key-value pair (and returns true)
	// only if the key is absent, otherwise it returns false.
	PutIfAbsent(ctx context.Context, k, v []byte, opts ...CallOption) (bool, error)

	// Get returns the value specified by the key if the key-value pair is
	// present, othervise returns nil.
	Get(ctx context.Context, k []byte, opts ...CallOption) ([]byte, error)

	// Remove removes the key-value pair specified by the key k from the map
	// if it is present.
	Remove(ctx context.Context, k []byte, opts ...CallOption) error

	// Range returns the channel kv that will send all key-value pairs containing in
	// the dictionary.
	Range(ctx context.Context, opts ...CallOption) (kv <-chan [][]byte, err <-chan error)
}

Dictionary represents a collection of key-value pairs.

type Mutex

type Mutex interface {
	// TryLock tries to lock the Mutex. Returns true on success, otherwise
	// returns false.
	TryLock(ctx context.Context, payload []byte, opts ...CallOption) (bool, []byte, error)

	// Unlock tries to unlock the Mutex. Returns true if the locked Mutex was
	// unlocked, otherwise returns false.
	Unlock(ctx context.Context, opts ...CallOption) (bool, []byte, error)
}

Mutex is a mutual exclusion lock.

type Option

type Option func(*client)

Option is a function applied to an options to change the options' default values.

func WithBootstrap

func WithBootstrap(v string) Option

WithBootstrap sets the Cluster peers to connect to.

func WithCallOptions

func WithCallOptions(v ...grpc.CallOption) Option

WithCallOptions sets gRPC call options.

func WithDialTimeout

func WithDialTimeout(v time.Duration) Option

WithDialTimeout changes the default gRPC dial timeout.

func WithFailFast

func WithFailFast(v bool) Option

WithFailFast enables or disables (disabled by default) the Client's fail fast option. If enabled the Client does not retry unsuccessful Cluster calls.

func WithID

func WithID(v []byte) Option

WithID sets the Client's ID, generated by default.

func WithIdleStrategy

func WithIdleStrategy(v cc.IdleStrategy) Option

WithIdleStrategy sets the Client's idle stratege.

func WithKeepAlivePeriod

func WithKeepAlivePeriod(v time.Duration) Option

WithKeepAlivePeriod sets the Client's gRPC keep alive period.

func WithLoggerName

func WithLoggerName(v string) Option

WithLoggerName sets the Client's logger name.

func WithLoggingLevel

func WithLoggingLevel(v string) Option

WithLoggingLevel sets the Client's logging level.

func WithPingPeriod

func WithPingPeriod(v time.Duration) Option

WithPingPeriod sets the period between ping messages sent by the Client to the Cluster.

func WithRetryTimeout

func WithRetryTimeout(v time.Duration) Option

WithRetryTimeout defines the timeout to retry the call to the Cluster within.

type Queue

type Queue interface {
	Collection

	// Offer inserts the element e into the queue
	Offer(ctx context.Context, e []byte, opts ...CallOption) error

	// Poll retrieves and removes the head of the queue; returns nil if the queue is empty
	Poll(ctx context.Context, opts ...CallOption) ([]byte, error)

	// Peek retrieves, but does not remove, the head of the queue; returns nil if the queue is empty
	Peek(ctx context.Context, opts ...CallOption) ([]byte, error)
}

Queue defines ordered in FIFO manner collection of elements which may contain duplicates

type State

type State int

State is the Client's state.

const (
	// Connecting is the state returned when the Client is connecting to the Cluster.
	Connecting State = iota + 100
	// Connected is the state returned when the Client is connected to the Cluster.
	Connected
)

func (State) String

func (s State) String() string

type StateChan

type StateChan = <-chan State

StateChan returns the Client's state.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL