lockclient

package
v0.0.0-...-384ce83 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrSessionNonExistent = Error("the session related to this process doesn't exist")
	ErrSessionExpired     = Error("session expired")
)

Constant errors. Rule of thumb, all errors start with a small letter and end with no full stop.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// StartService starts the lockservice Lockey using the given
	// configuration. It provides an appropriate error on failing
	// to do so. Starting the service should be a non-blocking call
	// and return as soon as the server is started and setup.
	StartService(Config) error
	// Connect allows the user process to establish a connection
	// with the client. This returns an ID of the session that
	// results from the connection.
	Connect() session.Session
	// Acquire can be used to acquire a lock on Lockey. This
	// implementation interacts with the underlying server and
	// provides the service.
	Acquire(lockservice.Object, session.Session) error
	// Release can be used to release a lock on Lockey. This
	// implementation interacts with the underlying server and
	// provides the service.
	Release(lockservice.Object, session.Session) error
}

Client describes a client that can be used to interact with the Lockey lockservice. The client can start the lockservice and interact by making calls to it.

The client has the ability to start the lockservice from its in-built function or it can be started separately.

The client allows the user to Acquire a lock and Release a lock, using it's descriptor.

type Config

type Config interface {
	// IP provides the IP address where the server is intended to run.
	IP() string
	// Port provides the port where the server is supposed to run.
	Port() string
}

Config describes the configuration for the lockservice to run on.

type Error

type Error string

Error provides constant error strings to the driver functions.

func (Error) Error

func (e Error) Error() string

type SimpleClient

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

SimpleClient implements Client, the lockclient for LocKey.

func NewSimpleClient

func NewSimpleClient(config *lockservice.SimpleConfig, log zerolog.Logger, cache *cache.LRUCache) *SimpleClient

NewSimpleClient returns a new SimpleClient of the given parameters. This client works with or without the existance of a cache.

func (*SimpleClient) Acquire

func (sc *SimpleClient) Acquire(d lockservice.Object, s session.Session) error

Acquire allows the user process to acquire a lock. This returns a "session expired" error if the session expires when the lock is being acquired.

All locks acquired during the session will be revoked if the session expires.

func (*SimpleClient) CheckAcquire

func (sc *SimpleClient) CheckAcquire(d lockservice.ObjectDescriptor) (string, error)

CheckAcquire checks for acquisition of lock and returns the owner if the lock is already acquired. The errors returned can be due to HTTP errors or marshalling errors. A "file is not acquired" error is returned if so and no error and an owner is returned if the object is acquired.

func (*SimpleClient) Connect

func (sc *SimpleClient) Connect() session.Session

Connect lets the user process to establish a connection with the client.

func (*SimpleClient) Release

func (sc *SimpleClient) Release(d lockservice.Object, s session.Session) error

Release makes an HTTP call to the lockserver and releases the lock. The errors invloved may be due the HTTP errors or the lockservice errors.

Only if there is an active session by the user process, it can release the locks once verified that the locks belong to the user process.

func (*SimpleClient) StartService

func (sc *SimpleClient) StartService(cfg Config) error

StartService starts the lockservice LocKey. This creates a new instance of the service and then starts the server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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