Documentation ¶
Index ¶
- Constants
- Variables
- func AcquireTimer(timeout time.Duration) *time.Timer
- func IsDeadlineError(err error) bool
- func ReadCommand(ro *ReadOption, br io.Reader, cmd *Command) (int, error)
- func ReleaseInvokeContext(ictx *InvokeContext)
- func ReleaseRequest(di *Request)
- func ReleaseResponse(di *Response)
- func ReleaseSofaResponseWriter(crw *SofaResponseWriter)
- func ReleaseTimer(t *time.Timer)
- func WithServerAsync(t bool) serverOptionSetter
- func WithServerHandler(fn Handler) serverOptionSetter
- func WithServerMaxConnctions(m int) serverOptionSetter
- func WithServerMaxPendingCommands(m int) serverOptionSetter
- func WithServerMetrics(sm *ServerMetrics) serverOptionSetter
- func WithServerOnEventHandler(e ServerOnEventHandler) serverOptionSetter
- func WithServerTimeout(readTimeout, writeTimeout, idleTimeout, flushInterval time.Duration) serverOptionSetter
- func WriteCommand(wo *WriteOption, b []byte, cmd *Command) ([]byte, error)
- type CMDCode
- type Client
- func (c *Client) AcquireInvokeContext(req *Request, res *Response, timeout time.Duration) *InvokeContext
- func (c *Client) Close() error
- func (c *Client) Closed() bool
- func (c *Client) Do(req *Request, res *Response) error
- func (c *Client) DoCallback(req *Request, cb ClientCallbacker) error
- func (c *Client) DoCallbackTimeout(req *Request, cb ClientCallbacker, timeout time.Duration) error
- func (c *Client) DoTimeout(req *Request, res *Response, timeout time.Duration) error
- func (c *Client) GetConn() net.Conn
- func (c *Client) GetMetrics() *ClientMetrics
- func (c *Client) GetReadError() chan error
- func (c *Client) ReleaseInvokeContext(ictx *InvokeContext)
- type ClientCallbacker
- type ClientCallbackerFunc
- type ClientConn
- func (x *ClientConn) Close() error
- func (x *ClientConn) Closed() bool
- func (x *ClientConn) Dispatch(err error, cmd interface{})
- func (x *ClientConn) DoDispatch(wg *sync.WaitGroup, err error, cmd interface{})
- func (x *ClientConn) GetConn() net.Conn
- func (x *ClientConn) GetMetrics() *ClientMetrics
- func (x *ClientConn) GetStatus() ClientConnStatus
- func (x *ClientConn) IncrementID() uint64
- func (x *ClientConn) OnStatusChange(to ClientConnStatus)
- func (x *ClientConn) Send(o interface{}) error
- func (x *ClientConn) Write(b []byte) (int, error)
- type ClientConnDispatcher
- type ClientConnDispatcherFunc
- type ClientConnDoer
- type ClientConnOptionSetter
- type ClientConnOptionSetterFunc
- func WithClientConnConn(conn net.Conn) ClientConnOptionSetterFunc
- func WithClientConnDispatcher(dispatcher ClientConnDispatcher) ClientConnOptionSetterFunc
- func WithClientConnMaxPendingCommands(m int) ClientConnOptionSetterFunc
- func WithClientConnMetrics(cm *ClientMetrics) ClientConnOptionSetterFunc
- func WithClientConnProtocolDecoder(dec ClientConnProtocolDecoder) ClientConnOptionSetterFunc
- func WithClientConnProtocolEncoder(enc ClientConnProtocolEncoder) ClientConnOptionSetterFunc
- func WithClientConnRedial(dialer Dialer) ClientConnOptionSetterFunc
- func WithClientConnStatusChanger(changer ClientConnStatusChanger) ClientConnOptionSetterFunc
- func WithClientConnTimeout(readtimeout, writetimeout, idletimeout time.Duration, ...) ClientConnOptionSetterFunc
- type ClientConnOptions
- type ClientConnProtocolDecoder
- type ClientConnProtocolDecoderFunc
- type ClientConnProtocolDecoderOption
- type ClientConnProtocolEncoder
- type ClientConnProtocolEncoderFunc
- type ClientConnProtocolEncoderOption
- type ClientConnProtocolIDIncrementer
- type ClientConnStatus
- type ClientConnStatusChanger
- type ClientConnStatusChangerFunc
- type ClientMetrics
- func (cm *ClientMetrics) AddReferences(n int64) int64
- func (cm *ClientMetrics) AddUsed(n int64) int64
- func (cm *ClientMetrics) GetBytesRead() int64
- func (cm *ClientMetrics) GetBytesWrite() int64
- func (cm *ClientMetrics) GetCommands() int64
- func (cm *ClientMetrics) GetCreated() int64
- func (cm *ClientMetrics) GetLasted() int64
- func (cm *ClientMetrics) GetPendingCommands() int64
- func (cm *ClientMetrics) GetReferences() int64
- func (cm *ClientMetrics) GetUsed() int64
- func (cm *ClientMetrics) ResetPendingCommands()
- func (cm *ClientMetrics) SetLasted()
- type ClientOptionSetter
- type ClientOptionSetterFunc
- func WithClientConn(conn net.Conn) ClientOptionSetterFunc
- func WithClientDisableAutoIncrementRequestID(b bool) ClientOptionSetterFunc
- func WithClientHandler(handler Handler) ClientOptionSetterFunc
- func WithClientHeartbeat(heartbeatinterval, heartbeattimeout time.Duration, heartbeatprobes int, ...) ClientOptionSetterFunc
- func WithClientMaxPendingCommands(m int) ClientOptionSetterFunc
- func WithClientMetrics(cm *ClientMetrics) ClientOptionSetterFunc
- func WithClientRedial(dialer Dialer) ClientOptionSetterFunc
- func WithClientTimeout(readtimeout, writetimeout, idletimeout time.Duration, ...) ClientOptionSetterFunc
- type Codec
- type Command
- func (c *Command) CopyTo(d *Command)
- func (c *Command) GetCMDCode() CMDCode
- func (c *Command) GetClass() []byte
- func (c *Command) GetCodec() Codec
- func (c *Command) GetConnection() []byte
- func (c *Command) GetContent() []byte
- func (c *Command) GetHeaders() *SimpleMap
- func (c *Command) GetProto() Proto
- func (c *Command) GetRequestID() uint32
- func (c *Command) GetStatus() Status
- func (c *Command) GetSwitc() uint8
- func (c *Command) GetTimeout() uint32
- func (c *Command) GetType() Type
- func (c *Command) GetVer1() Version
- func (c *Command) GetVer2() uint8
- func (c *Command) IsRequest() bool
- func (c *Command) Read(ro *ReadOption, br io.Reader) (int, error)
- func (c *Command) Reset()
- func (c *Command) SetCMDCode(cmd CMDCode)
- func (c *Command) SetClass(class []byte)
- func (c *Command) SetClassString(class string)
- func (c *Command) SetCodec(codec Codec)
- func (c *Command) SetConnection(connection []byte)
- func (c *Command) SetContent(content []byte)
- func (c *Command) SetContentString(content string)
- func (c *Command) SetProto(p Proto)
- func (c *Command) SetRequestID(id uint32)
- func (c *Command) SetStatus(s Status)
- func (c *Command) SetSwitc(s uint8)
- func (c *Command) SetTimeout(t uint32)
- func (c *Command) SetType(t Type)
- func (c *Command) SetVer1(v Version)
- func (c *Command) SetVer2(v uint8)
- func (c *Command) ShallowCopyTo(d *Command)
- func (c *Command) Size() int
- func (c *Command) String() string
- func (c *Command) Write(wo *WriteOption, b []byte) ([]byte, error)
- type Dialer
- type DialerFunc
- type Handler
- type HandlerFunc
- type InvokeContext
- func (i *InvokeContext) AssignResponse(res *Response)
- func (i *InvokeContext) CopyResponse(res *Response)
- func (i *InvokeContext) GetCallback() ClientCallbacker
- func (i *InvokeContext) GetCreated() time.Time
- func (i *InvokeContext) GetDeadline() time.Time
- func (i *InvokeContext) GetErrorCh() chan error
- func (i *InvokeContext) GetRequest() *Request
- func (i *InvokeContext) GetResponse() *Response
- func (i *InvokeContext) GetTimeout() time.Duration
- func (i *InvokeContext) Invoke(err error, res *Response)
- func (i *InvokeContext) SetCallback(cb ClientCallbacker) *InvokeContext
- func (i *InvokeContext) SetTimeout(t time.Duration) *InvokeContext
- type KeepAliver
- func (ca *KeepAliver) Del(tls bool, address string, client *Client) bool
- func (t *KeepAliver) Get(tls bool, addr string) (*Client, bool)
- func (k *KeepAliver) GracefullyClose(client *Client)
- func (ca *KeepAliver) Put(tls bool, force bool, addr string, client *Client) bool
- func (k *KeepAliver) ServeHTTP(rw http.ResponseWriter, r *http.Request)
- type KeepAliverOptions
- type Pool
- func (p *Pool) Delete(client *Client)
- func (p *Pool) DeleteClients(clients []*Client)
- func (p *Pool) DeleteLocked(client *Client)
- func (p *Pool) Get() (*Client, bool)
- func (p *Pool) Iterate(fn func(client *Client))
- func (p *Pool) MarshalJSON() ([]byte, error)
- func (p *Pool) Push(client *Client)
- func (p *Pool) Size() int
- type PoolMap
- type Proto
- type ReadOption
- type Request
- func (c *Request) CopyCommand(cmd *Command) *Request
- func (c *Request) CopyTo(d *Request) *Request
- func (c *Request) GetCMDCode() CMDCode
- func (c *Request) GetClass() []byte
- func (c *Request) GetCodec() Codec
- func (c *Request) GetConnection() []byte
- func (c *Request) GetContent() []byte
- func (c *Request) GetContext() context.Context
- func (c *Request) GetHeaders() *SimpleMap
- func (c *Request) GetProto() Proto
- func (c *Request) GetRequestID() uint32
- func (c *Request) GetStatus() Status
- func (c *Request) GetSwitc() uint8
- func (c *Request) GetTBRemotingConnection() *javaobject.TBRemotingConnectionRequest
- func (c *Request) GetTimeout() uint32
- func (c *Request) GetType() Type
- func (c *Request) GetVer1() Version
- func (c *Request) GetVer2() uint8
- func (c *Request) Read(ro *ReadOption, r io.Reader) (int, error)
- func (c *Request) Reset()
- func (c *Request) SetCMDCode(cmd CMDCode) *Request
- func (c *Request) SetClass(class []byte) *Request
- func (c *Request) SetClassString(class string) *Request
- func (c *Request) SetCodec(codec Codec) *Request
- func (c *Request) SetConnection(connection []byte) *Request
- func (c *Request) SetContent(content []byte) *Request
- func (c *Request) SetContentString(content string) *Request
- func (c *Request) SetContext(ctx context.Context) *Request
- func (c *Request) SetProto(p Proto) *Request
- func (c *Request) SetRequestID(id uint32) *Request
- func (c *Request) SetStatus(s Status) *Request
- func (c *Request) SetSwitc(s uint8) *Request
- func (c *Request) SetTimeout(t uint32) *Request
- func (c *Request) SetType(t Type) *Request
- func (c *Request) SetVer1(v Version) *Request
- func (c *Request) SetVer2(v uint8) *Request
- func (c *Request) ShallowCopyCommand(cmd *Command) *Request
- func (c *Request) Size() int
- func (c *Request) String() string
- func (c *Request) Write(wo *WriteOption, b []byte) ([]byte, error)
- type Response
- func (c *Response) CopyCommand(cmd *Command) *Response
- func (c *Response) CopyTo(d *Response) *Response
- func (c *Response) Derive(b *Request)
- func (c *Response) GetCMDCode() CMDCode
- func (c *Response) GetClass() []byte
- func (c *Response) GetCodec() Codec
- func (c *Response) GetContent() []byte
- func (c *Response) GetHeaders() *SimpleMap
- func (c *Response) GetProto() Proto
- func (c *Response) GetRequestID() uint32
- func (c *Response) GetStatus() Status
- func (c *Response) GetSwitc() uint8
- func (c *Response) GetTBRemotingConnection() *javaobject.TBRemotingConnectionResponse
- func (c *Response) GetTimeout() uint32
- func (c *Response) GetType() Type
- func (c *Response) GetVer1() Version
- func (c *Response) GetVer2() uint8
- func (c *Response) Read(ro *ReadOption, r io.Reader) (int, error)
- func (c *Response) Reset()
- func (c *Response) SetCMDCode(cmd CMDCode) *Response
- func (c *Response) SetClass(class []byte) *Response
- func (c *Response) SetClassString(class string) *Response
- func (c *Response) SetCodec(codec Codec) *Response
- func (c *Response) SetConnection(content []byte) *Response
- func (c *Response) SetContent(content []byte) *Response
- func (c *Response) SetContentString(content string) *Response
- func (c *Response) SetProto(p Proto) *Response
- func (c *Response) SetRequestID(id uint32) *Response
- func (c *Response) SetStatus(s Status) *Response
- func (c *Response) SetSwitc(s uint8) *Response
- func (c *Response) SetTimeout(t uint32) *Response
- func (c *Response) SetType(t Type) *Response
- func (c *Response) SetVer1(v Version) *Response
- func (c *Response) SetVer2(v uint8) *Response
- func (c *Response) ShallowCopyCommand(cmd *Command) *Response
- func (c *Response) Size() int
- func (c *Response) String() string
- func (c *Response) Write(wo *WriteOption, b []byte) ([]byte, error)
- type ResponseWriter
- type Server
- func (srv *Server) GetMetrics() *ServerMetrics
- func (srv *Server) HandleCommand(wg *sync.WaitGroup, conn net.Conn, bw *bufiorw.Writer, rw *SofaResponseWriter, ...) bool
- func (srv *Server) Serve(ln net.Listener) error
- func (srv *Server) ServeConn(conn net.Conn) error
- func (srv *Server) ServeJob(v interface{})
- func (srv *Server) Shutdown(ctx context.Context) error
- type ServerEvent
- type ServerEventContext
- type ServerMetrics
- type ServerOnEventHandler
- type SimpleMap
- type SofaResponseWriter
- func (rw *SofaResponseWriter) Derive(req *Request)
- func (rw *SofaResponseWriter) GetConn() net.Conn
- func (rw *SofaResponseWriter) GetID() uint64
- func (rw *SofaResponseWriter) GetResponse() *Response
- func (rw *SofaResponseWriter) GetWriteError() error
- func (rw *SofaResponseWriter) GetWriter() io.Writer
- func (rw *SofaResponseWriter) Hijack() (net.Conn, bool)
- func (rw *SofaResponseWriter) IsHijacked() bool
- func (rw *SofaResponseWriter) Reset(w io.Writer) *SofaResponseWriter
- func (rw *SofaResponseWriter) Write() (int, error)
- type Status
- type TestResponseWriter
- func (rw *TestResponseWriter) GetConn() net.Conn
- func (rw *TestResponseWriter) GetID() uint64
- func (rw *TestResponseWriter) GetResponse() *Response
- func (rw *TestResponseWriter) GetWriteError() error
- func (rw *TestResponseWriter) GetWriter() io.Writer
- func (rw *TestResponseWriter) Hijack() (net.Conn, bool)
- func (rw *TestResponseWriter) Write() (int, error)
- type Type
- type Version
- type WriteOption
Examples ¶
Constants ¶
const ( ClassRequest = "com.alipay.sofa.rpc.core.request.SofaRequest" ClassResponse = "com.alipay.sofa.rpc.core.response.SofaResponse" )
Variables ¶
var ( ClassRequestBytes = []byte(ClassRequest) ClassResponseBytes = []byte(ClassResponse) )
var ( ErrBufferNotEnough = errors.New("sofabolt: buffer not enough") ErrMalformedProto = errors.New("sofabolt: malformed proto") ErrMalformedType = errors.New("sofabolt: malformed type") ErrServerHandler = errors.New("sofabolt: server handler cannot be nil") ErrServerNotARequest = errors.New("sofabolt: server received a response") ErrClientExpectResponse = errors.New("sofabolt: receive a request") ErrClientTimeout = errors.New("sofabolt: client do timeout") ErrClientNotARequest = errors.New("sofabolt: client send a response") ErrClientWasClosed = errors.New("sofabolt: client was closed") ErrClientTooManyRequests = errors.New("sofabolt: client too many requests") ErrClientServerTimeout = errors.New("sofabolt: clientserver do timeout") ErrClientDisableRedial = errors.New("sofabolt: disable redial") ErrClientNilConnection = errors.New("sofabolt: client connection is nil") )
var DummyServerOnEventHandler = ServerOnEventHandler(func(*Server, error, *ServerEventContext) {
})
Functions ¶
func IsDeadlineError ¶
func ReadCommand ¶
ReadCommand reads a command from io.Reader.
func ReleaseInvokeContext ¶
func ReleaseInvokeContext(ictx *InvokeContext)
func ReleaseRequest ¶
func ReleaseRequest(di *Request)
func ReleaseResponse ¶
func ReleaseResponse(di *Response)
func ReleaseSofaResponseWriter ¶
func ReleaseSofaResponseWriter(crw *SofaResponseWriter)
func ReleaseTimer ¶
func WithServerAsync ¶
func WithServerAsync(t bool) serverOptionSetter
func WithServerHandler ¶
func WithServerHandler(fn Handler) serverOptionSetter
func WithServerMaxConnctions ¶
func WithServerMaxConnctions(m int) serverOptionSetter
func WithServerMaxPendingCommands ¶
func WithServerMaxPendingCommands(m int) serverOptionSetter
func WithServerMetrics ¶
func WithServerMetrics(sm *ServerMetrics) serverOptionSetter
func WithServerOnEventHandler ¶
func WithServerOnEventHandler(e ServerOnEventHandler) serverOptionSetter
func WithServerTimeout ¶
func WriteCommand ¶
func WriteCommand(wo *WriteOption, b []byte, cmd *Command) ([]byte, error)
WriteCommand writes the command to []byte.
Types ¶
type Client ¶
func NewClient ¶
func NewClient(options ...ClientOptionSetter) (*Client, error)
func (*Client) AcquireInvokeContext ¶
func (*Client) DoCallback ¶
func (c *Client) DoCallback(req *Request, cb ClientCallbacker) error
func (*Client) DoCallbackTimeout ¶
func (*Client) GetMetrics ¶
func (c *Client) GetMetrics() *ClientMetrics
func (*Client) GetReadError ¶
func (*Client) ReleaseInvokeContext ¶
func (c *Client) ReleaseInvokeContext(ictx *InvokeContext)
type ClientCallbacker ¶
type ClientCallbacker interface {
Invoke(error, *InvokeContext)
}
type ClientCallbackerFunc ¶
type ClientCallbackerFunc func(error, *InvokeContext)
func (ClientCallbackerFunc) Invoke ¶
func (c ClientCallbackerFunc) Invoke(err error, cctx *InvokeContext)
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
func NewClientConn ¶
func NewClientConn(options ...ClientConnOptionSetter) (*ClientConn, error)
func (*ClientConn) Close ¶
func (x *ClientConn) Close() error
func (*ClientConn) Closed ¶
func (x *ClientConn) Closed() bool
func (*ClientConn) Dispatch ¶
func (x *ClientConn) Dispatch(err error, cmd interface{})
func (*ClientConn) DoDispatch ¶
func (x *ClientConn) DoDispatch(wg *sync.WaitGroup, err error, cmd interface{})
func (*ClientConn) GetConn ¶
func (x *ClientConn) GetConn() net.Conn
func (*ClientConn) GetMetrics ¶
func (x *ClientConn) GetMetrics() *ClientMetrics
func (*ClientConn) GetStatus ¶
func (x *ClientConn) GetStatus() ClientConnStatus
func (*ClientConn) IncrementID ¶
func (x *ClientConn) IncrementID() uint64
func (*ClientConn) OnStatusChange ¶
func (x *ClientConn) OnStatusChange(to ClientConnStatus)
func (*ClientConn) Send ¶
func (x *ClientConn) Send(o interface{}) error
type ClientConnDispatcher ¶
type ClientConnDispatcher interface {
Dispatch(err error, cmd interface{})
}
type ClientConnDispatcherFunc ¶
type ClientConnDispatcherFunc func(err error, cmd interface{})
func (ClientConnDispatcherFunc) Dispatch ¶
func (cd ClientConnDispatcherFunc) Dispatch(err error, cmd interface{})
type ClientConnDoer ¶
type ClientConnDoer interface { Send(o interface{}) error Dispatch(err error, cmd interface{}) GetStatus() ClientConnStatus IncrementID() uint64 Close() error }
type ClientConnOptionSetter ¶
type ClientConnOptionSetter interface {
Set(*ClientConn)
}
ClientConnOptionSetter configures a ClientConn.
type ClientConnOptionSetterFunc ¶
type ClientConnOptionSetterFunc func(*ClientConn)
func WithClientConnConn ¶
func WithClientConnConn(conn net.Conn) ClientConnOptionSetterFunc
func WithClientConnDispatcher ¶
func WithClientConnDispatcher(dispatcher ClientConnDispatcher) ClientConnOptionSetterFunc
func WithClientConnMaxPendingCommands ¶
func WithClientConnMaxPendingCommands(m int) ClientConnOptionSetterFunc
func WithClientConnMetrics ¶
func WithClientConnMetrics(cm *ClientMetrics) ClientConnOptionSetterFunc
func WithClientConnProtocolDecoder ¶
func WithClientConnProtocolDecoder(dec ClientConnProtocolDecoder) ClientConnOptionSetterFunc
func WithClientConnProtocolEncoder ¶
func WithClientConnProtocolEncoder(enc ClientConnProtocolEncoder) ClientConnOptionSetterFunc
func WithClientConnRedial ¶
func WithClientConnRedial(dialer Dialer) ClientConnOptionSetterFunc
func WithClientConnStatusChanger ¶
func WithClientConnStatusChanger(changer ClientConnStatusChanger) ClientConnOptionSetterFunc
func WithClientConnTimeout ¶
func WithClientConnTimeout(readtimeout, writetimeout, idletimeout time.Duration, flushInterval time.Duration) ClientConnOptionSetterFunc
func (ClientConnOptionSetterFunc) Set ¶
func (f ClientConnOptionSetterFunc) Set(c *ClientConn)
type ClientConnOptions ¶
type ClientConnOptions struct {
// contains filtered or unexported fields
}
type ClientConnProtocolDecoder ¶
type ClientConnProtocolDecoder interface {
Decode(do *ClientConnProtocolDecoderOption, r io.Reader) (cmd interface{}, err error)
}
type ClientConnProtocolDecoderFunc ¶
type ClientConnProtocolDecoderFunc func(do *ClientConnProtocolDecoderOption, r io.Reader) (cmd interface{}, err error)
func (ClientConnProtocolDecoderFunc) Decode ¶
func (ccp ClientConnProtocolDecoderFunc) Decode(do *ClientConnProtocolDecoderOption, r io.Reader) (cmd interface{}, err error)
type ClientConnProtocolDecoderOption ¶
type ClientConnProtocolDecoderOption struct { }
func NewClientConnProtocolDecoderOption ¶
func NewClientConnProtocolDecoderOption() *ClientConnProtocolDecoderOption
type ClientConnProtocolEncoder ¶
type ClientConnProtocolEncoder interface {
Encode(eo *ClientConnProtocolEncoderOption, dst []byte, cmd interface{}) ([]byte, error)
}
type ClientConnProtocolEncoderFunc ¶
type ClientConnProtocolEncoderFunc func(*ClientConnProtocolEncoderOption, []byte, interface{}) ([]byte, error)
func (ClientConnProtocolEncoderFunc) Encode ¶
func (ccp ClientConnProtocolEncoderFunc) Encode(eo *ClientConnProtocolEncoderOption, dst []byte, cmd interface{}) ([]byte, error)
type ClientConnProtocolEncoderOption ¶
type ClientConnProtocolEncoderOption struct { }
func NewClientConnProtocolEncoderOption ¶
func NewClientConnProtocolEncoderOption() *ClientConnProtocolEncoderOption
type ClientConnProtocolIDIncrementer ¶
type ClientConnProtocolIDIncrementer interface {
IncrementID() uint64
}
type ClientConnStatus ¶
type ClientConnStatus uint32
const ( IdleClientConnStatus ClientConnStatus = iota ConnectingClientConnStatus ReadTimeoutClientConnStatus ActiveClientConnStatus TransientFailureClientConnStatus ShutdownClientConnStatus )
func (ClientConnStatus) String ¶
func (cs ClientConnStatus) String() string
type ClientConnStatusChanger ¶
type ClientConnStatusChanger interface {
OnStatusChange(cc *ClientConn, from, to ClientConnStatus)
}
type ClientConnStatusChangerFunc ¶
type ClientConnStatusChangerFunc func(cc *ClientConn, from, to ClientConnStatus)
func (ClientConnStatusChangerFunc) OnStatusChange ¶
func (cs ClientConnStatusChangerFunc) OnStatusChange(cc *ClientConn, from, to ClientConnStatus)
type ClientMetrics ¶
type ClientMetrics struct {
// contains filtered or unexported fields
}
func (*ClientMetrics) AddReferences ¶
func (cm *ClientMetrics) AddReferences(n int64) int64
func (*ClientMetrics) AddUsed ¶
func (cm *ClientMetrics) AddUsed(n int64) int64
func (*ClientMetrics) GetBytesRead ¶
func (cm *ClientMetrics) GetBytesRead() int64
func (*ClientMetrics) GetBytesWrite ¶
func (cm *ClientMetrics) GetBytesWrite() int64
func (*ClientMetrics) GetCommands ¶
func (cm *ClientMetrics) GetCommands() int64
func (*ClientMetrics) GetCreated ¶
func (cm *ClientMetrics) GetCreated() int64
func (*ClientMetrics) GetLasted ¶
func (cm *ClientMetrics) GetLasted() int64
func (*ClientMetrics) GetPendingCommands ¶
func (cm *ClientMetrics) GetPendingCommands() int64
func (*ClientMetrics) GetReferences ¶
func (cm *ClientMetrics) GetReferences() int64
func (*ClientMetrics) GetUsed ¶
func (cm *ClientMetrics) GetUsed() int64
func (*ClientMetrics) ResetPendingCommands ¶
func (cm *ClientMetrics) ResetPendingCommands()
func (*ClientMetrics) SetLasted ¶
func (cm *ClientMetrics) SetLasted()
type ClientOptionSetter ¶
type ClientOptionSetter interface {
Set(*Client)
}
ClientOptionSetter configures a client.
type ClientOptionSetterFunc ¶
type ClientOptionSetterFunc func(*Client)
func WithClientConn ¶
func WithClientConn(conn net.Conn) ClientOptionSetterFunc
func WithClientDisableAutoIncrementRequestID ¶
func WithClientDisableAutoIncrementRequestID(b bool) ClientOptionSetterFunc
func WithClientHandler ¶
func WithClientHandler(handler Handler) ClientOptionSetterFunc
func WithClientHeartbeat ¶
func WithClientHeartbeat(heartbeatinterval, heartbeattimeout time.Duration, heartbeatprobes int, onheartbeat func(success bool)) ClientOptionSetterFunc
func WithClientMaxPendingCommands ¶
func WithClientMaxPendingCommands(m int) ClientOptionSetterFunc
func WithClientMetrics ¶
func WithClientMetrics(cm *ClientMetrics) ClientOptionSetterFunc
func WithClientRedial ¶
func WithClientRedial(dialer Dialer) ClientOptionSetterFunc
func WithClientTimeout ¶
func WithClientTimeout(readtimeout, writetimeout, idletimeout time.Duration, flushInterval time.Duration) ClientOptionSetterFunc
func (ClientOptionSetterFunc) Set ¶
func (f ClientOptionSetterFunc) Set(c *Client)
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Example ¶
req := AcquireRequest() d, err := req.Write(NewWriteOption(), nil) if err != nil { log.Fatal(err) } newreq := AcquireRequest() _, err = newreq.Read(NewReadOption(), bytes.NewReader(d)) if err != nil { log.Fatal(err) } res := AcquireResponse() d, err = res.Write(NewWriteOption(), nil) if err != nil { log.Fatal(err) } newres := AcquireResponse() _, err = newres.Read(NewReadOption(), bytes.NewReader(d)) if err != nil { log.Fatal(err) } fmt.Println(req.String() == newreq.String()) fmt.Println(res.String() == newres.String())
Output: true true
func (*Command) GetCMDCode ¶
func (*Command) GetConnection ¶
func (*Command) GetContent ¶
func (*Command) GetHeaders ¶
func (*Command) GetRequestID ¶
func (*Command) GetTimeout ¶
func (*Command) SetCMDCode ¶
func (*Command) SetClassString ¶
func (*Command) SetConnection ¶
func (*Command) SetContent ¶
func (*Command) SetContentString ¶
func (*Command) SetRequestID ¶
func (*Command) SetTimeout ¶
func (*Command) ShallowCopyTo ¶
type DialerFunc ¶
type Handler ¶
type Handler interface {
ServeSofaBOLT(rw ResponseWriter, req *Request)
}
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
func (HandlerFunc) ServeSofaBOLT ¶
func (s HandlerFunc) ServeSofaBOLT(rw ResponseWriter, req *Request)
type InvokeContext ¶
type InvokeContext struct {
// contains filtered or unexported fields
}
func AcquireInvokeContext ¶
func AcquireInvokeContext(req *Request, res *Response, timeout time.Duration) *InvokeContext
func NewInvokeContext ¶
func NewInvokeContext(req *Request) *InvokeContext
func (*InvokeContext) AssignResponse ¶
func (i *InvokeContext) AssignResponse(res *Response)
func (*InvokeContext) CopyResponse ¶
func (i *InvokeContext) CopyResponse(res *Response)
func (*InvokeContext) GetCallback ¶
func (i *InvokeContext) GetCallback() ClientCallbacker
func (*InvokeContext) GetCreated ¶
func (i *InvokeContext) GetCreated() time.Time
func (*InvokeContext) GetDeadline ¶
func (i *InvokeContext) GetDeadline() time.Time
func (*InvokeContext) GetErrorCh ¶
func (i *InvokeContext) GetErrorCh() chan error
func (*InvokeContext) GetRequest ¶
func (i *InvokeContext) GetRequest() *Request
func (*InvokeContext) GetResponse ¶
func (i *InvokeContext) GetResponse() *Response
func (*InvokeContext) GetTimeout ¶
func (i *InvokeContext) GetTimeout() time.Duration
func (*InvokeContext) Invoke ¶
func (i *InvokeContext) Invoke(err error, res *Response)
func (*InvokeContext) SetCallback ¶
func (i *InvokeContext) SetCallback(cb ClientCallbacker) *InvokeContext
func (*InvokeContext) SetTimeout ¶
func (i *InvokeContext) SetTimeout(t time.Duration) *InvokeContext
type KeepAliver ¶
type KeepAliver struct {
// contains filtered or unexported fields
}
func NewKeepAliver ¶
func NewKeepAliver(o *KeepAliverOptions, logger sofalogger.Logger) (*KeepAliver, error)
func (*KeepAliver) GracefullyClose ¶
func (k *KeepAliver) GracefullyClose(client *Client)
func (*KeepAliver) ServeHTTP ¶
func (k *KeepAliver) ServeHTTP(rw http.ResponseWriter, r *http.Request)
type KeepAliverOptions ¶
type KeepAliverOptions struct { Context context.Context `json:"-"` MaClientConnUsed int `json:"max_client_used"` MinClientInPool int `json:"min_clinet_in_pool"` HeartbeatInterval time.Duration `json:"heartbeat_interval"` HeartbeatTimeout time.Duration `json:"heartbeat_timeout"` CleanupInterval time.Duration `json:"cleanup_interval"` CleanupMaxChecks int `json:"cleanup_max_checks"` }
type PoolMap ¶
type PoolMap struct {
// contains filtered or unexported fields
}
Map is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines without additional locking or coordination. Loads, stores, and deletes run in amortized constant time.
The Map type is specialized. Most code should use a plain Go map instead, with separate locking or coordination, for better type safety and to make it easier to maintain other invariants along with the map content.
The Map type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.
The zero Map is empty and ready for use. A Map must not be copied after first use.
func (*PoolMap) Load ¶
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.
func (*PoolMap) LoadOrStore ¶
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*PoolMap) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.
Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func AcquireRequest ¶
func AcquireRequest() *Request
func (*Request) CopyCommand ¶
func (*Request) CopyTo ¶
NOTE: ctx is not copied here (and should not be). If ctx sharing is desired, caller should explicitly copy it.
func (*Request) GetCMDCode ¶
func (*Request) GetConnection ¶
func (*Request) GetContent ¶
func (*Request) GetContext ¶
func (*Request) GetHeaders ¶
func (*Request) GetRequestID ¶
func (*Request) GetTBRemotingConnection ¶
func (c *Request) GetTBRemotingConnection() *javaobject.TBRemotingConnectionRequest
func (*Request) GetTimeout ¶
func (*Request) SetCMDCode ¶
func (*Request) SetClassString ¶
func (*Request) SetConnection ¶
func (*Request) SetContent ¶
func (*Request) SetContentString ¶
func (*Request) SetRequestID ¶
func (*Request) SetTimeout ¶
func (*Request) ShallowCopyCommand ¶
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func AcquireResponse ¶
func AcquireResponse() *Response
func (*Response) CopyCommand ¶
func (*Response) GetCMDCode ¶
func (*Response) GetContent ¶
func (*Response) GetHeaders ¶
func (*Response) GetRequestID ¶
func (*Response) GetTBRemotingConnection ¶
func (c *Response) GetTBRemotingConnection() *javaobject.TBRemotingConnectionResponse
func (*Response) GetTimeout ¶
func (*Response) SetCMDCode ¶
func (*Response) SetClassString ¶
func (*Response) SetConnection ¶
func (*Response) SetContent ¶
func (*Response) SetContentString ¶
func (*Response) SetRequestID ¶
func (*Response) SetTimeout ¶
func (*Response) ShallowCopyCommand ¶
type ResponseWriter ¶
type Server ¶
func (*Server) GetMetrics ¶
func (srv *Server) GetMetrics() *ServerMetrics
func (*Server) HandleCommand ¶
type ServerEvent ¶
type ServerEvent uint16
const ( ServerTemporaryAcceptEvent ServerEvent = 0 ServerWorkerPoolOverflowEvent ServerEvent = 1 ServerConnErrorEvent ServerEvent = 2 ServerConnHijackedEvent ServerEvent = 3 )
func (ServerEvent) String ¶
func (i ServerEvent) String() string
type ServerEventContext ¶
type ServerEventContext struct {
// contains filtered or unexported fields
}
func NewServerEventContext ¶
func NewServerEventContext(event ServerEvent) *ServerEventContext
func (ServerEventContext) GetType ¶
func (s ServerEventContext) GetType() ServerEvent
func (*ServerEventContext) SetConn ¶
func (sec *ServerEventContext) SetConn(conn net.Conn) *ServerEventContext
func (*ServerEventContext) SetReq ¶
func (sec *ServerEventContext) SetReq(req *Request) *ServerEventContext
func (*ServerEventContext) SetRes ¶
func (sec *ServerEventContext) SetRes(res *Response) *ServerEventContext
type ServerMetrics ¶
type ServerMetrics struct {
// contains filtered or unexported fields
}
func (*ServerMetrics) GetBytesRead ¶
func (sm *ServerMetrics) GetBytesRead() int64
func (*ServerMetrics) GetBytesWrite ¶
func (sm *ServerMetrics) GetBytesWrite() int64
func (*ServerMetrics) GetCommands ¶
func (sm *ServerMetrics) GetCommands() int64
func (*ServerMetrics) GetConnections ¶
func (sm *ServerMetrics) GetConnections() int64
func (*ServerMetrics) GetPendingCommands ¶
func (sm *ServerMetrics) GetPendingCommands() int64
func (*ServerMetrics) GetPendingConnections ¶
func (sm *ServerMetrics) GetPendingConnections() int64
type ServerOnEventHandler ¶
type ServerOnEventHandler func(*Server, error, *ServerEventContext)
type SimpleMap ¶
type SimpleMap = fastsimplemap.FastSimpleMap
type SofaResponseWriter ¶
type SofaResponseWriter struct {
// contains filtered or unexported fields
}
func AcquireSofaResponseWriter ¶
func AcquireSofaResponseWriter(conn net.Conn, w io.Writer) *SofaResponseWriter
func (*SofaResponseWriter) Derive ¶
func (rw *SofaResponseWriter) Derive(req *Request)
func (*SofaResponseWriter) GetConn ¶
func (rw *SofaResponseWriter) GetConn() net.Conn
func (*SofaResponseWriter) GetID ¶
func (rw *SofaResponseWriter) GetID() uint64
func (*SofaResponseWriter) GetResponse ¶
func (rw *SofaResponseWriter) GetResponse() *Response
func (*SofaResponseWriter) GetWriteError ¶
func (rw *SofaResponseWriter) GetWriteError() error
func (*SofaResponseWriter) GetWriter ¶
func (rw *SofaResponseWriter) GetWriter() io.Writer
func (*SofaResponseWriter) IsHijacked ¶
func (rw *SofaResponseWriter) IsHijacked() bool
func (*SofaResponseWriter) Reset ¶
func (rw *SofaResponseWriter) Reset(w io.Writer) *SofaResponseWriter
func (*SofaResponseWriter) Write ¶
func (rw *SofaResponseWriter) Write() (int, error)
type Status ¶
type Status uint16
const ( StatusSuccess Status = 0 // 0x00 response status StatusError Status = 1 // 0x01 StatusServerException Status = 2 // 0x02 StatusUnknown Status = 3 // 0x03 StatusServerThreadPoolBusy Status = 4 // 0x04 StatusErrorComm Status = 5 // 0x05 StatusNoProcessor Status = 6 // 0x06 StatusTimeout Status = 7 // 0x07 StatusClientSendError Status = 8 // 0x08 StatusCodecException Status = 9 // 0x09 StatusConnectionClosed Status = 16 // 0x10 StatusServerSerialException Status = 17 // 0x11 StatusServerDeseralException Status = 18 // 0x12 )
type TestResponseWriter ¶
type TestResponseWriter struct { sync.Mutex ID uint64 Conn net.Conn Writer io.Writer Response Response Error uatomic.Error NumWrite int Hijacked uint32 }
func (*TestResponseWriter) GetConn ¶
func (rw *TestResponseWriter) GetConn() net.Conn
func (*TestResponseWriter) GetID ¶
func (rw *TestResponseWriter) GetID() uint64
func (*TestResponseWriter) GetResponse ¶
func (rw *TestResponseWriter) GetResponse() *Response
func (*TestResponseWriter) GetWriteError ¶
func (rw *TestResponseWriter) GetWriteError() error
func (*TestResponseWriter) GetWriter ¶
func (rw *TestResponseWriter) GetWriter() io.Writer
func (*TestResponseWriter) Write ¶
func (rw *TestResponseWriter) Write() (int, error)
type WriteOption ¶
type WriteOption struct{}
func NewWriteOption ¶
func NewWriteOption() *WriteOption
Source Files ¶
- client.go
- client_metrics.go
- client_option.go
- client_response_wirter.go
- clientconn_options.go
- clientconn_protocol.go
- clientconnstatus.go
- clinetconn.go
- command.go
- command_option.go
- handler.go
- helper.go
- invoke_context.go
- keepaliver.go
- pool.go
- pool_generated.go
- request.go
- response.go
- response_writer.go
- server.go
- server_event.go
- server_metrics.go
- server_option.go
- serverevent_string.go
- simplemap.go
- sofabolt.go
- syncpool.go