Skip to content

Commit

Permalink
Merge pull request #764 from georgehao/refact-seri
Browse files Browse the repository at this point in the history
feat: update the comment of getty/listener
  • Loading branch information
fangyincheng committed Sep 19, 2020
2 parents 256c1ed + 5db064a commit 8a059dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
32 changes: 16 additions & 16 deletions remoting/getty/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

// todo: WritePkg_Timeout will entry *.yml
const (
// WritePkg_Timeout ...
// WritePkg_Timeout the timeout of write pkg
WritePkg_Timeout = 5 * time.Second
)

Expand All @@ -64,35 +64,35 @@ func (s *rpcSession) GetReqNum() int32 {
// RpcClientHandler
// //////////////////////////////////////////

// RpcClientHandler ...
// nolint
type RpcClientHandler struct {
conn *gettyRPCClient
}

// NewRpcClientHandler ...
// nolint
func NewRpcClientHandler(client *gettyRPCClient) *RpcClientHandler {
return &RpcClientHandler{conn: client}
}

// OnOpen ...
// OnOpen call the getty client session opened, add the session to getty client session list
func (h *RpcClientHandler) OnOpen(session getty.Session) error {
h.conn.addSession(session)
return nil
}

// OnError ...
// OnError the getty client session has errored, so remove the session from the getty client session list
func (h *RpcClientHandler) OnError(session getty.Session, err error) {
logger.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err)
h.conn.removeSession(session)
}

// OnClose ...
// OnClose close the session, remove it from the getty session list
func (h *RpcClientHandler) OnClose(session getty.Session) {
logger.Infof("session{%s} is closing......", session.Stat())
h.conn.removeSession(session)
}

// OnMessage ...
// OnMessage get response from getty server, and update the session to the getty client session list
func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
result, ok := pkg.(remoting.DecodeResult)
if !ok {
Expand Down Expand Up @@ -138,7 +138,7 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
h.conn.pool.rpcClient.responseHandler.Handler(p)
}

// OnCron ...
// OnCron check the session health periodic. if the session's sessionTimeout has reached, just close the session
func (h *RpcClientHandler) OnCron(session getty.Session) {
rpcSession, err := h.conn.getClientRpcSession(session)
if err != nil {
Expand All @@ -160,7 +160,7 @@ func (h *RpcClientHandler) OnCron(session getty.Session) {
// RpcServerHandler
// //////////////////////////////////////////

// RpcServerHandler implement EventListener of getty.
// nolint
type RpcServerHandler struct {
maxSessionNum int
sessionTimeout time.Duration
Expand All @@ -169,7 +169,7 @@ type RpcServerHandler struct {
server *Server
}

// NewRpcServerHandler ...
// nolint
func NewRpcServerHandler(maxSessionNum int, sessionTimeout time.Duration, serverP *Server) *RpcServerHandler {
return &RpcServerHandler{
maxSessionNum: maxSessionNum,
Expand All @@ -179,7 +179,8 @@ func NewRpcServerHandler(maxSessionNum int, sessionTimeout time.Duration, server
}
}

// OnOpen ...
// OnOpen call server session opened, add the session to getty server session list. also onOpen
// will check the max getty server session number
func (h *RpcServerHandler) OnOpen(session getty.Session) error {
var err error
h.rwlock.RLock()
Expand All @@ -198,23 +199,23 @@ func (h *RpcServerHandler) OnOpen(session getty.Session) error {
return nil
}

// OnError ...
// OnError the getty server session has errored, so remove the session from the getty server session list
func (h *RpcServerHandler) OnError(session getty.Session, err error) {
logger.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err)
h.rwlock.Lock()
delete(h.sessionMap, session)
h.rwlock.Unlock()
}

// OnClose ...
// OnClose close the session, remove it from the getty server list
func (h *RpcServerHandler) OnClose(session getty.Session) {
logger.Infof("session{%s} is closing......", session.Stat())
h.rwlock.Lock()
delete(h.sessionMap, session)
h.rwlock.Unlock()
}

// OnMessage ...
// OnMessage get request from getty client, update the session reqNum and reply response to client
func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
h.rwlock.Lock()
if _, ok := h.sessionMap[session]; ok {
Expand Down Expand Up @@ -285,7 +286,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
reply(session, resp, hessian.PackageResponse)
}

// OnCron ...
// OnCron check the session health periodic. if the session's sessionTimeout has reached, just close the session
func (h *RpcServerHandler) OnCron(session getty.Session) {
var (
flag bool
Expand All @@ -312,7 +313,6 @@ func (h *RpcServerHandler) OnCron(session getty.Session) {
}

func reply(session getty.Session, resp *remoting.Response, tp hessian.PackageType) {

if err := session.WritePkg(resp, WritePkg_Timeout); err != nil {
logger.Errorf("WritePkg error: %#v, %#v", perrors.WithStack(err), resp)
}
Expand Down
1 change: 0 additions & 1 deletion remoting/getty/readwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func NewRpcServerPackageHandler(server *Server) *RpcServerPackageHandler {
func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface{}, int, error) {
req, length, err := (p.server.codec).Decode(data)
//resp,len, err := (*p.).DecodeResponse(buf)

if err != nil {
if err == hessian.ErrHeaderNotEnough || err == hessian.ErrBodyNotEnough {
return nil, 0, nil
Expand Down
2 changes: 1 addition & 1 deletion test/integrate/dubbo/go-client/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/apache/dubbo-go/test/integrate/dubbo/go-client

require github.com/apache/dubbo-go-hessian2 v1.6.0-rc1.0.20200906044240-6c1fb5c3bd44
require github.com/apache/dubbo-go-hessian2 v1.7.0

go 1.13
2 changes: 1 addition & 1 deletion test/integrate/dubbo/go-server/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/apache/dubbo-go/test/integrate/dubbo/go-server

require github.com/apache/dubbo-go-hessian2 v1.6.0-rc1.0.20200906044240-6c1fb5c3bd44
require github.com/apache/dubbo-go-hessian2 v1.7.0

go 1.13

0 comments on commit 8a059dd

Please sign in to comment.