sofabolt

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ClassRequest  = "com.alipay.sofa.rpc.core.request.SofaRequest"
	ClassResponse = "com.alipay.sofa.rpc.core.response.SofaResponse"
)

Variables

View Source
var (
	ClassRequestBytes  = []byte(ClassRequest)
	ClassResponseBytes = []byte(ClassResponse)
)
View Source
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")
)
View Source
var DummyServerOnEventHandler = ServerOnEventHandler(func(*Server, error, *ServerEventContext) {
})

Functions

func AcquireTimer

func AcquireTimer(timeout time.Duration) *time.Timer

func IsDeadlineError

func IsDeadlineError(err error) bool

func ReadCommand

func ReadCommand(ro *ReadOption, br io.Reader, cmd *Command) (int, error)

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 ReleaseTimer(t *time.Timer)

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 WithServerTimeout(readTimeout, writeTimeout, idleTimeout, flushInterval time.Duration) serverOptionSetter

func WriteCommand

func WriteCommand(wo *WriteOption, b []byte, cmd *Command) ([]byte, error)

WriteCommand writes the command to []byte.

Types

type CMDCode

type CMDCode uint16
const (
	CMDCodeBOLTHeartbeat CMDCode = 0
	CMDCodeBOLTRequest   CMDCode = 1
	CMDCodeBOLTResponse  CMDCode = 2

	CMDCodeTRemotingHeartbeat CMDCode = 0
	CMDCodeTRemotingRequest   CMDCode = 13
	CMDCodeTRemotingResponse  CMDCode = 14
)

func (CMDCode) String

func (c CMDCode) String() string

type Client

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

func NewClient

func NewClient(options ...ClientOptionSetter) (*Client, error)

func (*Client) AcquireInvokeContext

func (c *Client) AcquireInvokeContext(req *Request, res *Response, timeout time.Duration) *InvokeContext

func (*Client) Close

func (c *Client) Close() error

func (*Client) Closed

func (c *Client) Closed() bool

func (*Client) Do

func (c *Client) Do(req *Request, res *Response) error

func (*Client) DoCallback

func (c *Client) DoCallback(req *Request, cb ClientCallbacker) error

func (*Client) DoCallbackTimeout

func (c *Client) DoCallbackTimeout(req *Request,
	cb ClientCallbacker, timeout time.Duration) error

func (*Client) DoTimeout

func (c *Client) DoTimeout(req *Request, res *Response, timeout time.Duration) error

func (*Client) GetConn

func (c *Client) GetConn() net.Conn

func (*Client) GetMetrics

func (c *Client) GetMetrics() *ClientMetrics

func (*Client) GetReadError

func (c *Client) GetReadError() chan error

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

func (*ClientConn) Write

func (x *ClientConn) Write(b []byte) (int, 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 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

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 Codec

type Codec uint8
const (
	CodecHessian            Codec = 0
	CodecHessian2           Codec = 1
	CodecProtobuf           Codec = 11
	CodecJSON               Codec = 12
	CodecTBRemotingHessian2 Codec = 4
	CodecTBRemotingHessian1 Codec = 1
)

func (Codec) String

func (c Codec) String() string

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

func (c *Command) CopyTo(d *Command)

func (*Command) GetCMDCode

func (c *Command) GetCMDCode() CMDCode

func (*Command) GetClass

func (c *Command) GetClass() []byte

func (*Command) GetCodec

func (c *Command) GetCodec() Codec

func (*Command) GetConnection

func (c *Command) GetConnection() []byte

func (*Command) GetContent

func (c *Command) GetContent() []byte

func (*Command) GetHeaders

func (c *Command) GetHeaders() *SimpleMap

func (*Command) GetProto

func (c *Command) GetProto() Proto

func (*Command) GetRequestID

func (c *Command) GetRequestID() uint32

func (*Command) GetStatus

func (c *Command) GetStatus() Status

func (*Command) GetSwitc

func (c *Command) GetSwitc() uint8

func (*Command) GetTimeout

func (c *Command) GetTimeout() uint32

func (*Command) GetType

func (c *Command) GetType() Type

func (*Command) GetVer1

func (c *Command) GetVer1() Version

func (*Command) GetVer2

func (c *Command) GetVer2() uint8

func (*Command) IsRequest

func (c *Command) IsRequest() bool

func (*Command) Read

func (c *Command) Read(ro *ReadOption, br io.Reader) (int, error)

func (*Command) Reset

func (c *Command) Reset()

func (*Command) SetCMDCode

func (c *Command) SetCMDCode(cmd CMDCode)

func (*Command) SetClass

func (c *Command) SetClass(class []byte)

func (*Command) SetClassString

func (c *Command) SetClassString(class string)

func (*Command) SetCodec

func (c *Command) SetCodec(codec Codec)

func (*Command) SetConnection

func (c *Command) SetConnection(connection []byte)

func (*Command) SetContent

func (c *Command) SetContent(content []byte)

func (*Command) SetContentString

func (c *Command) SetContentString(content string)

func (*Command) SetProto

func (c *Command) SetProto(p Proto)

func (*Command) SetRequestID

func (c *Command) SetRequestID(id uint32)

func (*Command) SetStatus

func (c *Command) SetStatus(s Status)

func (*Command) SetSwitc

func (c *Command) SetSwitc(s uint8)

func (*Command) SetTimeout

func (c *Command) SetTimeout(t uint32)

func (*Command) SetType

func (c *Command) SetType(t Type)

func (*Command) SetVer1

func (c *Command) SetVer1(v Version)

func (*Command) SetVer2

func (c *Command) SetVer2(v uint8)

func (*Command) ShallowCopyTo

func (c *Command) ShallowCopyTo(d *Command)

func (*Command) Size

func (c *Command) Size() int

func (*Command) String

func (c *Command) String() string

nolint

func (*Command) Write

func (c *Command) Write(wo *WriteOption, b []byte) ([]byte, error)

type Dialer

type Dialer interface {
	Dial() (net.Conn, error)
}

type DialerFunc

type DialerFunc func() (net.Conn, error)

func (DialerFunc) Dial

func (d DialerFunc) Dial() (net.Conn, error)

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

func (ca *KeepAliver) Del(tls bool, address string, client *Client) bool

func (*KeepAliver) Get

func (t *KeepAliver) Get(tls bool, addr string) (*Client, bool)

func (*KeepAliver) GracefullyClose

func (k *KeepAliver) GracefullyClose(client *Client)

func (*KeepAliver) Put

func (ca *KeepAliver) Put(tls bool, force bool, addr string, client *Client) bool

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 Pool

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

func NewPool

func NewPool() *Pool

func (*Pool) Delete

func (p *Pool) Delete(client *Client)

func (*Pool) DeleteClients

func (p *Pool) DeleteClients(clients []*Client)

func (*Pool) DeleteLocked

func (p *Pool) DeleteLocked(client *Client)

func (*Pool) Get

func (p *Pool) Get() (*Client, bool)

func (*Pool) Iterate

func (p *Pool) Iterate(fn func(client *Client))

func (*Pool) MarshalJSON

func (p *Pool) MarshalJSON() ([]byte, error)

func (*Pool) Push

func (p *Pool) Push(client *Client)

func (*Pool) Size

func (p *Pool) Size() int

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

func (m *PoolMap) Delete(key string)

Delete deletes the value for a key.

func (*PoolMap) Load

func (m *PoolMap) Load(key string) (value *Pool, ok bool)

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

func (m *PoolMap) LoadOrStore(key string, value *Pool) (actual *Pool, loaded bool)

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

func (m *PoolMap) Range(f func(key string, value *Pool) bool)

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.

func (*PoolMap) Store

func (m *PoolMap) Store(key string, value *Pool)

Store sets the value for a key.

type Proto

type Proto uint8
const (
	ProtoBOLTV1     Proto = 0x01
	ProtoBOLTV2     Proto = 0x02
	ProtoTBRemoting Proto = 0x0d
)

func (Proto) String

func (p Proto) String() string

type ReadOption

type ReadOption struct{}

func NewReadOption

func NewReadOption() *ReadOption

type Request

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

func AcquireRequest

func AcquireRequest() *Request

func (*Request) CopyCommand

func (c *Request) CopyCommand(cmd *Command) *Request

func (*Request) CopyTo

func (c *Request) CopyTo(d *Request) *Request

NOTE: ctx is not copied here (and should not be). If ctx sharing is desired, caller should explicitly copy it.

func (*Request) GetCMDCode

func (c *Request) GetCMDCode() CMDCode

func (*Request) GetClass

func (c *Request) GetClass() []byte

func (*Request) GetCodec

func (c *Request) GetCodec() Codec

func (*Request) GetConnection

func (c *Request) GetConnection() []byte

func (*Request) GetContent

func (c *Request) GetContent() []byte

func (*Request) GetContext

func (c *Request) GetContext() context.Context

func (*Request) GetHeaders

func (c *Request) GetHeaders() *SimpleMap

func (*Request) GetProto

func (c *Request) GetProto() Proto

func (*Request) GetRequestID

func (c *Request) GetRequestID() uint32

func (*Request) GetStatus

func (c *Request) GetStatus() Status

func (*Request) GetSwitc

func (c *Request) GetSwitc() uint8

func (*Request) GetTBRemotingConnection

func (c *Request) GetTBRemotingConnection() *javaobject.TBRemotingConnectionRequest

func (*Request) GetTimeout

func (c *Request) GetTimeout() uint32

func (*Request) GetType

func (c *Request) GetType() Type

func (*Request) GetVer1

func (c *Request) GetVer1() Version

func (*Request) GetVer2

func (c *Request) GetVer2() uint8

func (*Request) Read

func (c *Request) Read(ro *ReadOption, r io.Reader) (int, error)

func (*Request) Reset

func (c *Request) Reset()

func (*Request) SetCMDCode

func (c *Request) SetCMDCode(cmd CMDCode) *Request

func (*Request) SetClass

func (c *Request) SetClass(class []byte) *Request

func (*Request) SetClassString

func (c *Request) SetClassString(class string) *Request

func (*Request) SetCodec

func (c *Request) SetCodec(codec Codec) *Request

func (*Request) SetConnection

func (c *Request) SetConnection(connection []byte) *Request

func (*Request) SetContent

func (c *Request) SetContent(content []byte) *Request

func (*Request) SetContentString

func (c *Request) SetContentString(content string) *Request

func (*Request) SetContext

func (c *Request) SetContext(ctx context.Context) *Request

func (*Request) SetProto

func (c *Request) SetProto(p Proto) *Request

func (*Request) SetRequestID

func (c *Request) SetRequestID(id uint32) *Request

func (*Request) SetStatus

func (c *Request) SetStatus(s Status) *Request

func (*Request) SetSwitc

func (c *Request) SetSwitc(s uint8) *Request

func (*Request) SetTimeout

func (c *Request) SetTimeout(t uint32) *Request

func (*Request) SetType

func (c *Request) SetType(t Type) *Request

func (*Request) SetVer1

func (c *Request) SetVer1(v Version) *Request

func (*Request) SetVer2

func (c *Request) SetVer2(v uint8) *Request

func (*Request) ShallowCopyCommand

func (c *Request) ShallowCopyCommand(cmd *Command) *Request

func (*Request) Size

func (c *Request) Size() int

func (*Request) String

func (c *Request) String() string

func (*Request) Write

func (c *Request) Write(wo *WriteOption, b []byte) ([]byte, error)

type Response

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

func AcquireResponse

func AcquireResponse() *Response

func (*Response) CopyCommand

func (c *Response) CopyCommand(cmd *Command) *Response

func (*Response) CopyTo

func (c *Response) CopyTo(d *Response) *Response

func (*Response) Derive

func (c *Response) Derive(b *Request)

func (*Response) GetCMDCode

func (c *Response) GetCMDCode() CMDCode

func (*Response) GetClass

func (c *Response) GetClass() []byte

func (*Response) GetCodec

func (c *Response) GetCodec() Codec

func (*Response) GetContent

func (c *Response) GetContent() []byte

func (*Response) GetHeaders

func (c *Response) GetHeaders() *SimpleMap

func (*Response) GetProto

func (c *Response) GetProto() Proto

func (*Response) GetRequestID

func (c *Response) GetRequestID() uint32

func (*Response) GetStatus

func (c *Response) GetStatus() Status

func (*Response) GetSwitc

func (c *Response) GetSwitc() uint8

func (*Response) GetTBRemotingConnection

func (c *Response) GetTBRemotingConnection() *javaobject.TBRemotingConnectionResponse

func (*Response) GetTimeout

func (c *Response) GetTimeout() uint32

func (*Response) GetType

func (c *Response) GetType() Type

func (*Response) GetVer1

func (c *Response) GetVer1() Version

func (*Response) GetVer2

func (c *Response) GetVer2() uint8

func (*Response) Read

func (c *Response) Read(ro *ReadOption, r io.Reader) (int, error)

func (*Response) Reset

func (c *Response) Reset()

func (*Response) SetCMDCode

func (c *Response) SetCMDCode(cmd CMDCode) *Response

func (*Response) SetClass

func (c *Response) SetClass(class []byte) *Response

func (*Response) SetClassString

func (c *Response) SetClassString(class string) *Response

func (*Response) SetCodec

func (c *Response) SetCodec(codec Codec) *Response

func (*Response) SetConnection

func (c *Response) SetConnection(content []byte) *Response

func (*Response) SetContent

func (c *Response) SetContent(content []byte) *Response

func (*Response) SetContentString

func (c *Response) SetContentString(content string) *Response

func (*Response) SetProto

func (c *Response) SetProto(p Proto) *Response

func (*Response) SetRequestID

func (c *Response) SetRequestID(id uint32) *Response

func (*Response) SetStatus

func (c *Response) SetStatus(s Status) *Response

func (*Response) SetSwitc

func (c *Response) SetSwitc(s uint8) *Response

func (*Response) SetTimeout

func (c *Response) SetTimeout(t uint32) *Response

func (*Response) SetType

func (c *Response) SetType(t Type) *Response

func (*Response) SetVer1

func (c *Response) SetVer1(v Version) *Response

func (*Response) SetVer2

func (c *Response) SetVer2(v uint8) *Response

func (*Response) ShallowCopyCommand

func (c *Response) ShallowCopyCommand(cmd *Command) *Response

func (*Response) Size

func (c *Response) Size() int

func (*Response) String

func (c *Response) String() string

func (*Response) Write

func (c *Response) Write(wo *WriteOption, b []byte) ([]byte, error)

type ResponseWriter

type ResponseWriter interface {
	GetID() uint64
	GetConn() net.Conn
	GetWriter() io.Writer
	GetResponse() *Response
	Hijack() (net.Conn, bool)
	Write() (int, error)
	GetWriteError() error
}

type Server

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

func NewServer

func NewServer(options ...serverOptionSetter) (*Server, error)

func (*Server) GetMetrics

func (srv *Server) GetMetrics() *ServerMetrics

func (*Server) HandleCommand

func (srv *Server) HandleCommand(wg *sync.WaitGroup, conn net.Conn, bw *bufiorw.Writer,
	rw *SofaResponseWriter, req *Request) bool

func (*Server) Serve

func (srv *Server) Serve(ln net.Listener) error

func (*Server) ServeConn

func (srv *Server) ServeConn(conn net.Conn) error

ServeConn serves a net.Conn

func (*Server) ServeJob

func (srv *Server) ServeJob(v interface{})

func (*Server) Shutdown

func (srv *Server) Shutdown(ctx context.Context) error

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

func (rw *SofaResponseWriter) Hijack() (net.Conn, bool)

func (*SofaResponseWriter) IsHijacked

func (rw *SofaResponseWriter) IsHijacked() bool

func (*SofaResponseWriter) Reset

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

func (rw *TestResponseWriter) Hijack() (net.Conn, bool)

func (*TestResponseWriter) Write

func (rw *TestResponseWriter) Write() (int, error)

type Type

type Type uint8
const (
	TypeBOLTResponse      Type = 0
	TypeBOLTRequest       Type = 1
	TypeBOLTRequestOneWay Type = 2
	TypeTBRemotingOneWay  Type = 1
	TypeTBRemotingTwoWay  Type = 2
)

func (Type) String

func (t Type) String() string

type Version

type Version uint8
const (
	VersionBOLTV1 Version = 1
	VersionBOLTV2 Version = 2
)

func (Version) String

func (c Version) String() string

type WriteOption

type WriteOption struct{}

func NewWriteOption

func NewWriteOption() *WriteOption

Directories

Path Synopsis
conn
delayconn
Package delayconn implements many smart net.Conn.
Package delayconn implements many smart net.Conn.
protocol
simplemap

Jump to

Keyboard shortcuts

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