Documentation ¶
Index ¶
- type Connection
- func (c *Connection) CallPostStart()
- func (c *Connection) CallPreStop()
- func (c *Connection) Close()
- func (c *Connection) DeleteContext(key string)
- func (c *Connection) GetContext(key string) interface{}
- func (c *Connection) GetID() uint64
- func (c *Connection) GetServer() ZServer
- func (c *Connection) Reader()
- func (c *Connection) RespondToClient(ct encoding.ZContentType, data []byte) error
- func (c *Connection) Start()
- func (c *Connection) UpdateContext(key string, value interface{})
- func (c *Connection) Writer()
- type ConnectionAdmin
- func (ca *ConnectionAdmin) Evacuate()
- func (ca *ConnectionAdmin) PoolSize() int
- func (ca *ConnectionAdmin) Register(conn ZConnection)
- func (ca *ConnectionAdmin) Remove(conn ZConnection)
- func (ca *ConnectionAdmin) Retrieve(cid uint64) ZConnection
- func (ca *ConnectionAdmin) RetrieveAll() []ZConnection
- type Handler
- type Mux
- type Request
- type Server
- type ServerOption
- type ZConnection
- type ZConnectionAdmin
- type ZHandler
- type ZMux
- type ZRequest
- type ZServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct { ID uint64 Conn net.Conn Server ZServer Context map[string]interface{} // contains filtered or unexported fields }
func (*Connection) CallPostStart ¶
func (c *Connection) CallPostStart()
func (*Connection) CallPreStop ¶
func (c *Connection) CallPreStop()
func (*Connection) DeleteContext ¶
func (c *Connection) DeleteContext(key string)
func (*Connection) GetContext ¶
func (c *Connection) GetContext(key string) interface{}
func (*Connection) GetID ¶
func (c *Connection) GetID() uint64
func (*Connection) GetServer ¶
func (c *Connection) GetServer() ZServer
func (*Connection) Reader ¶
func (c *Connection) Reader()
Read from the TCP stream payload and decode the raw bytes to struct Prepare a processed request and send it to a worker to handle it
func (*Connection) RespondToClient ¶
func (c *Connection) RespondToClient(ct encoding.ZContentType, data []byte) error
Called by handler after dealing with the request Send the raw bytes to Writer
func (*Connection) Start ¶
func (c *Connection) Start()
Seperate read/write thread, leave the handling part to ZMux
func (*Connection) UpdateContext ¶
func (c *Connection) UpdateContext(key string, value interface{})
func (*Connection) Writer ¶
func (c *Connection) Writer()
Write the processed response (raw bytes received from handler) to client Quit on receiving the close signal after Reader quits
type ConnectionAdmin ¶
type ConnectionAdmin struct { // A vault of connections Pool map[uint64]ZConnection Mutex sync.RWMutex }
func (*ConnectionAdmin) Evacuate ¶
func (ca *ConnectionAdmin) Evacuate()
Called when daemon is shut down, closing all active connections to ensure a clean quit
func (*ConnectionAdmin) PoolSize ¶
func (ca *ConnectionAdmin) PoolSize() int
func (*ConnectionAdmin) Register ¶
func (ca *ConnectionAdmin) Register(conn ZConnection)
Add new connection to the vault
func (*ConnectionAdmin) Remove ¶
func (ca *ConnectionAdmin) Remove(conn ZConnection)
Delete the connection from the vault
func (*ConnectionAdmin) Retrieve ¶
func (ca *ConnectionAdmin) Retrieve(cid uint64) ZConnection
Get the connection via its id
func (*ConnectionAdmin) RetrieveAll ¶
func (ca *ConnectionAdmin) RetrieveAll() []ZConnection
type Handler ¶
type Handler struct{}
Define the behavior of server in response to client's request Need to be implemented at server side and registerd to ZJunx server's multiplexer (ZMux) after server is up
type Mux ¶
type Mux struct { // workers' number WorkerProcesses uint64 // request queues for each worker WorkerBacklog []chan ZRequest // channel attached to each worker to receive quit signal //WorkerExit []chan bool // the cancel function linked to ZMux's context WorkerExit context.CancelFunc WorkerGroup sync.WaitGroup // A bunch of registered handler to handle request HandlerSet map[encoding.ZContentType]ZHandler // legitime value: RoundRobin, Random, LeastConn ScheduleAlgo string }
func (*Mux) Register ¶
func (m *Mux) Register(ct encoding.ZContentType, h ZHandler)
Register the serverside defined handler to ZMux
func (*Mux) WorkerDismiss ¶
func (m *Mux) WorkerDismiss()
type Request ¶
type Request struct { Conn ZConnection Cont *encoding.Content }
Group the content decoded sent by client and associate ZConnection
func (*Request) Connection ¶
func (r *Request) Connection() ZConnection
func (*Request) ContentData ¶
func (*Request) ContentType ¶
func (r *Request) ContentType() encoding.ZContentType
type Server ¶
type Server struct { Name string ListenIP string IPVersion string ListenPort uint64 Mux ZMux CnxAdm ZConnectionAdmin PostStartHook func(ZConnection) PreStopHook func(ZConnection) // contains filtered or unexported fields }
func (*Server) GetCnxAdm ¶
func (s *Server) GetCnxAdm() ZConnectionAdmin
func (*Server) GetPostStartHook ¶
func (s *Server) GetPostStartHook() func(ZConnection)
func (*Server) GetPreStopHook ¶
func (s *Server) GetPreStopHook() func(ZConnection)
func (*Server) SetInterruptHandler ¶
func (s *Server) SetInterruptHandler()
type ServerOption ¶
type ServerOption func(*Server)
func WithHandler ¶
func WithHandler(ct encoding.ZContentType, h ZHandler) ServerOption
func WithPostStart ¶
func WithPostStart(hook func(ZConnection)) ServerOption
func WithPreStop ¶
func WithPreStop(hook func(ZConnection)) ServerOption
type ZConnection ¶
type ZConnectionAdmin ¶
type ZConnectionAdmin interface { Register(ZConnection) Retrieve(uint64) ZConnection RetrieveAll() []ZConnection Remove(ZConnection) Evacuate() PoolSize() int }
func AdmInit ¶
func AdmInit() ZConnectionAdmin
type ZMux ¶
type ZMux interface { Register(encoding.ZContentType, ZHandler) Schedule(ZRequest) Handle(ZRequest) WorkerDismiss() }
A multiplexer dealing with client's requests
type ZRequest ¶
type ZRequest interface { ContentType() encoding.ZContentType ContentData() []byte Connection() ZConnection }
type ZServer ¶
type ZServer interface { Start() Stop() GetMux() ZMux GetCnxAdm() ZConnectionAdmin GetPostStartHook() func(ZConnection) GetPreStopHook() func(ZConnection) SetInterruptHandler() }
func NewServer ¶
func NewServer(opts ...ServerOption) ZServer