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 ¶
const ( OP_NONE = iota OP_OPEN OP_CLOSE OP_LOCK OP_UNLOCK OP_GET OP_SET OP_INCR )
Variables ¶
var Counter *int64
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 MainServer ¶
func MainServer(server string)
MainServer is the main entry point of this package. It spawns TCP listener and core goroutines
func MonitoringServer ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a client connection
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.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is the main TCP server, 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 (*LockArea) RemoveClient ¶
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 Replier ¶
type Replier interface {
Reply(*MessageReply)
}
Replier represents a client that can process a reply message
type ResultJson ¶
type ResultJson struct {
Tps int64
}