remoting

package
v3.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 9 Imported by: 24

Documentation

Overview

Package remoting provides facilities for decoding and encoding, client and server.

Index

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 RegistryCodec(protocol string, codecTmp Codec)

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.

func GetCodec

func GetCodec(protocol string) Codec

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 Event

type Event struct {
	Path    string
	Action  EventType
	Content string
}

Event defines common elements for service event

func (Event) String

func (e Event) String() string

nolint

type EventType

type EventType int

EventType means SourceObjectEventType

const (
	// EventTypeAdd means add event
	EventTypeAdd EventType = iota
	// EventTypeDel means del event
	EventTypeDel
	EventTypeUpdate
)

func (EventType) String

func (t EventType) String() string

nolint

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) Close

func (client *ExchangeClient) Close()

Close close the client.

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

type ExchangeServer struct {
	Server Server
	URL    *common.URL
}

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 Options

type Options struct {
	ConnectTimeout time.Duration
}

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

func NewRequest(version string) *Request

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

func NewResponse(id int64, version string) *Response

NewResponse create to a new Response.

func (*Response) Handle

func (response *Response) Handle()

func (*Response) IsHeartbeat

func (response *Response) IsHeartbeat() bool

func (*Response) String

func (response *Response) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL