container

package
v0.0.0-...-93c743e Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 18 Imported by: 0

README

  • 托管Server
  • 维护服务的依赖关系
  • 处理消息上下行

容器中管理的主要对象:

  1. him.Server
  2. map[string]ClientMap

Documentation

Index

Constants

View Source
const (
	StateYoung = "young"
	StateAdult = "adult"
)

新/旧服务

View Source
const (
	KeyServiceState = "service_state"
)

Variables

This section is empty.

Functions

func EnableMonitor

func EnableMonitor(listen string) error

func Forward

func Forward(serviceName string, packet *pkt.LogicPkt) error

Forward 消息上行主要用于 下游服务(长连网关) 发送消息到上游服务(如LoginServer)

func HashCode

func HashCode(key string) int

func Init

func Init(srv him.Server, deps ...string) error

Init 初始化服务,由上层传入依赖服务

func Push

func Push(server string, p *pkt.LogicPkt) error

Push a message to gateway 逻辑服务-消息下行

func SetDialer

func SetDialer(dialer him.Dialer)

SetDialer set tcp dialer

func SetSelector

func SetSelector(selector Selector)

SetSelector set a default selector 用于上层业务注册一个自定义的服务路由器

func SetServiceNaming

func SetServiceNaming(nm naming.Naming)

SetServiceNaming set service naming

func Start

func Start() error

Start 启动容器 step1: 服务注册 step2:启动Server step3:监听依赖服务 step4:系统退出

Types

type ClientMap

type ClientMap interface {
	Add(client him.Client)
	Remove(clientId string)
	Get(clientId string) (client him.Client, ok bool)

	Services(kvs ...string) []him.Service
}

func NewClientMap

func NewClientMap(num int) ClientMap

type ClientMapImpl

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

func (*ClientMapImpl) Add

func (ch *ClientMapImpl) Add(client him.Client)

func (*ClientMapImpl) Get

func (ch *ClientMapImpl) Get(clientId string) (client him.Client, ok bool)

func (*ClientMapImpl) Remove

func (ch *ClientMapImpl) Remove(clientId string)

func (*ClientMapImpl) Services

func (ch *ClientMapImpl) Services(kvs ...string) []him.Service

Services 返回服务列表 TODO: 优化kvs传参

type Container

type Container struct {
	sync.RWMutex

	Naming naming.Naming
	Srv    him.Server
	// contains filtered or unexported fields
}

func Default

func Default() *Container

type HashSelector

type HashSelector struct {
}

HashSelector 哈希选择器

func (*HashSelector) Lookup

func (h *HashSelector) Lookup(header *pkt.Header, servers []him.Service) string

Lookup TODO: 目前的选择器是伪哈希,当service的数量不变时,固定可用,当service数量发生变化时,会导致service的哈希取值发生变化

type Selector

type Selector interface {
	Lookup(*pkt.Header, []him.Service) string
}

Selector is used to select a Service

Jump to

Keyboard shortcuts

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