mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-15 16:34:44 +08:00
1.优化pending存储结构,支持超时判断
2.protobuf与json支持临时内存池
This commit is contained in:
@@ -2,11 +2,26 @@ package rpc
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type PBProcessor struct {
|
||||
}
|
||||
|
||||
var rpcPbResponeDataPool sync.Pool
|
||||
var rpcPbRequestDataPool sync.Pool
|
||||
|
||||
|
||||
func init(){
|
||||
rpcPbResponeDataPool.New = func()interface{}{
|
||||
return &JsonRpcResponseData{}
|
||||
}
|
||||
|
||||
rpcPbRequestDataPool.New = func()interface{}{
|
||||
return &JsonRpcRequestData{}
|
||||
}
|
||||
}
|
||||
|
||||
func (slf *PBRpcRequestData) MakeRequest(seq uint64,serviceMethod string,noReply bool,inParam []byte) *PBRpcRequestData{
|
||||
slf.Seq = proto.Uint64(seq)
|
||||
slf.ServiceMethod = proto.String(serviceMethod)
|
||||
@@ -23,15 +38,6 @@ func (slf *PBRpcResponseData) MakeRespone(seq uint64,err *RpcError,reply []byte)
|
||||
return slf
|
||||
}
|
||||
|
||||
func (slf *PBRpcRequestData) ReleaseRpcRequest(rpcRequestData IRpcRequestData){
|
||||
|
||||
}
|
||||
|
||||
func (slf *PBRpcRequestData) ReleaseRpcRespose(rpcRequestData IRpcRequestData){
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (slf *PBProcessor) Marshal(v interface{}) ([]byte, error){
|
||||
return proto.Marshal(v.(proto.Message))
|
||||
}
|
||||
@@ -43,13 +49,26 @@ func (slf *PBProcessor) Unmarshal(data []byte, msg interface{}) error{
|
||||
|
||||
|
||||
func (slf *PBProcessor) MakeRpcRequest(seq uint64,serviceMethod string,noReply bool,inParam []byte) IRpcRequestData{
|
||||
return (&PBRpcRequestData{}).MakeRequest(seq,serviceMethod,noReply,inParam)
|
||||
pPbRpcRequestData := rpcPbRequestDataPool.Get().(*PBRpcRequestData)
|
||||
pPbRpcRequestData.MakeRequest(seq,serviceMethod,noReply,inParam)
|
||||
return pPbRpcRequestData
|
||||
}
|
||||
|
||||
func (slf *PBProcessor) MakeRpcResponse(seq uint64,err *RpcError,reply []byte) IRpcResponseData {
|
||||
return (&PBRpcResponseData{}).MakeRespone(seq,err,reply)
|
||||
pPBRpcResponseData := rpcPbResponeDataPool.Get().(*PBRpcResponseData)
|
||||
pPBRpcResponseData.MakeRespone(seq,err,reply)
|
||||
return pPBRpcResponseData
|
||||
}
|
||||
|
||||
func (slf *PBProcessor) ReleaseRpcRequest(rpcRequestData IRpcRequestData){
|
||||
rpcPbRequestDataPool.Put(rpcRequestData)
|
||||
}
|
||||
|
||||
func (slf *PBProcessor) ReleaseRpcRespose(rpcRequestData IRpcRequestData){
|
||||
rpcPbResponeDataPool.Put(rpcRequestData)
|
||||
}
|
||||
|
||||
|
||||
func (slf *PBRpcRequestData) IsReply() bool{
|
||||
return slf.GetNoReply()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user