Documentation ¶
Index ¶
- type ActiveContext
- type ActiveHandler
- type ActiveHandlerFunc
- type Attachment
- type Bootstrap
- type Channel
- type ChannelFactory
- type ChannelHandler
- type ChannelIDFactory
- type ChannelInboundHandler
- type ChannelInitializer
- type ChannelOutboundHandler
- type CodecHandler
- type Event
- type EventContext
- type EventHandler
- type EventHandlerFunc
- type Exception
- type ExceptionContext
- type ExceptionHandler
- type ExceptionHandlerFunc
- type Handler
- type HandlerContext
- type InactiveContext
- type InactiveHandler
- type InactiveHandlerFunc
- type InboundContext
- type InboundHandler
- type InboundHandlerFunc
- type Listener
- type Message
- type Option
- func WithChannel(channelFactory ChannelFactory) Option
- func WithChannelID(channelIDFactory ChannelIDFactory) Option
- func WithChildInitializer(initializer ChannelInitializer) Option
- func WithClientInitializer(initializer ChannelInitializer) Option
- func WithContext(ctx context.Context) Option
- func WithPipeline(pipelineFactory PipelineFactory) Option
- func WithTransport(transportFactory TransportFactory) Option
- type OutboundContext
- type OutboundHandler
- type OutboundHandlerFunc
- type Pipeline
- type PipelineFactory
- type ReadIdleEvent
- type SimpleChannelHandler
- type TransportFactory
- type WriteIdleEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActiveContext ¶
type ActiveContext interface { HandlerContext HandleActive() }
ActiveContext defines an active handler
type ActiveHandler ¶
type ActiveHandler interface {
HandleActive(ctx ActiveContext)
}
ActiveHandler defines an active handler
type ActiveHandlerFunc ¶
type ActiveHandlerFunc func(ctx ActiveContext)
ActiveHandlerFunc impl ActiveHandler
func (ActiveHandlerFunc) HandleActive ¶
func (fn ActiveHandlerFunc) HandleActive(ctx ActiveContext)
HandleActive to impl ActiveHandler
type Attachment ¶
type Attachment interface { }
Attachment defines the object or data associated with the Channel
type Bootstrap ¶
type Bootstrap interface { // Context return context Context() context.Context // Listen create a listener Listen(url string, option ...transport.Option) Listener // Connect to remote endpoint Connect(url string, attachment Attachment, option ...transport.Option) (Channel, error) // Shutdown boostrap Shutdown() }
Bootstrap makes it easy to bootstrap a channel
func NewBootstrap ¶
NewBootstrap create a new Bootstrap with default config.
type Channel ¶
type Channel interface { // ID channel id ID() int64 // Write message through the Pipeline Write(Message) bool // Trigger user event Trigger(event Event) // Close through the Pipeline Close(err error) // IsActive return true if the Channel is active and so connected IsActive() bool // Writev to write [][]byte for optimize syscall Writev([][]byte) (int64, error) // LocalAddr local address LocalAddr() string // RemoteAddr remote address RemoteAddr() string // Transport get transport of channel Transport() transport.Transport // Pipeline get pipeline of channel Pipeline() Pipeline // Attachment get attachment Attachment() Attachment // SetAttachment set attachment SetAttachment(Attachment) // Context channel context Context() context.Context // contains filtered or unexported methods }
Channel is defines a server-side-channel & client-side-channel
type ChannelFactory ¶
type ChannelFactory func(id int64, ctx context.Context, pipeline Pipeline, transport transport.Transport) Channel
ChannelFactory to create a channel
func NewBufferedChannel ¶
func NewBufferedChannel(capacity int, sizeRead int) ChannelFactory
NewBufferedChannel create a ChannelFactory with buffered transport
type ChannelHandler ¶
type ChannelHandler interface { ActiveHandler InboundHandler OutboundHandler ExceptionHandler InactiveHandler }
ChannelHandler defines a channel handler
type ChannelInboundHandler ¶
type ChannelInboundHandler interface { ActiveHandler InboundHandler InactiveHandler }
ChannelInboundHandler defines a channel inbound handler
func ReadIdleHandler ¶
func ReadIdleHandler(idleTime time.Duration) ChannelInboundHandler
ReadIdleHandler fire ReadIdleEvent after waiting for a reading timeout
type ChannelInitializer ¶
type ChannelInitializer func(Channel)
ChannelInitializer to init the pipeline of channel
type ChannelOutboundHandler ¶
type ChannelOutboundHandler interface { ActiveHandler OutboundHandler InactiveHandler }
ChannelOutboundHandler defines a channel outbound handler
func WriteIdleHandler ¶
func WriteIdleHandler(idleTime time.Duration) ChannelOutboundHandler
WriteIdleHandler fire WriteIdleEvent after waiting for a sending timeout
type CodecHandler ¶
type CodecHandler interface { CodecName() string InboundHandler OutboundHandler }
CodecHandler defines an codec handler
type Event ¶
type Event interface { }
Event defines user-defined event types, read-write timeout events, etc
type EventContext ¶
type EventContext interface { HandlerContext HandleEvent(event Event) }
EventContext defines an event handler
type EventHandler ¶
type EventHandler interface {
HandleEvent(ctx EventContext, event Event)
}
EventHandler defines an event handler
type EventHandlerFunc ¶
type EventHandlerFunc func(ctx EventContext, event Event)
EventHandlerFunc impl EventHandler
func (EventHandlerFunc) HandleEvent ¶
func (fn EventHandlerFunc) HandleEvent(ctx EventContext, event Event)
HandleEvent to impl EventHandler
type Exception ¶
type Exception interface { // Unwrap inner error. Unwrap() error // Error message. Error() string // Stack stack trace. Stack() []byte // PrintStackTrace dump stack trace to writers. PrintStackTrace(writer io.Writer, msg ...string) }
Exception defines an exception
func AsException ¶
AsException to wrap error to Exception
type ExceptionContext ¶
type ExceptionContext interface { HandlerContext HandleException(ex Exception) }
ExceptionContext defines an exception handler
type ExceptionHandler ¶
type ExceptionHandler interface {
HandleException(ctx ExceptionContext, ex Exception)
}
ExceptionHandler defines an exception handler
type ExceptionHandlerFunc ¶
type ExceptionHandlerFunc func(ctx ExceptionContext, ex Exception)
ExceptionHandlerFunc impl ExceptionHandler
func (ExceptionHandlerFunc) HandleException ¶
func (fn ExceptionHandlerFunc) HandleException(ctx ExceptionContext, ex Exception)
HandleException to impl ExceptionHandler
type Handler ¶
type Handler interface { }
Handler defines an any handler At least one or more of the following types should be implemented ActiveHandler InboundHandler OutboundHandler ExceptionHandler InactiveHandler EventHandler
type HandlerContext ¶
type HandlerContext interface { Channel() Channel Handler() Handler Write(message Message) Trigger(event Event) Close(err error) Attachment() Attachment SetAttachment(Attachment) }
HandlerContext defines a base handler context
type InactiveContext ¶
type InactiveContext interface { HandlerContext HandleInactive(ex Exception) }
InactiveContext defines an inactive handler
type InactiveHandler ¶
type InactiveHandler interface {
HandleInactive(ctx InactiveContext, ex Exception)
}
InactiveHandler defines an inactive handler
type InactiveHandlerFunc ¶
type InactiveHandlerFunc func(ctx InactiveContext, ex Exception)
InactiveHandlerFunc impl InactiveHandler
func (InactiveHandlerFunc) HandleInactive ¶
func (fn InactiveHandlerFunc) HandleInactive(ctx InactiveContext, ex Exception)
HandleInactive to impl InactiveHandler
type InboundContext ¶
type InboundContext interface { HandlerContext HandleRead(message Message) }
InboundContext defines an inbound handler
type InboundHandler ¶
type InboundHandler interface {
HandleRead(ctx InboundContext, message Message)
}
InboundHandler defines an Inbound handler
type InboundHandlerFunc ¶
type InboundHandlerFunc func(ctx InboundContext, message Message)
InboundHandlerFunc impl InboundHandler
func (InboundHandlerFunc) HandleRead ¶
func (fn InboundHandlerFunc) HandleRead(ctx InboundContext, message Message)
HandleRead to impl InboundHandler
type Message ¶
type Message interface { }
Message defines an any message
Represent different objects in different processing steps, in most cases the message type handled by the codec is mainly io.Reader / []byte, in the user handler should have been converted to a protocol object.
type Option ¶
type Option func(options *bootstrapOptions)
func WithChannel ¶
func WithChannel(channelFactory ChannelFactory) Option
WithChannel to set ChannelFactory
func WithChannelID ¶
func WithChannelID(channelIDFactory ChannelIDFactory) Option
WithChannelID to set ChannelIDFactory
func WithChildInitializer ¶
func WithChildInitializer(initializer ChannelInitializer) Option
WithChildInitializer to set server side ChannelInitializer
func WithClientInitializer ¶
func WithClientInitializer(initializer ChannelInitializer) Option
WithClientInitializer to set client side ChannelInitializer
func WithContext ¶
WithContext fork child context with context.WithCancel
func WithPipeline ¶
func WithPipeline(pipelineFactory PipelineFactory) Option
WithPipeline to set PipelineFactory
func WithTransport ¶
func WithTransport(transportFactory TransportFactory) Option
WithTransport to set TransportFactory
type OutboundContext ¶
type OutboundContext interface { HandlerContext HandleWrite(message Message) }
OutboundContext defines an outbound handler
type OutboundHandler ¶
type OutboundHandler interface {
HandleWrite(ctx OutboundContext, message Message)
}
OutboundHandler defines an outbound handler
type OutboundHandlerFunc ¶
type OutboundHandlerFunc func(ctx OutboundContext, message Message)
OutboundHandlerFunc impl OutboundHandler
func (OutboundHandlerFunc) HandleWrite ¶
func (fn OutboundHandlerFunc) HandleWrite(ctx OutboundContext, message Message)
HandleWrite to impl OutboundHandler
type Pipeline ¶
type Pipeline interface { // AddFirst add a handler to the first. AddFirst(handlers ...Handler) Pipeline // AddLast add a handler to the last. AddLast(handlers ...Handler) Pipeline // AddHandler add handlers in position. AddHandler(position int, handlers ...Handler) Pipeline // IndexOf find fist index of handler. IndexOf(func(Handler) bool) int // LastIndexOf find last index of handler. LastIndexOf(func(Handler) bool) int // ContextAt get context by position. ContextAt(position int) HandlerContext // Size of handler Size() int // Channel get channel. Channel() Channel // ServeChannel serve the channel. ServeChannel(channel Channel) FireChannelActive() FireChannelRead(message Message) FireChannelWrite(message Message) FireChannelException(ex Exception) FireChannelInactive(ex Exception) FireChannelEvent(event Event) }
Pipeline defines a message processing pipeline.
type SimpleChannelHandler ¶
type SimpleChannelHandler = ChannelInboundHandler
SimpleChannelHandler defines ChannelInboundHandler alias
type TransportFactory ¶
TransportFactory tp create transport