-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_handler.go
More file actions
38 lines (31 loc) · 836 Bytes
/
Copy pathclient_handler.go
File metadata and controls
38 lines (31 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package easycall
import (
"github.com/panjf2000/ants/v2"
"github.com/starjiang/elog"
)
//ClientHandler for EasyService
type ClientHandler struct {
client interface{}
pool *ants.Pool
}
func NewClientHandler(client interface{}) *ClientHandler {
clientHandler := &ClientHandler{}
clientHandler.client = client
pool, _ := ants.NewPool(EASYCALL_CLIENT_GO_POOL_SIZE, ants.WithNonblocking(true))
clientHandler.pool = pool
return clientHandler
}
func (h *ClientHandler) Dispatch(pkgData []byte, client *EasyConnection) {
err := h.pool.Submit(func() {
defer PanicHandler()
serviceClient := h.client.(*ServiceClient)
reqPkg, err := DecodeWithBodyData(pkgData)
if err != nil {
elog.Error("decode pkg fail:", err)
}
serviceClient.Process(reqPkg)
})
if err != nil {
elog.Error("submit to pool fail,", err)
}
}