rpc/server/servlet_handlers.go
crusader 6aa5c1536d ing
2017-11-29 01:19:03 +09:00

41 lines
1.1 KiB
Go

package server
import (
"fmt"
"git.loafle.net/commons_go/logging"
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/rpc/protocol"
)
type ServletHandlers struct {
rpc.RPCServletHandlers
RPCRegistry rpc.Registry
}
func (sh *ServletHandlers) Invoke(servletCTX rpc.RPCServletContext, requestCodec protocol.RegistryCodec) (result interface{}, err error) {
if !sh.RPCRegistry.HasMethod(requestCodec.Method()) {
return nil, fmt.Errorf("RPC Servlet Handler: Method[%s] is not exist", requestCodec.Method())
}
result, err = sh.RPCRegistry.Invoke(requestCodec)
if nil != err {
if params, pErr := requestCodec.Params(); nil != err {
logging.Logger().Error(fmt.Sprintf("RPC Servlet Handler: Read Param of Method[%s] returns error %v", requestCodec.Method(), pErr))
} else {
logging.Logger().Error(fmt.Sprintf("RPC Servlet Handler: Method[%s] params[%v] returns error %v", requestCodec.Method(), params, err))
}
}
return
}
func (sh *ServletHandlers) Validate() {
sh.RPCServletHandlers.Validate()
if nil == sh.RPCRegistry {
logging.Logger().Panic(fmt.Sprintf("RPC Servlet Handler: RPC Registry must be specified"))
}
}