You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package connection
// ManagerInterface 连接管理器接口
type ManagerInterface interface {
// Add 添加连接
Add(conn ConnectionInterface) error
// Remove 移除连接
Remove(connID string) error
// Get 获取连接
Get(connID string) (ConnectionInterface, error)
// Count 获取连接数
Count() int
// GetAll 获取所有连接
GetAll() []ConnectionInterface
// AddToGroup 将连接添加到分组(使用字符串分组策略)
AddToGroup(groupID string, connID string) error
// RemoveFromGroup 从分组中移除连接
RemoveFromGroup(groupID string, connID string) error
// GetGroup 获取分组(使用字符串分组策略)
GetGroup(groupID string) []ConnectionInterface
// BroadcastToGroup 向分组广播消息
BroadcastToGroup(groupID string, data []byte) error
// AddToGroupByStrategy 使用分组策略将连接添加到分组
// 如果策略支持自动分组会自动获取分组ID
AddToGroupByStrategy(groupID string, connID string, strategy GroupStrategy) error
// GetGroupByStrategy 使用分组策略获取分组
GetGroupByStrategy(groupID string, strategy GroupStrategy) []ConnectionInterface
// RegisterGroupStrategy 注册分组策略(用于自动分组)
// name: 策略名称
// strategy: 分组策略
RegisterGroupStrategy(name string, strategy GroupStrategy)
// GetGroupStrategy 获取已注册的分组策略
GetGroupStrategy(name string) GroupStrategy
// CleanupInactive 清理非活动连接
CleanupInactive(timeout interface{}) // 使用interface{}以兼容不同的实现
// AddIndex 添加索引(通过业务数据查询连接)
// key: 索引键(如 "hardware_id"
// value: 索引值(如 "device_001"
// connID: 连接ID
AddIndex(key, value string, connID string) error
// RemoveIndex 移除索引
RemoveIndex(key, value string, connID string) error
// FindByIndex 通过索引查找连接
FindByIndex(key, value string) (ConnectionInterface, error)
// FindByIndexKey 通过索引键查找所有连接
FindByIndexKey(key string) ([]ConnectionInterface, error)
}