Documentation
¶
Index ¶
- Constants
- Variables
- func AddNodeRoute(mid uint32, nodeRoute *NodeRoute)
- func BindSID(agent *Agent)
- func ClusterLocalDataRoute(agent *Agent, session *cproto.Session, msg *Message, nodeRoute *NodeRoute, ...) error
- func Count() int
- func DefaultDataRoute(agent *Agent, msg *Message, route *NodeRoute)
- func ForeachAgent(fn func(a *Agent))
- func LocalDataRoute(agent *Agent, session *cproto.Session, msg *Message, nodeRoute *NodeRoute, ...)
- func NewActor(agentActorID string) *actor
- func Response(iActor cfacade.IActor, session *cproto.Session, mid uint32, v interface{})
- func SetEndian(e binary.ByteOrder)
- func SetHeartbeatTime(t time.Duration)
- func SetWriteBacklog(backlog int)
- func Unbind(sid cfacade.SID)
- type ActorBase
- type Agent
- func Bind(sid cfacade.SID, uid cfacade.UID) (*Agent, error)
- func GetAgent(sid string, uid cfacade.UID) (*Agent, bool)
- func GetAgentWithSID(sid cfacade.SID) (*Agent, bool)
- func GetAgentWithUID(uid cfacade.UID) (*Agent, bool)
- func NewAgent(app cfacade.IApplication, conn net.Conn, session *cproto.Session) *Agent
- func (a *Agent) AddOnClose(fn OnCloseFunc)
- func (a *Agent) Bind(uid cfacade.UID) (*Agent, error)
- func (a *Agent) Close()
- func (a *Agent) IsClosed() bool
- func (a *Agent) Kick(mid uint32, reason interface{}, closed bool)
- func (a *Agent) RemoteAddr() string
- func (a *Agent) Response(mid uint32, v interface{})
- func (a *Agent) Run()
- func (a *Agent) SID() cfacade.SID
- func (a *Agent) SendKick(pkg []byte)
- func (a *Agent) SendRaw(bytes []byte)
- func (a *Agent) Session() *cproto.Session
- func (a *Agent) SetLastAt()
- func (a *Agent) SetState(state int32) bool
- func (a *Agent) State() int32
- func (a *Agent) UID() cfacade.UID
- func (a *Agent) Unbind()
- type DataRouteFunc
- type Message
- type NodeRoute
- type OnCloseFunc
- type OnNewAgentFunc
Constants ¶
const ( AgentInit int32 = 0 // initial state AgentClosed int32 = 4 // closed, no further processing )
Agent lifecycle states.
const (
ResponseFuncName = "response"
)
Remote function name constants.
Variables ¶
var (
NoneMessage = Message{} // zero-value sentinel
)
Package-level message constants.
Functions ¶
func AddNodeRoute ¶
AddNodeRoute maps a mid (message id) to a NodeRoute for routing incoming messages.
func ClusterLocalDataRoute ¶
func ClusterLocalDataRoute(agent *Agent, session *cproto.Session, msg *Message, nodeRoute *NodeRoute, nodeID, targetPath string) error
ClusterLocalDataRoute publishes a message to a local actor on a remote node via the cluster.
func DefaultDataRoute ¶
DefaultDataRoute is the default message routing handler. It dispatches locally when the target node type matches the agent's node, or forwards to a random member of the target node type via the cluster.
func ForeachAgent ¶
func ForeachAgent(fn func(a *Agent))
ForeachAgent iterates over all connected agents.
func LocalDataRoute ¶
func LocalDataRoute(agent *Agent, session *cproto.Session, msg *Message, nodeRoute *NodeRoute, targetPath string)
LocalDataRoute posts a message to a local actor on this node.
func NewActor ¶
func NewActor(agentActorID string) *actor
NewActor creates a new simple parser Actor with the given agent actor id.
func Response ¶
Response looks up the agent by the session and sends a response payload back to the client.
func SetHeartbeatTime ¶
SetHeartbeatTime sets the heartbeat interval for agent connections. Values less than 1 second are ignored.
func SetWriteBacklog ¶
func SetWriteBacklog(backlog int)
SetWriteBacklog sets the size of the write and pending channel buffers. Values less than or equal to 0 are ignored.
Types ¶
type Agent ¶
type Agent struct {
cfacade.IApplication
// contains filtered or unexported fields
}
Agent represents a single client connection. All conn.Write and teardown operations happen exclusively in writeChan's goroutine.
func Bind ¶ added in v1.5.3
Bind associates a uid with an existing sid. Returns any previously bound agent for the same uid (duplicate login).
func GetAgentWithSID ¶ added in v1.5.3
GetAgentWithSID looks up an agent by session id (public).
func GetAgentWithUID ¶
GetAgentWithUID looks up an agent by user id.
func (*Agent) AddOnClose ¶
func (a *Agent) AddOnClose(fn OnCloseFunc)
func (*Agent) RemoteAddr ¶
type DataRouteFunc ¶
DataRouteFunc is called to route a decoded message to the target actor.
type Message ¶
type Message struct {
MID uint32 // message id for request/response matching
Len uint32 // length of the data payload
Data []byte // payload bytes
}
Message represents a decoded simple-protocol message. The wire format is: MID(4 bytes) + DataLen(4 bytes) + Data(DataLen bytes).
type NodeRoute ¶
type NodeRoute struct {
NodeType string // target node type
ActorID string // target actor id
FuncName string // target function name
}
NodeRoute describes the target actor and function for a given message id.
func GetNodeRoute ¶
GetNodeRoute returns the NodeRoute for the given message id.
type OnCloseFunc ¶
type OnCloseFunc func(*Agent)
type OnNewAgentFunc ¶
type OnNewAgentFunc func(newAgent *Agent)