client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Self     = protocol.ProtoEvent
	Peer     = protocol.ProtoEventBus
	SelfName = "event"
	PeerName = "ebus"
)

Protocol identity information.

Variables

View Source
var (
	ErrShutdown         = errors.New("connection is shut down")
	ErrUnsupportedCodec = errors.New("unsupported codec")
	ErrInvalidEvent     = errors.New("invalid event")
)

Functions

This section is empty.

Types

type Call

type Call struct {
	ID            uint64
	ServicePath   string            // The name of the service and method to call.
	ServiceMethod string            // The name of the service and method to call.
	ReqMetadata   map[string]string // metadata
	ResMetadata   map[string]string
	Content       interface{}
	Args          interface{} // The argument to the function (*struct).
	Reply         interface{} // The reply from the function (*struct).
	Error         error       // After completion, the error status.
	Done          chan *Call  // Strobes when call is complete.
}

Call represents an active RPC.

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *Config, handler PipeHandler) *Client

func (*Client) Broadcast

func (c *Client) Broadcast(data []byte) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) Connect

func (c *Client) Connect(eventName string, addr string) error

func (*Client) Pipe

func (c *Client) Pipe(id uint32) protocol.Pipe

func (*Client) RangePipes

func (c *Client) RangePipes(f func(uint32, protocol.Pipe) bool)

func (*Client) Send

func (c *Client) Send(src, dest uint32, data []byte) error

func (*Client) SendData

func (c *Client) SendData(src, dest uint32, hash uint64, data []byte) error

func (*Client) SendMessage

func (c *Client) SendMessage(src uint32, dest uint32, hash uint64, m *mangos.Message) error

func (*Client) SetAutoReconnect

func (c *Client) SetAutoReconnect(v bool)

func (*Client) SetDataErrorContinue

func (c *Client) SetDataErrorContinue(v bool)

func (*Client) SetInterval

func (c *Client) SetInterval(v time.Duration)

func (*Client) SetReadTimeout

func (c *Client) SetReadTimeout(v time.Duration)

func (*Client) SetRecvSize

func (c *Client) SetRecvSize(v int)

func (*Client) SetSendSize

func (c *Client) SetSendSize(v int)

func (*Client) SetWriteTimeout

func (c *Client) SetWriteTimeout(v time.Duration)

func (*Client) Stop

func (c *Client) Stop()

func (*Client) String

func (c *Client) String() string

type Config

type Config struct {
	ServiceId         int           `json:"service_id" yaml:"service_id" toml:"service_id"`
	EventName         string        `json:"event" yaml:"event" toml:"event"`
	Address           string        `json:"address" yaml:"address" toml:"address"`
	SendChanSize      int           `json:"send_chan_size,omitempty" yaml:"send_chan_size,omitempty" toml:"send_chan_size,omitempty"`
	RecvChanSize      int           `json:"recv_chan_size,omitempty" yaml:"recv_chan_size,omitempty" toml:"recv_chan_size,omitempty"`
	DataErrorContinue bool          `json:"data_error_continue,omitempty" yaml:"data_error_continue,omitempty" toml:"data_error_continue,omitempty"`
	Reconnect         bool          `json:"reconnect,omitempty" yaml:"reconnect,omitempty" toml:"reconnect,omitempty"`
	Interval          time.Duration `json:"interval,omitempty" yaml:"interval,omitempty" toml:"interval,omitempty"`
	ReadTimeout       time.Duration `json:"read_timeout,omitempty" yaml:"read_timeout,omitempty" toml:"read_timeout,omitempty"`
	WriteTimeout      time.Duration `json:"write_timeout,omitempty" yaml:"write_timeout,omitempty" toml:"write_timeout,omitempty"`
}

type Options

type Options struct {
	SerializeType byte          `json:"serialize_type,omitempty" yaml:"serialize_type,omitempty" toml:"serialize_type,omitempty"`
	CompressType  byte          `json:"compress_type,omitempty" yaml:"compress_type,omitempty" toml:"compress_type,omitempty"`
	NotifyBlock   bool          `json:"notify_block,omitempty" yaml:"notify_block,omitempty" toml:"notify_block,omitempty"`
	IdleTimeout   time.Duration `json:"idle_timeout,omitempty" yaml:"idle_timeout,omitempty" toml:"idle_timeout,omitempty"`
	TraceMessage  bool          `json:"trace_message,omitempty" yaml:"trace_message,omitempty" toml:"trace_message,omitempty"`
}

type Pipe

type Pipe struct {
	// contains filtered or unexported fields
}

func (*Pipe) Close

func (p *Pipe) Close() error

func (*Pipe) Event

func (p *Pipe) Event() uint32

func (*Pipe) GetPrivate

func (p *Pipe) GetPrivate() interface{}

func (*Pipe) ID

func (p *Pipe) ID() uint32

func (*Pipe) LocalAddr

func (p *Pipe) LocalAddr() string

func (*Pipe) Pipe

func (p *Pipe) Pipe() mangos.Pipe

func (*Pipe) Pipes

func (p *Pipe) Pipes() map[uint32]*Pipe

func (*Pipe) RecvMsg

func (p *Pipe) RecvMsg() *mproto.Message

func (*Pipe) RemoteAddr

func (p *Pipe) RemoteAddr() string

func (*Pipe) RemoteID

func (p *Pipe) RemoteID() uint32

func (*Pipe) SendMsg

func (p *Pipe) SendMsg(m *mproto.Message) error

func (*Pipe) SetEvent

func (p *Pipe) SetEvent(v uint32)

func (*Pipe) SetPrivate

func (p *Pipe) SetPrivate(v interface{})

func (*Pipe) Stop

func (p *Pipe) Stop()

type PipeHandler

type PipeHandler interface {
	OnPipeConnected(p protocol.Pipe)
	OnPipeDataArrived(p protocol.Pipe, msg interface{}) error
	OnPipeClosed(p protocol.Pipe)
	OnPipeTimer(p protocol.Pipe)
}

type Protocol

type Protocol struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewProtocol

func NewProtocol() *Protocol

NewProtocol returns a new protocol implementation.

func (*Protocol) AddPipe

func (s *Protocol) AddPipe(pp mproto.Pipe) error

func (*Protocol) Close

func (s *Protocol) Close() error

func (*Protocol) GetOption

func (s *Protocol) GetOption(option string) (interface{}, error)

func (*Protocol) Info

func (*Protocol) Info() mproto.Info

func (*Protocol) OpenContext

func (s *Protocol) OpenContext() (mproto.Context, error)

func (*Protocol) Pipe

func (s *Protocol) Pipe(id uint32) protocol.Pipe

func (*Protocol) RangePipes

func (s *Protocol) RangePipes(f func(uint32, protocol.Pipe) bool)

func (*Protocol) RecvMsg

func (s *Protocol) RecvMsg() (*mproto.Message, error)

func (*Protocol) RemovePipe

func (s *Protocol) RemovePipe(pp mproto.Pipe)

func (*Protocol) SendMsg

func (s *Protocol) SendMsg(m *mproto.Message) error

func (*Protocol) SetOption

func (s *Protocol) SetOption(name string, value interface{}) error

func (*Protocol) SetPipeEventHook

func (s *Protocol) SetPipeEventHook(v protocol.PipeEventHook)

func (*Protocol) String added in v0.2.0

func (s *Protocol) String() string

type XClient

type XClient struct {
	*Client
	// contains filtered or unexported fields
}

func NewXClient

func NewXClient(cfg *Config, watchCfg *discovery.ClientConfig, handler PipeHandler) *XClient

func (*XClient) AddClient

func (c *XClient) AddClient(_ string, addr string)

func (*XClient) Call

func (c *XClient) Call(ctx context.Context, src, dest uint32, eventHash uint64,
	servicePath, serviceMethod string, args interface{}, reply interface{}) error

Call invokes the named function, waits for it to complete, and returns its error status.

func (*XClient) Go

func (c *XClient) Go(ctx context.Context, src, dest uint32, eventHash uint64,
	servicePath, serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call

Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.

func (*XClient) OnPipeClosed

func (c *XClient) OnPipeClosed(p protocol.Pipe)

func (*XClient) OnPipeConnected

func (c *XClient) OnPipeConnected(p protocol.Pipe)

func (*XClient) OnPipeDataArrived

func (c *XClient) OnPipeDataArrived(p protocol.Pipe, msg interface{}) error

func (*XClient) OnPipeTimer

func (c *XClient) OnPipeTimer(p protocol.Pipe)

func (*XClient) Pick

func (c *XClient) Pick(hash string) (protocol.Pipe, error)

func (*XClient) PickSend

func (c *XClient) PickSend(srcHash string, dest uint32, destHash uint64, data []byte) error

func (*XClient) RemoveClient

func (c *XClient) RemoveClient(_ string, addr string)

func (*XClient) Stop

func (c *XClient) Stop()

func (*XClient) UpdateClient

func (c *XClient) UpdateClient(_ string, addr string, conn any)

func (*XClient) Watch

func (c *XClient) Watch()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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