network

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//短连接模式
	ConnectionShort int = iota
	//长连接模式
	ConnectionLong
)

Variables

View Source
var (
	//不同系统服务使用不同的连接持有模式
	DefaultServerServiceToConnectionControl = map[config.ClusterType]int{
		config.DiscoverCluster:    ConnectionLong,
		config.HealthCheckCluster: ConnectionShort,
		config.MonitorCluster:     ConnectionShort,
	}
)

Functions

func IsAvailableConnection

func IsAvailableConnection(conn *Connection) bool

连接是否可用

func ToGRPCConn

func ToGRPCConn(conn ClosableConn) *grpc.ClientConn

转换成GRPC连接

Types

type ClientInfo

type ClientInfo struct {
	IP      atomic.Value
	HashKey atomic.Value
}

当前客户端相关信息

func (*ClientInfo) GetHashKey

func (c *ClientInfo) GetHashKey() []byte

获取Hash值

func (*ClientInfo) GetIPString

func (c *ClientInfo) GetIPString() string

获取IP值

type ClosableConn

type ClosableConn interface {
	//关闭并释放
	Close() error
}

可关闭连接对象

type ConnCreator

type ConnCreator interface {
	//插件名
	Name() string
	//创建实际的连接
	CreateConnection(address string, timeout time.Duration, clientInfo *ClientInfo) (ClosableConn, error)
}

连接创建器

type ConnID

type ConnID struct {
	//唯一ID
	ID uint32
	//所属服务
	Service config.ClusterService
	//目标server地址
	Address string
	// contains filtered or unexported fields
}

连接标识

func (ConnID) String

func (c ConnID) String() string

TOString方法

type Connection

type Connection struct {
	ConnID
	//连接实体
	Conn ClosableConn
	// contains filtered or unexported fields
}

GRPC连接对象,含唯一连接ID

func (*Connection) ForceClose

func (c *Connection) ForceClose() bool

func (*Connection) Release

func (c *Connection) Release(opKey string)

释放连接

type ConnectionManager

type ConnectionManager interface {

	// SetConnCreator 设置当前协议的连接创建器
	SetConnCreator(creator ConnCreator)

	// Destroy 销毁并释放连接管理器
	Destroy()

	// GetConnection 获取并占用连接
	GetConnection(opKey string, clusterType config.ClusterType) (*Connection, error)

	// GetConnectionByHashKey 通过传入一致性hashKey的方式获取链接
	GetConnectionByHashKey(opKey string, clusterType config.ClusterType, hashKey []byte) (*Connection, error)

	// ReportConnectionDown 报告连接故障
	ReportConnectionDown(connID ConnID)

	// ReportSuccess 上报接口调用成功
	ReportSuccess(connID ConnID, retCode int32, timeout time.Duration)

	// ReportFail 上报接口调用失败
	ReportFail(connID ConnID, retCode int32, timeout time.Duration)

	// UpdateServers 更新服务地址
	UpdateServers(svcEventKey model.ServiceEventKey)

	// GetClientInfo 获取当前客户端信息
	GetClientInfo() *ClientInfo

	// IsReady discover服务是否已经就绪
	IsReady() bool

	// GetHashExpectedInstance 计算hash Key对应的实例
	GetHashExpectedInstance(clusterType config.ClusterType, hash []byte) (string, model.Instance, error)

	// ConnectByAddr 直接通过addr连接,慎使用
	ConnectByAddr(clusterType config.ClusterType, addr string, instance model.Instance) (*Connection, error)
}

通用的连接管理器

func NewConnectionManager

func NewConnectionManager(
	cfg config.Configuration, valueCtx model.ValueContext) (ConnectionManager, error)

创建连接管理器

type ServerAddressList

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

服务地址列表

func (*ServerAddressList) ConnectServerByAddrOnly

func (s *ServerAddressList) ConnectServerByAddrOnly(addr string, timeout time.Duration,
	clsService config.ClusterService, instance model.Instance) (*Connection, error)

Jump to

Keyboard shortcuts

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