lockservice

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: 2 Imported by: 0

Documentation

Overview

Package lockservice implements the lockserver functions.

Index

Constants

View Source
const (
	ErrFileacquired        = Error("file already acquired")
	ErrCantReleaseFile     = Error("file cannot be released, wasn't locked before")
	ErrUnauthorizedAccess  = Error("file cannot be released, unauthorized access")
	ErrCheckAcquireFailure = Error("file is not acquired")
	ErrFileUnlocked        = Error("file doesn't have a lock")
)

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 CheckAcquireRes

type CheckAcquireRes struct {
	Owner string `json:"owner"`
}

CheckAcquireRes is the response of a Checkacquire.

type Descriptors

type Descriptors interface {
	ID() string
	Owner() string
}

Descriptors describe the type of data that a lock acquiring component must describe.

type Error

type Error string

Error provides constant error strings to the driver functions.

func (Error) Error

func (e Error) Error() string

type LockCheckRequest

type LockCheckRequest struct {
	FileID string `json:"fileID"`
}

LockCheckRequest is an instance of a lock check request.

type LockDescriptor

type LockDescriptor struct {
	FileID string
	UserID string
}

LockDescriptor implements the Descriptors interface. Many descriptors can be added to this struct and the ID can be a combination of all those descriptors.

func NewLockDescriptor

func NewLockDescriptor(FileID, UserID string) *LockDescriptor

NewLockDescriptor returns an instance of the LockDescriptor.

func (*LockDescriptor) ID

func (sd *LockDescriptor) ID() string

ID represents the distinguishable ID of the descriptor.

func (*LockDescriptor) Owner

func (sd *LockDescriptor) Owner() string

Owner represents the distinguishable ID of the entity that holds the lock for FileID.

type LockRequest

type LockRequest struct {
	FileID string `json:"fileID"`
	UserID string `json:"userID"`
}

LockRequest is an instance of a request for a lock.

type LockService

type LockService interface {
	// Acquire allows the service to set a lock on the given descriptors.
	// An error is generated if the same isn't possible for any reason,
	// including already existing locks on the descriptor.
	Acquire(Descriptors) error
	// Release allows the service to release the lock on the given descriptors.
	// An error is generated if the same isn't possible for any reason,
	// including releasing locks on non-acquired descriptors.
	Release(Descriptors) error
	// CheckAcquired checks whether a lock has been acquired on the given descriptor.
	// The function returns true if the lock has been acquired on the component.
	// It also returns the owner of the lock on query.
	CheckAcquired(Descriptors) (string, bool)
	// CheckReleased checks whether a lock has been released (or not acquired) on the
	// given component. Returns true if there are no locks on the descriptor.
	CheckReleased(Descriptors) bool
}

LockService describes a lock service component that enables maintaining a set of locks. This service is a standalone component that can be implemented on any server component, distributed or not.

type Object

type Object interface {
	ID() string
}

Object describes any object that can be used with the lockservice.

type ObjectDescriptor

type ObjectDescriptor struct {
	ObjectID string
}

ObjectDescriptor describes the object that is subjected to lock operations.

func NewObjectDescriptor

func NewObjectDescriptor(ObjectID string) *ObjectDescriptor

NewObjectDescriptor returns an instance of the ObjectDescriptor.

func (*ObjectDescriptor) ID

func (od *ObjectDescriptor) ID() string

ID returns the ID related to the object.

type SafeLockMap

type SafeLockMap struct {
	LockMap map[string]string
	Mutex   sync.Mutex
}

SafeLockMap is the lockserver's data structure

type SimpleConfig

type SimpleConfig struct {
	IPAddr   string
	PortAddr string
}

SimpleConfig implements Config.

func NewSimpleConfig

func NewSimpleConfig(IPAddr, PortAddr string) *SimpleConfig

NewSimpleConfig returns an instance of the SimpleConfig.

func (*SimpleConfig) IP

func (scfg *SimpleConfig) IP() string

IP returns the IP from the SimpleConfig.

func (*SimpleConfig) Port

func (scfg *SimpleConfig) Port() string

Port returns the port from SimpleConfig.

type SimpleLockService

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

SimpleLockService is a lock service that implements LockService. It uses a golang map to maintain the locks of the descriptors. It can acquire and release locks and has an in-built logger.

func NewSimpleLockService

func NewSimpleLockService(log zerolog.Logger) *SimpleLockService

NewSimpleLockService creates and returns a new lock service ready to use.

func (*SimpleLockService) Acquire

func (ls *SimpleLockService) Acquire(sd Descriptors) error

Acquire function lets a client acquire a lock on an object.

func (*SimpleLockService) CheckAcquired

func (ls *SimpleLockService) CheckAcquired(sd Descriptors) (string, bool)

CheckAcquired returns true if the file is Acquired. It also returns the owner of the file.

func (*SimpleLockService) CheckReleased

func (ls *SimpleLockService) CheckReleased(sd Descriptors) bool

CheckReleased returns true if the file is released

func (*SimpleLockService) Release

func (ls *SimpleLockService) Release(sd Descriptors) error

Release lets a client to release a lock on an object.

Directories

Path Synopsis
Package node will be responsible for maintaining all the code with respect to a single node.
Package node will be responsible for maintaining all the code with respect to a single node.

Jump to

Keyboard shortcuts

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