service

package
v0.0.0-...-677ea5f Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DK_Zone_Global = "global"
	DK_Server_Id   = "server_id"

	Max_Globle_Group uint16 = 999
)
View Source
const (
	HeadSrvToRegHandshakeReq uint8 = iota
	HeadRegToSrvHandshakeRes
	HeadSrvToRegBindSnapshotReq
	HeadSrvToRegBindSnapshotNtf
	HeadRegToSrvChangeGroup
	HeadSrvToSrvHandshakeReq
	HeadSrvToSrvHandshakeRes
	HeadSrvToSrvBindNotify
	HeadSrvToSrvReq
	HeadSrvToSrvRes
	HeadSrvToSrvConfirm
	HeadSrvToSrvCancel
	HeadSrvToSrvNtf
)
View Source
const (
	TransporterAgentGroups   = "TransporterAgentGroups"
	TransporterAgentServerId = "TransporterAgentServerId"
)
View Source
const (
	AgentNotifies = "notifies"
)

Variables

This section is empty.

Functions

func AuthAgentData

func AuthAgentData(data utils.IData)

func BindCodecPool

func BindCodecPool(codec network.IPoolCodec, group, code uint16, req, res func() interface{})

func CheckAgentAuthData

func CheckAgentAuthData(data utils.IData) bool

func CodeToString

func CodeToString(code uint16) string

func GetFullCode

func GetFullCode(group, code uint16) uint32

func GetGroupAndCode

func GetGroupAndCode(fullCode uint32) (group, code uint16)

func GroupToString

func GroupToString(group uint16) string

func GroupsToStrings

func GroupsToStrings(groups []uint16) []string

func NewDiscoverDialer

func NewDiscoverDialer(option *DiscoverDialerOption) *discoverDialer

func NewLocalLocker

func NewLocalLocker() *localLocker

func NewNotifyReceiver

func NewNotifyReceiver(codec network.IPoolCodec, locker ILocker) *notifyReceiver

func NewNotifySender

func NewNotifySender() *notifySender

func NewRequestReceiver

func NewRequestReceiver(codec network.IPoolCodec, locker ILocker) *requestReceiver

func NewRequestSender

func NewRequestSender() *requestSender

func NewServer

func NewServer(addr string, code network.IPoolCodec) *server

func NewServerSender

func NewServerSender(requestSender IRequestSender, notifySender INotifySender) *serverSender

func NewServerTransporter

func NewServerTransporter(addr string) *serverTransporter

func NewTransporterDialer

func NewTransporterDialer() *transporterDialer

func NewTransporterListener

func NewTransporterListener(addr string, onCloseAgent network.FAgent) *transporterListener

func SetCodeNames

func SetCodeNames(data map[uint16]string)

func SetGroupNames

func SetGroupNames(data map[uint16]string)

func SetGroupStateNames

func SetGroupStateNames(data map[EGroupState]string)

Types

type BaseService

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

func NewBaseService

func NewBaseService(code uint16) *BaseService

func (*BaseService) Code

func (b *BaseService) Code() uint16

type DiscoverDialerOption

type DiscoverDialerOption struct {
	Zone         string
	RegisterAddr string
	RegisterKey  string
	Addr         string
	ServeGroups  []uint16
	WatchGroups  []uint16
	ListenGroups []uint16
}

type DiscoverGroupSnapshot

type DiscoverGroupSnapshot struct {
	Name     string
	ServerId int64
}

type DiscoverServerSnapshot

type DiscoverServerSnapshot struct {
	Id           int64
	Zone         string
	Address      string
	Key          string
	ServeGroups  []string
	WatchGroups  []string
	ListenGroups []string
}

type DiscoverSnapshot

type DiscoverSnapshot struct {
	Global  *DiscoverZoneSnapshot
	Zones   []*DiscoverZoneSnapshot
	Servers []*DiscoverServerSnapshot
}

type DiscoverZoneSnapshot

type DiscoverZoneSnapshot struct {
	Name   string
	Groups []*DiscoverGroupSnapshot
}

type EGroupState

type EGroupState uint8
const (
	EGroupStateNone EGroupState = iota
	EGroupStatePrepare
	EGroupStateNormal
	EGroupStateBusy
	EGroupStateFull
	EGroupStateSafeguard
	EGroupStateOffline
)

func (EGroupState) String

func (t EGroupState) String() string

type FActionAgent

type FActionAgent func(group uint16, action func(agent network.IAgent))

type FGroupChange

type FGroupChange func(serverId int64, addr, key string, group uint16)

type FNotify

type FNotify func(notify INotify)

type FRequest

type FRequest func(request IRequest)

type FSnapshotListener

type FSnapshotListener func(*DiscoverSnapshot)

type IDiscoverDialer

type IDiscoverDialer interface {
	BindSnapshotChangedHandle(snapshotChangedHandle FSnapshotListener)
	// contains filtered or unexported methods
}

type IDiscoverListener

type IDiscoverListener interface {
	// contains filtered or unexported methods
}

func NewDiscoverListener

func NewDiscoverListener(addr string, checkKey utils.FunStr) IDiscoverListener

type ILocker

type ILocker interface {
	Lock(key string) error
	Unlock(key string) error
	RLock(key string) error
	RUnlock(key string) error
}

type INotify

type INotify interface {
	NotifyReceiver() INotifyReceiver
	Agent() network.IAgent
	TId() int64
	Body() interface{}

	Complete()
	// contains filtered or unexported methods
}

type INotifyListener

type INotifyListener interface {
	Code() uint16
	Listen(notify INotify)
}

type INotifyReceiver

type INotifyReceiver interface {
	HasGroup(group uint16) bool
	GetGroupCodes(group uint16) (codes []uint16, ok bool)
	ListenGroups() []uint16
	Locker() ILocker
	Notifies() map[uint16][]uint16

	RegisterNotifyListeners(group uint16, notifies ...INotifyListener)
	RegisterFuncNotifyListener(group, code uint16, notify FNotify)
	// contains filtered or unexported methods
}

type INotifySender

type INotifySender interface {
	NotifyReceiver() INotifyReceiver
	SetNotifyReceiver(receiver INotifyReceiver)
	ServerTransporter() IServerTransporter
	SetServerTransporter(transporter IServerTransporter)
	Notify(parent int64, group, code uint16, setNtf utils.ActionObj)
}

type IRequest

type IRequest interface {
	Agent() network.IAgent
	//请求id,可用于链路日志
	TId() int64
	//请求消息体
	Body() interface{}
	//是否开启事物
	Transaction() bool
	//响应正常
	ResponseOk(res func(interface{}))
	//响应错误
	ResponseError(err error)

	//接收事务确认的通道,用于执行提交逻辑
	OnConfirmCh() <-chan struct{}
	//接收事务取消的通道,用于执行回滚逻辑
	OnCancelCh() <-chan struct{}

	//同步发起子事务请求,当该父事务接收确认/取消信号,立即转发到请求的子事务
	RequestSub(group, code uint16, setReq utils.ActionObj) (res interface{}, doneCh utils.WaitCh, err error)
	//异步发起子事务请求,当该父事务接收确认/取消信号,立即转发到请求的子事务
	RequestAsyncSub(group, code uint16, setReq utils.ActionObj, handle utils.ActionObjErr) error

	//子通知
	NotifySub(group, code uint16, setNtf utils.ActionObj)
	// contains filtered or unexported methods
}

type IRequestReceiver

type IRequestReceiver interface {
	Locker() ILocker
	ServerSender() IServerSender
	SetServerSender(serverSender IServerSender)

	HasGroup(code uint16) bool

	ServeGroups() []uint16
	RegisterRequestServices(group uint16, services ...IRequestService)
	RegisterFuncRequestService(group, code uint16, service FRequest)
	// contains filtered or unexported methods
}

type IRequestSender

type IRequestSender interface {
	RequestReceiver() IRequestReceiver
	SetRequestReceiver(receiver IRequestReceiver)
	ServerTransporter() IServerTransporter
	SetServerTransporter(transporter IServerTransporter)
	Request(parent int64, group, code uint16, transaction bool, setReq utils.ActionObj) (tid int64, res interface{}, done utils.WaitCh, err error)
	RequestAsync(parent int64, group, code uint16, transaction bool, setReq utils.ActionObj, handle utils.ActionObjErr) (int64, error)
	Confirm(tid int64)
	Cancel(tid int64)
}

type IRequestService

type IRequestService interface {
	Code() uint16
	Serve(request IRequest)
}

type IServer

type IServer interface {
	ConnectDiscover(zone, addr, key string)
	RegisterWatchGroups(groups ...uint16)
	RegisterRequestServices(group uint16, services ...IRequestService)
	RegisterFuncRequestService(group, code uint16, service FRequest)
	RegisterNotifyListeners(group uint16, notifies ...INotifyListener)
	RegisterFuncNotifyListener(group, code uint16, notify FNotify)
	Notify(parent int64, group, code uint16, setNtf utils.ActionObj)
	Request(parent int64, group, code uint16, transaction bool, setReq utils.ActionObj) (tid int64, res interface{}, done utils.WaitCh, err error)
	RequestAsync(parent int64, group, code uint16, transaction bool, setReq utils.ActionObj, handle utils.ActionObjErr) (int64, error)
}

type IServerSender

type IServerSender interface {
	RequestSender() IRequestSender
	NotifySender() INotifySender
}

type IServerTransporter

type IServerTransporter interface {
	ConnectDiscover(zone, discoverAddr, discoverKey string)
	DiscoverDialer() IDiscoverDialer
	TransporterListener() ITransporterListener
	TransporterDialer() ITransporterDialer
}

type ITransporterDialer

type ITransporterDialer interface {
	WatchGroups() []uint16
	RegisterWatchGroups(groups ...uint16)
	NotifyReceiver() INotifyReceiver
	SetNotifyReceiver(receiver INotifyReceiver)
	SendRequest(tid int64, group, code uint16, transaction bool, request []byte, resCh chan<- []byte, errCh chan<- error)
	SendConfirm(tid int64)
	SendCancel(tid int64)
	// contains filtered or unexported methods
}

type ITransporterListener

type ITransporterListener interface {
	Addr() string

	Gate() network.IGate

	RequestReceiver() IRequestReceiver
	SetRequestReceiver(receiver IRequestReceiver)
	SendNotify(tid int64, group, code uint16, notify []byte)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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