cluster

package
v0.0.0-...-3d1c771 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BROADCAST = -1
	BUFF_SIZE = 10000
)

Variables

This section is empty.

Functions

func Close

func Close(cserver *CServer, debug bool)

Used to shutdown a server

func Count

func Count() int

Get count of existing servers

func Exists

func Exists(pid int, debug bool) bool

Check if server exists

func Serialize

func Serialize(envelope *Envelope) string

Serialization of Envelope object to send over the network

Types

type CServer

type CServer struct {
	CSPid        int
	CSPeers      []int
	ChannelIn    chan *Envelope
	ChannelOut   chan *Envelope
	ChannelClose chan bool
	Address      string
}

Structure of the Server object

func New

func New(pid int, config string, debug bool) *CServer

Start a server with a json config file It also starts two go routines to handle the incoming and outgoing traffic for the server

func (*CServer) Inbox

func (cserver *CServer) Inbox() chan *Envelope

Implements the Inbox() function

func (*CServer) Outbox

func (cserver *CServer) Outbox() chan *Envelope

Implements the Outbox() function

func (*CServer) Peers

func (cserver *CServer) Peers() []int

Implements the Peers() function

func (*CServer) Pid

func (cserver *CServer) Pid() int

Implementes the Pid() function

type Envelope

type Envelope struct {
	// On the sender side, Pid identifies the receiving peer. If instead, Pid is
	// set to cluster.BROADCAST, the message is sent to all peers. On the receiver side, the
	// Id is always set to the original sender. If the Id is not found, the message is silently dropped
	Pid int

	// An id that globally and uniquely identifies the message, meant for duplicate detection at
	// higher levels. It is opaque to this package.
	MsgId int64

	// the actual message.
	Msg interface{}
}

func DeSerialize

func DeSerialize(s string) *Envelope

Deserialization of the Envelope object after receiving from network

type PidServer

type PidServer struct {
	Pid    int
	Server *CServer
}

type Server

type Server interface {
	// Id of this server
	Pid() int

	// array of other servers' ids in the same cluster
	Peers() []int

	// the channel to use to send messages to other peers
	// Note that there are no guarantees of message delivery, and messages
	// are silently dropped
	Outbox() chan *Envelope

	// the channel to receive messages from other peers.
	Inbox() chan *Envelope
}

Jump to

Keyboard shortcuts

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