util

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

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

Go to latest
Published: Jul 7, 2015 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KGlogLevel          = 3
	KConnTimeoutSeconds = 3
)
View Source
const (
	ReadOK = iota
	ReadError

	ReadTimeOut
	KReplyStatSendSuc
	KReplyStatSendTimeOut
	KReplyStatPingTimeOut
	KReplyStatPongTimeOut
)
View Source
const (
	StateChangeEventType  = "stateChange"
	LeaderChangeEventType = "leaderChange"
	TermChangeEventType   = "termChange"
	CommitEventType       = "commit"
	AddPeerEventType      = "addPeer"
	RemovePeerEventType   = "removePeer"

	HeartbeatIntervalEventType        = "heartbeatInterval"
	ElectionTimeoutThresholdEventType = "electionTimeoutThreshold"

	HeartbeatEventType = "heartbeat"
)

Variables

This section is empty.

Functions

func AppName

func AppName() string

func BytesToUint32

func BytesToUint32(buf []byte) uint32

func GetListener

func GetListener(ipPort string) net.Listener

func GoDone

func GoDone(num int, fun GoFun)

func GoMustBeLaunch

func GoMustBeLaunch(fun GoLaunchFun, args ...interface{})

func GoSelect

func GoSelect(num int, fun GoSelectFun, goCall bool, c chan interface{})

func IsBigEndian

func IsBigEndian() bool

func Json2Ojb

func Json2Ojb(jsonStr string, data interface{}) bool

func JsonStrEuqal

func JsonStrEuqal(str1, str2 string) bool

func ListenerEnableTLS

func ListenerEnableTLS(listener net.Listener, tlsCfg *TlsCfg) net.Listener

func Map2Struct

func Map2Struct(data interface{}, obj interface{}) error

Struct Att MUST be CanSet. Big prefix

func Obj2Json

func Obj2Json(obj interface{}, pretty bool) string

func PoolSetByte

func PoolSetByte(orgBytes []byte)

func RandInt

func RandInt(max int) uint32

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

Struct Att MUST be CanSet. Big prefix

func Uint32InBytes

func Uint32InBytes(v uint32, b []byte)

func Uint32ToBytes

func Uint32ToBytes(i uint32) []byte

Types

type BaseCliCb

type BaseCliCb func(stat ConnStat, content []byte, cli *TcpCli, ele *TcpBase)

type baseBaseCb func(stat ConnStat, content []byte, ele* TcpBase)

type BaseSerCb

type BaseSerCb func(stat ConnStat, content []byte, ser *TcpSer, ele *TcpBase)

type ConnStat

type ConnStat int
const (
	Connect ConnStat //you can call one of
	Disconnect
	Data
)

type Event

type Event interface {
	Type() string
	Source() interface{}
	Value() interface{}
	PrevValue() interface{}
}

Event represents an action that occurred within the Raft library. Listeners can subscribe to event types by using the Server.AddEventListener() function.

func NewEvent

func NewEvent(typ string, value interface{}, prevValue interface{}) Event

newEvent creates a new event.

type EventDispatcher

type EventDispatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

EventDispatcher is responsible for managing listeners for named events and dispatching event notifications to those listeners.

func NewEventDispatcher

func NewEventDispatcher(source interface{}) *EventDispatcher

newEventDispatcher creates a new EventDispatcher instance.

func (*EventDispatcher) AddEventListener

func (d *EventDispatcher) AddEventListener(typ string, listener EventListener)

AddEventListener adds a listener function for a given event type.

func (*EventDispatcher) DispatchEvent

func (d *EventDispatcher) DispatchEvent(e Event)

DispatchEvent dispatches an event.

func (*EventDispatcher) RemoveEventListener

func (d *EventDispatcher) RemoveEventListener(typ string, listener EventListener)

RemoveEventListener removes a listener function for a given event type.

type EventListener

type EventListener func(Event)

EventListener is a function that can receive event notifications.

type GoFun

type GoFun func()

type GoLaunchFun

type GoLaunchFun func(args ...interface{})

type GoSelectFun

type GoSelectFun func(args interface{})

type PingPongStat

type PingPongStat int

type TcpBase

type TcpBase struct {
	PPStat PingPongStat
	// contains filtered or unexported fields
}

func NewTcpBase

func NewTcpBase(cb tcpBaseCb, conn net.Conn) *TcpBase

func (*TcpBase) ConnId

func (tcp *TcpBase) ConnId() string

func (*TcpBase) ConnIp

func (tcp *TcpBase) ConnIp() string

func (*TcpBase) IsAuth

func (tcp *TcpBase) IsAuth() bool

type TcpCli

type TcpCli struct {
	TcpNBase
	// contains filtered or unexported fields
}

func NewTcpCli

func NewTcpCli(bsCb BaseCliCb, enableHash bool, maxOutgo int, outGoBuf int, heartBeatSecond int) *TcpCli

func (*TcpCli) ConnRemove

func (tcp *TcpCli) ConnRemove(ip string)

func (*TcpCli) Connect

func (tcp *TcpCli) Connect(ipPort string) error

func (*TcpCli) SendByHash

func (tcp *TcpCli) SendByHash(key string, content []byte)

type TcpNBase

type TcpNBase struct {
	sync.RWMutex
	Tag       int
	ConnCount uint32
	// contains filtered or unexported fields
}

func (*TcpNBase) AuthOut

func (tcp *TcpNBase) AuthOut(connId string)

func (*TcpNBase) Close

func (tcp *TcpNBase) Close()

func (*TcpNBase) CloseAllConns

func (tcp *TcpNBase) CloseAllConns()

func (*TcpNBase) ConIdByIp

func (tcp *TcpNBase) ConIdByIp(ip string) (string, error)

func (*TcpNBase) ConnByIp

func (tcp *TcpNBase) ConnByIp(ip string) *TcpBase

func (*TcpNBase) ConnRemove

func (tcp *TcpNBase) ConnRemove(connIp string)

func (*TcpNBase) ConnRemoveByConnId

func (tcp *TcpNBase) ConnRemoveByConnId(connId string)

func (*TcpNBase) HeartBeatSecond

func (tcp *TcpNBase) HeartBeatSecond() int

func (*TcpNBase) SendAllConns

func (tcp *TcpNBase) SendAllConns(bytes []byte)

func (*TcpNBase) SendWithConn

func (tcp *TcpNBase) SendWithConn(connId string, bytes []byte)

func (*TcpNBase) SendWithIp

func (tcp *TcpNBase) SendWithIp(connIp string, bytes []byte)

func (*TcpNBase) SetConnId

func (tcp *TcpNBase) SetConnId(ip, connId string)

type TcpSer

type TcpSer struct {
	TcpNBase

	MaxConn uint32
	// contains filtered or unexported fields
}

func NewTcpSer

func NewTcpSer(ipPort string, tlsCfg *TlsCfg, cb BaseSerCb, maxOutgo int, outGoBuf int, listenerGoNum int, heartBeatSecond int) *TcpSer

func (*TcpSer) Close

func (tcp *TcpSer) Close()

type TlsCfg

type TlsCfg struct {
	Pem string
	Key string
}

Jump to

Keyboard shortcuts

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