Documentation
¶
Index ¶
- Constants
- Variables
- func AddLogger(name string, logger Logger)
- func Debug(fmt string, args ...interface{})
- func Error(fmt string, args ...interface{})
- func Info(fmt string, args ...interface{})
- func LifecycleCheckRun(l Lifecycle) bool
- func LifecycleStart(l Lifecycle) error
- func LifecycleStop(l Lifecycle)
- func NewDecodeError(decoder, msg string) error
- func NewEncodeError(encoder, msg string) error
- func RemoveLogger(name string)
- func SetLogLevel(level Level)
- func Trace(fmt string, args ...interface{})
- func Warn(fmt string, args ...interface{})
- type AcceptHandleFunc
- type Acceptor
- type AcceptorConfig
- type AckManager
- type ApolloConfig
- type ApolloEntity
- type ByteBuf
- type Channel
- type ChannelGroup
- type ChannelHandler
- type Client
- type ClientConfig
- type Close
- type DecodeError
- type DecoderInitFunc
- type EncodeError
- type EncoderInitFunc
- type FrameCodec
- type FrameDecoder
- type FrameEncoder
- type FunctionalChannelHandler
- func (h *FunctionalChannelHandler) ChannelActivate(channel Channel) error
- func (h *FunctionalChannelHandler) ChannelError(channel Channel, channelErr error)
- func (h *FunctionalChannelHandler) ChannelInactivate(channel Channel) error
- func (h *FunctionalChannelHandler) ChannelRead(channel Channel, in interface{}) error
- type FunctionalPipelineInitializer
- type HandlerInitFunc
- type Init
- type Level
- type Lifecycle
- type Logger
- type Pipeline
- type PipelineInitializer
- type Sender
- type Server
- type ServerConfig
- type Sync
- type TCPConfig
- type TLVConfig
- type Type
- type UnknownAddr
Constants ¶
const ( LTrace Level = 1 LDebug = LTrace<<1 + 1 LInfo = LDebug<<1 + 1 LWarn = LInfo<<1 + 1 LError = LWarn<<1 + 1 LNone = LError<<1 + 1 )
const ( TagSize = 1 LengthSize = 4 )
Variables ¶
var ( NilInitializerError = errors.New("initializer is nil") NilConnError = errors.New("conn is nil") NilDecoderError = errors.New("decoder is nil") NilEncoderError = errors.New("encoder is nil") NilHandlerError = errors.New("handler is nil") )
Errors
var AckTimeoutError = errors.New("ack timeout")
var ClientNotRunningError = errors.New("client is not running")
Errors
var (
ErrInvalidChannel = errors.New("invalid channel")
)
var NilCallbackError = errors.New("callback is nil")
var NilListenerError = errors.New("listener is nil")
Functions ¶
func LifecycleCheckRun ¶
LifecycleCheckRun returns true is specified Lifecycle instance is valid and current is running.
func LifecycleStart ¶
LifecycleStart check and start specified Lifecycle instance.
func LifecycleStop ¶
func LifecycleStop(l Lifecycle)
LifecycleStop check and stop specified Lifecycle instance.
func NewDecodeError ¶
NewDecodeError create instance of DecodeError with specified error message.
func NewEncodeError ¶
NewEncodeError create instance of EncodeError with specified error message.
func RemoveLogger ¶
func RemoveLogger(name string)
RemoveLogger will cancel the specified logger from global logger proxy.
func SetLogLevel ¶
func SetLogLevel(level Level)
SetLogLevel set output limit to global logger proxy.
Types ¶
type AcceptHandleFunc ¶
type Acceptor ¶
Acceptor is a interface wraps necessary methods for network connection acceptance. The implementation should be based on FSM.
func NewAcceptor ¶
func NewAcceptor(config AcceptorConfig) Acceptor
Create a new ParallelAcceptor with acceptor properties.
type AcceptorConfig ¶
type AcceptorConfig struct {
Parallelism uint8
Listener net.Listener
AcceptHandleFunc func(conn net.Conn)
}
AcceptorConfig is a data struct for acceptor initialization.
type AckManager ¶
type AckManager interface {
// InitAck init and register a ack transaction to manager.
InitAck(key interface{})
// WaitAck will block invoker goroutine until specified ack transaction commit or timeout.
WaitAck(key interface{}, timeout time.Duration) (data interface{}, err error)
// CommitAck commit specified ack transaction.
CommitAck(key interface{}, data interface{})
}
AckManager is the interface wraps methods for acknowledgement management.
func NewAckManager ¶
func NewAckManager() AckManager
NewAckManager will create a instance of default implementation of AckManage. The current default implementation is safeAckManager.
type ApolloConfig ¶
type ApolloConfig struct {
TLVConfig
// contains filtered or unexported fields
}
func (*ApolloConfig) RegisterEntity ¶
func (c *ApolloConfig) RegisterEntity(constructor func() ApolloEntity)
type ApolloEntity ¶
type ApolloEntity interface {
TypeCode() uint16
}
type ByteBuf ¶
type ByteBuf interface {
io.Writer
io.Reader
ReadIndex() int
ReadBytes(length int) []byte
ReadableBytes() int
WriteIndex() int
WriteBytes(bytes []byte)
WritableBytes() int
Capacity() int
Reset()
Release()
}
ByteBuf is the interface provide necessary method of byte buffer with double indexes. The implementation must be designed to consist of two indexes that are read and written separately.
The relationship between reading index and writing index:
+--------------+--------------------+------------------+ | read bytes | readable bytes | writable bytes | | | (unread content) | (free) | +--------------+--------------------+------------------+ ↑ ↑ ↑ ↑ 0 <= readerIndex <= writerIndex <= capacity +------------------------------------------------------+
Method Reset will reset both read index and write index to 0. Method Release will release read bytes and recalculate indexes.
func NewByteBuf ¶
Create a new instance of ElasticUnsafeByteBuf with init size.
type Channel ¶
type Channel interface {
Sender
Close
Remote() net.Addr
IsConnected() bool
GetContext(key string) interface{}
AddContext(key string, val interface{})
DelContext(key string)
}
func NewChannel ¶
type ChannelGroup ¶
type ChannelGroup interface {
// Add will add a specified channel to channel group.
Add(channel Channel)
// Remove will remove specified channel from channel group.
Remove(channel Channel)
// CloseAll will close all channel which management by channel group and remove
// all channel from channel group.
CloseAll()
}
ChannelGroup is a interface wraps methods for channel management which provide batch close support for channels.
func NewHashSafeChannelGroup ¶
func NewHashSafeChannelGroup() ChannelGroup
NewHashSafeChannelGroup create a instance of ChannelGroup based on hash-table.
type ChannelHandler ¶
type ChannelHandler interface {
// ChannelActivate will be invoked while connection is ready.
ChannelActivate(channel Channel) error
// ChannelInActivate will be invoked after connection closed.
ChannelInactivate(channel Channel) error
// ChannelRead will be invoked while a message is ready.
ChannelRead(channel Channel, in interface{}) error
// ChannelError will be invoked while some exception happened.
ChannelError(channel Channel, channelErr error)
}
ChannelHandler is the interface provide necessary methods for channel event handle which invoked by pipeline.
type Client ¶
Client is the interface that wraps the basic method to implement a tcp network client.
func NewClient ¶
func NewClient(cfg ClientConfig, initializer PipelineInitializer) Client
NewClient create a new PipelineClient instance with specified configuration and initializer.
type ClientConfig ¶
ClientConfig provide properties for client configuration
type DecodeError ¶
type DecodeError struct {
// contains filtered or unexported fields
}
DecodeError is a error implementation with detail error string output include decoder name and cause for decode exception. The format of complete error string is '$DECODER decode error cause $CAUSE'.
func (*DecodeError) Error ¶
func (e *DecodeError) Error() string
type DecoderInitFunc ¶
type DecoderInitFunc func() FrameDecoder
type EncodeError ¶
type EncodeError struct {
// contains filtered or unexported fields
}
EncodeError is a error implementation with detail error string output include encoder name and cause for encode exception. The format of complete error string is '$ENCODER encode error cause $CAUSE'.
func (*EncodeError) Error ¶
func (e *EncodeError) Error() string
type EncoderInitFunc ¶
type EncoderInitFunc func() FrameEncoder
type FrameCodec ¶
type FrameCodec interface {
FrameDecoder
FrameEncoder
}
FrameCodec is the interface that wraps the basic method for both encode and decode.
type FrameDecoder ¶
FrameDecoder is the interface that wraps the basic method for decode tcp stream. A FrameDecoder will be instantiated and init by PipelineInitializer in Pipeline initializing.
Model:
+-------------------------+ | (src)↓ | | Decode(in) → (result) | +-------------------------+
func NewApolloFrameDecoder ¶
func NewApolloFrameDecoder(config ApolloConfig) FrameDecoder
NewApolloFrameDecoder create a new apolloFrameDecoder instance with configuration.
func NewStringFrameDecoder ¶
func NewStringFrameDecoder() FrameDecoder
NewStringFrameDecoder create a new stringFrameDecoder instance.
func NewTLVFrameDecoder ¶
func NewTLVFrameDecoder(config TLVConfig) FrameDecoder
NewTLVFrameDecoder create instance of tlvFrameDecoder with specified configuration.
type FrameEncoder ¶
FrameDecoder is the interface that wraps the basic method for encode tcp stream. A FrameEncoder will be instantiated and init by PipelineInitializer in Pipeline initializing.
Model:
+-------------------------+ | (src)↓ | | Encode(in) → (result) | +-------------------------+
func NewApolloFrameEncoder ¶
func NewApolloFrameEncoder(config ApolloConfig) FrameEncoder
NewApolloFrameEncoder create a new apolloFrameEncoder instance with configuration.
func NewStringFrameEncoder ¶
func NewStringFrameEncoder() FrameEncoder
NewStringFrameEncoder create a new stringFrameEncoder instance.
func NewTLVFrameEncoder ¶
func NewTLVFrameEncoder(config TLVConfig) FrameEncoder
NewTLVFrameEncoder create instance of tlvFrameEncoder with specified configuration.
type FunctionalChannelHandler ¶
type FunctionalChannelHandler struct {
HandleActivate func(channel Channel) error
HandleInactivate func(channel Channel) error
HandleRead func(channel Channel, in interface{}) error
HandleError func(channel Channel, err error)
}
FunctionalChannelHandler is a public implementation of ChannelHandler interface which support functional definition for business logic.
func (*FunctionalChannelHandler) ChannelActivate ¶
func (h *FunctionalChannelHandler) ChannelActivate(channel Channel) error
func (*FunctionalChannelHandler) ChannelError ¶
func (h *FunctionalChannelHandler) ChannelError(channel Channel, channelErr error)
func (*FunctionalChannelHandler) ChannelInactivate ¶
func (h *FunctionalChannelHandler) ChannelInactivate(channel Channel) error
func (*FunctionalChannelHandler) ChannelRead ¶
func (h *FunctionalChannelHandler) ChannelRead(channel Channel, in interface{}) error
type FunctionalPipelineInitializer ¶
type FunctionalPipelineInitializer struct {
DecoderInit DecoderInitFunc
EncoderInit EncoderInitFunc
HandlerInit HandlerInitFunc
}
FunctionalPipelineInitializer is a public implementation of PipelineInitializer interface which support functional definition for pipeline initialization logic.
func (*FunctionalPipelineInitializer) InitDecoder ¶
func (i *FunctionalPipelineInitializer) InitDecoder() FrameDecoder
func (*FunctionalPipelineInitializer) InitEncoder ¶
func (i *FunctionalPipelineInitializer) InitEncoder() FrameEncoder
func (*FunctionalPipelineInitializer) InitHandler ¶
func (i *FunctionalPipelineInitializer) InitHandler() ChannelHandler
type HandlerInitFunc ¶
type HandlerInitFunc func() ChannelHandler
type Init ¶
type Init interface {
Init() error
}
Init is the interface that wraps the basic method for init.
type Lifecycle ¶
LifeCycle is the interface that wraps the basic method for standard service lifecycle control.
type Pipeline ¶
Pipeline is the interface defined necessary methods which makes a pipeline of FrameDecoder, FrameEncoder, and ChannelHandler for inbound and outbound data processing.
Model:
+---------------------------------------+
| TCP Network Connection |
+---------------------------------------+
↑(write) ↓(read)
+----------------+ +----------------+
| FrameEncoder | | FrameDecoder |
+----------------+ +----------------+
↑(outbound) ↓(inbound)
+----------------+ +----------------+
| Channel | | ChannelHandler |
+----------------+ +----------------+
State:
+-----+ +---------+ +----------+ | NEW | → Start → | RUNNING | → Stop → | SHUTDOWN | +-----+ +---------+ +----------+
Notes: The implementations should be parallel safe and based on FSM.
func NewPipeline ¶
func NewPipeline(conn net.Conn, initializer PipelineInitializer) (Pipeline, error)
NewPipeline create and init pipeline with initializer.
type PipelineInitializer ¶
type PipelineInitializer interface {
// InitDecoder used for decoder initialization.
InitDecoder() FrameDecoder
// InitEncoder used for encoder initialization.
InitEncoder() FrameEncoder
// InitHandler used for channel handler initialization.
InitHandler() ChannelHandler
}
ChannelHandler is the interface provide necessary methods for pipeline initialization which invoked by pipeline.
type Server ¶
Server is the interface that wraps the basic method to implement a tcp network server based on FSM.
func NewServer ¶
func NewServer(cfg ServerConfig, initializer PipelineInitializer) Server
NewServer init a new server instance with specified configuration and initializer.
type ServerConfig ¶
ServerConfig provide properties for server configuration
type Sync ¶
type Sync interface {
Sync()
}
Sync is the interface that wraps the Sync() method which will block invoker goroutine.
type TLVConfig ¶
TLVConfig is a data struct provide configuration properties for both tlvFrameDecoder and tlvFrameEncoder.
+----------+-----------+-----------+
| TAG | LENGTH | VALUE |
| (1 byte) | (4 bytes) | (payload) |
+----------+-----------+-----------+
↑
TagValue
type Type ¶
type Type interface {
Type() string
}
Type is the interface wraps method to get string type value.
type UnknownAddr ¶
type UnknownAddr struct {
}
func (*UnknownAddr) Network ¶
func (ua *UnknownAddr) Network() string
func (*UnknownAddr) String ¶
func (ua *UnknownAddr) String() string