lockserver

package
v0.0.0-...-74c3b9c Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Lockserver is a small pessimistic locking server. It includes the following primitives:

get: Get an integer value.
set: Set an integer value.
incr: Increment an integer value.
lock: Lock an item.
unlock: Unlock an item.

Index

Examples

Constants

View Source
const (
	OP_NONE = iota
	OP_OPEN
	OP_CLOSE
	OP_LOCK
	OP_UNLOCK
	OP_GET
	OP_SET
	OP_INCR
)

Variables

View Source
var Counter *int64
View Source
var Service = map[string]Operation{
	"lock":   OP_LOCK,
	"unlock": OP_UNLOCK,
	"get":    OP_GET,
	"set":    OP_SET,
	"incr":   OP_INCR,
}

Service is a map to convert an operation name into an enumerate

Functions

func FilterOut

func FilterOut(l *list.List, pred func(e *list.Element) bool)

FilterOut remove from a list all items whose predicate result is true

func MainServer

func MainServer(server string)

MainServer is the main entry point of this package. It spawns TCP listener and core goroutines

func MonitoringServer

func MonitoringServer(ws *websocket.Conn)

Types

type Client

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

Client represents a client connection

func NewClient

func NewClient(con net.Conn, core *Core) (clt *Client)

NewClient construct a Client structure

func (*Client) Reply

func (clt *Client) Reply(r *MessageReply)

Reply is used by the core methods to return a reply to the client

type Core

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

Core is the structure representing the core goroutine, responsible on the logic of the application.

func NewCore

func NewCore() *Core

NewCore builds a Core object

type Listener

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

Listener is the main TCP server, waiting for incoming connections

func (*Listener) Listen

func (ln *Listener) Listen(t string, addr string)

Listen starts the TCP server loop, waiting for incoming connections

type LockArea

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

LockArea is the data structure responsible of tracking who locks what, and what is locked by who.

Example
la := NewLockArea()
c0 := &clt{n: 0}
la.AddClient(c0)

locks := []string{"toto", "tutu", "titi"}
for _, v := range locks {
	la.Add(c0, v)
}

for i, cnum := range []int{10, 1, 3, 2, 6, 7, 5, 4, 9, 8} {
	c := &clt{n: cnum}
	la.AddClient(c)
	la.Add(c, locks[i%len(locks)])
}

for e := la.locks["toto"].Front(); e != nil; e = e.Next() {
	fmt.Println(e.Value.(*clt))
}
Output:

&{0}
&{10}
&{2}
&{5}
&{8}

func NewLockArea

func NewLockArea() *LockArea

NewLockArea builds a new LockArea object

func (*LockArea) Add

func (lo *LockArea) Add(clt Replier, name string) bool

Add must be called to notify a locking event

func (*LockArea) AddClient

func (lo *LockArea) AddClient(clt Replier)

AddClient is called to notify a new client

func (*LockArea) Remove

func (lo *LockArea) Remove(clt Replier, name string) (Replier, bool)

Remove is called to notify an unlock

func (*LockArea) RemoveClient

func (lo *LockArea) RemoveClient(clt Replier) []Replier

Remove client is called to notify a client disconnection. It can be due to a normal disconnection, or a crash.

type MessageQuery

type MessageQuery struct {
	Op     string
	Target string
	Arg    string `json:",omitempty"`
	// contains filtered or unexported fields
}

MessageQuery is the query message structure.

type MessageReply

type MessageReply struct {
	Status string
	Error  string `json:",omitempty"`
	Value  string `json:",omitempty"`
	// contains filtered or unexported fields
}

MessageReply is the reply message structure.

type Operation

type Operation int

Operation is an enumerate listing the operation codes

type Replier

type Replier interface {
	Reply(*MessageReply)
}

Replier represents a client that can process a reply message

type ResultJson

type ResultJson struct {
	Tps int64
}

Jump to

Keyboard shortcuts

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