Skip to content
Snippets Groups Projects
Commit 25fa96d5 authored by 邹毅贤's avatar 邹毅贤
Browse files

add comment in all files of protocol directory

parent 6fe0e8a6
No related branches found
No related tags found
No related merge requests found
......@@ -111,7 +111,7 @@ func setClientGrpool() {
}
}
// Options ...
// Options is option for create dubbo client
type Options struct {
// connect timeout
ConnectTimeout time.Duration
......
......@@ -65,6 +65,7 @@ type DubboPackage struct {
Err error
}
// String prints dubbo package detail include header、path、body etc.
func (p DubboPackage) String() string {
return fmt.Sprintf("DubboPackage: Header-%v, Path-%v, Body-%v", p.Header, p.Service, p.Body)
}
......
......@@ -27,7 +27,7 @@ import (
)
type (
// GettySessionParam ...
// GettySessionParam is session configuration for getty.
GettySessionParam struct {
CompressEncoding bool `default:"false" yaml:"compress_encoding" json:"compress_encoding,omitempty"`
TcpNoDelay bool `default:"true" yaml:"tcp_no_delay" json:"tcp_no_delay,omitempty"`
......@@ -47,8 +47,7 @@ type (
SessionName string `default:"rpc" yaml:"session_name" json:"session_name,omitempty"`
}
// ServerConfig
//Config holds supported types by the multiconfig package
// ServerConfig holds supported types by the multiconfig package
ServerConfig struct {
// session
SessionTimeout string `default:"60s" yaml:"session_timeout" json:"session_timeout,omitempty"`
......@@ -64,8 +63,7 @@ type (
GettySessionParam GettySessionParam `required:"true" yaml:"getty_session_param" json:"getty_session_param,omitempty"`
}
// ClientConfig
//Config holds supported types by the multiconfig package
// ClientConfig holds supported types by the multiconfig package
ClientConfig struct {
ReconnectInterval int `default:"0" yaml:"reconnect_interval" json:"reconnect_interval,omitempty"`
......@@ -94,7 +92,7 @@ type (
}
)
// GetDefaultClientConfig ...
// GetDefaultClientConfig gets client default configuration.
func GetDefaultClientConfig() ClientConfig {
return ClientConfig{
ReconnectInterval: 0,
......@@ -122,7 +120,7 @@ func GetDefaultClientConfig() ClientConfig {
}}
}
// GetDefaultServerConfig ...
// GetDefaultServerConfig gets server default configuration.
func GetDefaultServerConfig() ServerConfig {
return ServerConfig{
SessionTimeout: "180s",
......
......@@ -33,7 +33,7 @@ import (
// dubbo protocol constant
const (
// DUBBO ...
// DUBBO is dubbo protocol name
DUBBO = "dubbo"
)
......
......@@ -41,10 +41,9 @@ import (
"github.com/apache/dubbo-go/protocol/invocation"
)
// todo: WritePkg_Timeout will entry *.yml
// todo: writePkg_Timeout will entry *.yml
const (
// WritePkg_Timeout ...
WritePkg_Timeout = 5 * time.Second
writePkg_Timeout = 5 * time.Second
)
var (
......@@ -56,10 +55,12 @@ type rpcSession struct {
reqNum int32
}
// AddReqNum adds total request number safely
func (s *rpcSession) AddReqNum(num int32) {
atomic.AddInt32(&s.reqNum, num)
}
// GetReqNum gets total request number safely
func (s *rpcSession) GetReqNum() int32 {
return atomic.LoadInt32(&s.reqNum)
}
......@@ -68,35 +69,35 @@ func (s *rpcSession) GetReqNum() int32 {
// RpcClientHandler
// //////////////////////////////////////////
// RpcClientHandler ...
// RpcClientHandler is handler of RPC Client
type RpcClientHandler struct {
conn *gettyRPCClient
}
// NewRpcClientHandler ...
// NewRpcClientHandler creates RpcClientHandler with @gettyRPCClient
func NewRpcClientHandler(client *gettyRPCClient) *RpcClientHandler {
return &RpcClientHandler{conn: client}
}
// OnOpen ...
// OnOpen notified when RPC client session opened
func (h *RpcClientHandler) OnOpen(session getty.Session) error {
h.conn.addSession(session)
return nil
}
// OnError ...
// OnError notified when RPC client session got any error
func (h *RpcClientHandler) OnError(session getty.Session, err error) {
logger.Warnf("session{%s} got error{%v}, will be closed.", session.Stat(), err)
h.conn.removeSession(session)
}
// OnClose ...
// OnOpen notified when RPC client session closed
func (h *RpcClientHandler) OnClose(session getty.Session) {
logger.Infof("session{%s} is closing......", session.Stat())
h.conn.removeSession(session)
}
// OnMessage ...
// OnMessage notified when RPC client session got any message in connection
func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
p, ok := pkg.(*DubboPackage)
if !ok {
......@@ -141,7 +142,7 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
}
}
// OnCron ...
// OnCron notified when RPC client session got any message in cron job
func (h *RpcClientHandler) OnCron(session getty.Session) {
clientRpcSession, err := h.conn.getClientRpcSession(session)
if err != nil {
......@@ -163,7 +164,7 @@ func (h *RpcClientHandler) OnCron(session getty.Session) {
// RpcServerHandler
// //////////////////////////////////////////
// RpcServerHandler ...
// RpcServerHandler is handler of RPC Server
type RpcServerHandler struct {
maxSessionNum int
sessionTimeout time.Duration
......@@ -171,7 +172,7 @@ type RpcServerHandler struct {
rwlock sync.RWMutex
}
// NewRpcServerHandler ...
// NewRpcServerHandler creates RpcServerHandler with @maxSessionNum and @sessionTimeout
func NewRpcServerHandler(maxSessionNum int, sessionTimeout time.Duration) *RpcServerHandler {
return &RpcServerHandler{
maxSessionNum: maxSessionNum,
......@@ -180,7 +181,7 @@ func NewRpcServerHandler(maxSessionNum int, sessionTimeout time.Duration) *RpcSe
}
}
// OnOpen ...
// OnOpen notified when RPC server session opened
func (h *RpcServerHandler) OnOpen(session getty.Session) error {
var err error
h.rwlock.RLock()
......@@ -199,7 +200,7 @@ func (h *RpcServerHandler) OnOpen(session getty.Session) error {
return nil
}
// OnError ...
// OnError notified when RPC server session got any error
func (h *RpcServerHandler) OnError(session getty.Session, err error) {
logger.Warnf("session{%s} got error{%v}, will be closed.", session.Stat(), err)
h.rwlock.Lock()
......@@ -207,7 +208,7 @@ func (h *RpcServerHandler) OnError(session getty.Session, err error) {
h.rwlock.Unlock()
}
// OnClose ...
// OnOpen notified when RPC server session closed
func (h *RpcServerHandler) OnClose(session getty.Session) {
logger.Infof("session{%s} is closing......", session.Stat())
h.rwlock.Lock()
......@@ -215,7 +216,7 @@ func (h *RpcServerHandler) OnClose(session getty.Session) {
h.rwlock.Unlock()
}
// OnMessage ...
// OnMessage notified when RPC server session got any message in connection
func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
h.rwlock.Lock()
if _, ok := h.sessionMap[session]; ok {
......@@ -306,7 +307,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
reply(session, p, hessian.PackageResponse)
}
// OnCron ...
// OnCron notified when RPC server session got any message in cron job
func (h *RpcServerHandler) OnCron(session getty.Session) {
var (
flag bool
......@@ -363,7 +364,7 @@ func reply(session getty.Session, req *DubboPackage, tp hessian.PackageType) {
resp.Body = nil
}
if err := session.WritePkg(resp, WritePkg_Timeout); err != nil {
if err := session.WritePkg(resp, writePkg_Timeout); err != nil {
logger.Errorf("WritePkg error: %#v, %#v", perrors.WithStack(err), req.Header)
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment