Documentation ¶
Overview ¶
Package remoting provides facilities for decoding and encoding, client and server.
Index ¶
- func AddPendingResponse(pr *PendingResponse)
- func RegistryCodec(protocol string, codecTmp Codec)
- func SequenceID() int64
- type AsyncCallbackResponse
- type Client
- type Codec
- type DataListener
- type DecodeResult
- type Event
- type EventType
- type ExchangeClient
- func (client *ExchangeClient) AsyncRequest(invocation *protocol.Invocation, url *common.URL, timeout time.Duration, ...) error
- func (client *ExchangeClient) Close()
- func (client *ExchangeClient) DecreaseActiveNumber() uint32
- func (client *ExchangeClient) GetActiveNumber() uint32
- func (client *ExchangeClient) IncreaseActiveNumber() uint32
- func (client *ExchangeClient) IsAvailable() bool
- func (client *ExchangeClient) Request(invocation *protocol.Invocation, url *common.URL, timeout time.Duration, ...) error
- func (client *ExchangeClient) Send(invocation *protocol.Invocation, url *common.URL, timeout time.Duration) error
- type ExchangeServer
- type Options
- type PendingResponse
- type Request
- type Response
- type SequenceType
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPendingResponse ¶
func AddPendingResponse(pr *PendingResponse)
AddPendingResponse stores the response into map
func RegistryCodec ¶
func SequenceID ¶
func SequenceID() int64
SequenceID increase 2 for every request as the same before. We expect that the request from client to server, the requestID is even; but from server to client, the requestID is odd.
Types ¶
type AsyncCallbackResponse ¶
type AsyncCallbackResponse struct { common.CallbackResponse Opts Options Cause error Start time.Time // invoke(call) start time == write start time ReadStart time.Time // read start time, write duration = ReadStart - Start Reply interface{} }
AsyncCallbackResponse async response for dubbo
type Client ¶
type Client interface { SetExchangeClient(client *ExchangeClient) Connect(url *common.URL) error Close() Request(request *Request, timeout time.Duration, response *PendingResponse) error IsAvailable() bool }
Client is the interface that wraps SetExchangeClient、 Connect、Close、Request and IsAvailable method. It is interface of client for network communication. If you use getty as network communication, you should define GettyClient that implements this interface.
SetExchangeClient method sets a ExchangeClient instance.
Connect method is to connect url.
Close method is for destroy.
Request method is sending request to server.
IsAvailable method checks whether the client is still available.
type Codec ¶
type Codec interface { EncodeRequest(request *Request) (*bytes.Buffer, error) EncodeResponse(response *Response) (*bytes.Buffer, error) Decode(data []byte) (*DecodeResult, int, error) }
Codec is the interface that wrap EncodeRequest、 EncodeResponse and Decode method for exchangeClient.
type DataListener ¶
type DataListener interface {
DataChange(event Event) bool // bool is return for interface implement is interesting
}
DataListener defines common data listener interface
type DecodeResult ¶
type DecodeResult struct { IsRequest bool // indicates whether the current request is a heartbeat request Result interface{} }
type ExchangeClient ¶
type ExchangeClient struct { ConnectTimeout time.Duration // timeout for connecting server // contains filtered or unexported fields }
ExchangeClient is abstraction level. it is like facade.
func NewExchangeClient ¶
func NewExchangeClient(url *common.URL, client Client, connectTimeout time.Duration, lazyInit bool) *ExchangeClient
NewExchangeClient returns a ExchangeClient.
func (*ExchangeClient) AsyncRequest ¶
func (client *ExchangeClient) AsyncRequest(invocation *protocol.Invocation, url *common.URL, timeout time.Duration, callback common.AsyncCallback, result *protocol.RPCResult) error
AsyncRequest async two way request.
func (*ExchangeClient) DecreaseActiveNumber ¶
func (client *ExchangeClient) DecreaseActiveNumber() uint32
DecreaseActiveNumber decrease number of service using client.
func (*ExchangeClient) GetActiveNumber ¶
func (client *ExchangeClient) GetActiveNumber() uint32
GetActiveNumber get number of service using client.
func (*ExchangeClient) IncreaseActiveNumber ¶
func (client *ExchangeClient) IncreaseActiveNumber() uint32
IncreaseActiveNumber increase number of service using client.
func (*ExchangeClient) IsAvailable ¶
func (client *ExchangeClient) IsAvailable() bool
IsAvailable to check if the underlying network client is available yet.
func (*ExchangeClient) Request ¶
func (client *ExchangeClient) Request(invocation *protocol.Invocation, url *common.URL, timeout time.Duration, result *protocol.RPCResult) error
Request means two way request.
func (*ExchangeClient) Send ¶
func (client *ExchangeClient) Send(invocation *protocol.Invocation, url *common.URL, timeout time.Duration) error
Send sends oneway request.
type ExchangeServer ¶
ExchangeServer is abstraction level. it is like facade. it implements Start and Stop.
func NewExchangeServer ¶
func NewExchangeServer(url *common.URL, server Server) *ExchangeServer
NewExchangeServer returns a ExchangeServer that constructs from url and server.
func (*ExchangeServer) Start ¶
func (server *ExchangeServer) Start()
func (*ExchangeServer) Stop ¶
func (server *ExchangeServer) Stop()
type PendingResponse ¶
type PendingResponse struct { Err error ReadStart time.Time Callback common.AsyncCallback Reply interface{} Done chan struct{} // contains filtered or unexported fields }
PendingResponse is the client sends request to server, there is one pendingResponse at client side to wait the response from server.
func GetPendingResponse ¶
func GetPendingResponse(seq SequenceType) *PendingResponse
GetPendingResponse gets the response
func NewPendingResponse ¶
func NewPendingResponse(id int64) *PendingResponse
NewPendingResponse aims to create PendingResponse. ID is always from ID of Request
func (PendingResponse) GetCallResponse ¶
func (r PendingResponse) GetCallResponse() common.CallbackResponse
GetCallResponse is used for callback of async. It is will return AsyncCallbackResponse.
func (*PendingResponse) SetResponse ¶
func (r *PendingResponse) SetResponse(response *Response)
type Request ¶
type Request struct { ID int64 Version string // protocol version SerialID byte // serial ID (ignore) Data interface{} TwoWay bool Event bool }
Request is the request for transport layer.
func NewRequest ¶
NewRequest aims to create Request. The ID is auto increase.
type Response ¶
type Response struct { ID int64 Version string SerialID byte Status uint8 Event bool Error error Result interface{} }
Response is the response for transport layer.
func NewResponse ¶
NewResponse create to a new Response.
func (*Response) IsHeartbeat ¶
type SequenceType ¶
type SequenceType int64
type Server ¶
type Server interface { Start() Stop() }
Server is the interface that wraps the basic Start method and Stop method. It is interface of server for network communication. If you use getty as network communication, you should define GettyServer that implements this interface.
Start method invokes once for connection.
Stop method is for destroy.