Documentation ¶
Index ¶
- Constants
- Variables
- func NewMiniProtocol(fragment ProtocolFragment) *protocol
- func NewMiniProtocolTransport(fragment ProtocolFragment, transport TransportProvider) *protocol
- func NewProtocol(name string, fragments ...ProtocolFragment) (*protocol, error)
- func NewProtocolTransport(name string, transport TransportProvider, fragments ...ProtocolFragment) (*protocol, error)
- func ParseServerFlags(default_ip string, default_port int) string
- type Addr
- type CircuitBreaker
- type Client
- type Code
- type Conn
- type Decoder
- type DecoderMap
- type FaultDetector
- type FaultDetectorBase
- func (detector *FaultDetectorBase) AddCallback(callback FaultDetectorCallback, key interface{})
- func (detector *FaultDetectorBase) Error() (err error)
- func (detector *FaultDetectorBase) ErrorDetected(err error)
- func (detector *FaultDetectorBase) InvokeCallback(wasOnline bool)
- func (detector *FaultDetectorBase) LoopCheck(checker func(), timeout time.Duration)
- func (detector *FaultDetectorBase) ObservedServer() Addr
- func (detector *FaultDetectorBase) Online() bool
- func (detector *FaultDetectorBase) PerformCheck(checker func() error)
- type FaultDetectorCallback
- type Listener
- type MarshallingProvider
- type Packet
- type Plugin
- type PluginServer
- type PluginSession
- type PluginSessionHandler
- type Protocol
- type ProtocolFragment
- type Server
- func (server *Server) Errors() <-chan error
- func (server *Server) LocalAddr() Addr
- func (server *Server) LogError(err error)
- func (server *Server) Protocol() Protocol
- func (server *Server) RegisterHandlers(handlers ServerHandlerMap) error
- func (server *Server) RegisterStopHandler(handler ServerStopper)
- func (server *Server) Reply(code Code, value interface{}) *Packet
- func (server *Server) ReplyCheck(err error) *Packet
- func (server *Server) ReplyError(err error) *Packet
- func (server *Server) ReplyOK() *Packet
- func (server *Server) Start(wg *sync.WaitGroup) golib.StopChan
- func (server *Server) Stop()
- func (server *Server) String() string
- type ServerHandlerMap
- type ServerProtocolFragment
- type ServerRequestHandler
- type ServerStopper
- type Session
- type SessionBase
- type SessionParameter
- type Sessions
- func (sessions Sessions) DeleteSession(key interface{}) error
- func (sessions Sessions) DeleteSessions() error
- func (sessions Sessions) Get(key interface{}) Session
- func (sessions Sessions) ReKeySession(oldKey, newKey interface{}) (*SessionBase, error)
- func (sessions Sessions) StartSession(key interface{}, session Session)
- func (sessions Sessions) StopSession(key interface{}) error
- type TransportProvider
Constants ¶
View Source
const ( CodeOK = iota CodeError )
View Source
const ( ErrorChanBuffer = 16 SendTimeout = 1 * time.Second )
View Source
const (
DefaultRetries = 3
)
View Source
const (
DefaultTimeout = 1 * time.Second
)
Variables ¶
View Source
var (
DefaultTransport = TcpTransport()
)
Functions ¶
func NewMiniProtocol ¶
func NewMiniProtocol(fragment ProtocolFragment) *protocol
func NewMiniProtocolTransport ¶
func NewMiniProtocolTransport(fragment ProtocolFragment, transport TransportProvider) *protocol
func NewProtocol ¶
func NewProtocol(name string, fragments ...ProtocolFragment) (*protocol, error)
func NewProtocolTransport ¶
func NewProtocolTransport(name string, transport TransportProvider, fragments ...ProtocolFragment) (*protocol, error)
func ParseServerFlags ¶
Types ¶
type CircuitBreaker ¶
type CircuitBreaker interface { Client Error() error Online() bool AddCallback(callback FaultDetectorCallback, key interface{}) }
func NewCircuitBreaker ¶
func NewCircuitBreaker(client Client, detector FaultDetector) (CircuitBreaker, error)
func NewCircuitBreakerOn ¶
func NewCircuitBreakerOn(protocol Protocol, detector FaultDetector) (CircuitBreaker, error)
type Client ¶
type Client interface { Close() error Closed() bool ResetConnection() // Will open new connection next time it's required SetServer(server_addr string) error Server() Addr SetTimeout(timeout time.Duration) Protocol() Protocol String() string SendPacket(packet *Packet) error Send(code Code, val interface{}) error SendRequest(code Code, val interface{}) (*Packet, error) SendRequestPacket(packet *Packet) (reply *Packet, err error) CheckReply(reply *Packet) error CheckError(reply *Packet, expectedCode Code) error }
func NewMiniClient ¶
func NewMiniClient(fragment ProtocolFragment) Client
func NewMiniClientFor ¶
func NewMiniClientFor(server_addr string, fragment ProtocolFragment) (Client, error)
type DecoderMap ¶
type FaultDetector ¶
type FaultDetectorBase ¶
func NewFaultDetectorBase ¶
func NewFaultDetectorBase(observedProtocol Protocol, server Addr) *FaultDetectorBase
func (*FaultDetectorBase) AddCallback ¶
func (detector *FaultDetectorBase) AddCallback(callback FaultDetectorCallback, key interface{})
func (*FaultDetectorBase) Error ¶
func (detector *FaultDetectorBase) Error() (err error)
func (*FaultDetectorBase) ErrorDetected ¶
func (detector *FaultDetectorBase) ErrorDetected(err error)
func (*FaultDetectorBase) InvokeCallback ¶
func (detector *FaultDetectorBase) InvokeCallback(wasOnline bool)
func (*FaultDetectorBase) LoopCheck ¶
func (detector *FaultDetectorBase) LoopCheck(checker func(), timeout time.Duration)
func (*FaultDetectorBase) ObservedServer ¶
func (detector *FaultDetectorBase) ObservedServer() Addr
func (*FaultDetectorBase) Online ¶
func (detector *FaultDetectorBase) Online() bool
func (*FaultDetectorBase) PerformCheck ¶
func (detector *FaultDetectorBase) PerformCheck(checker func() error)
type FaultDetectorCallback ¶
type FaultDetectorCallback func(key interface{})
type MarshallingProvider ¶
type MarshallingProvider interface { MarshalPacket(packet *Packet) ([]byte, error) UnmarshalPacket([]byte, Protocol) (*Packet, error) }
var (
Marshaller MarshallingProvider = gobMarshaller
)
type Plugin ¶
type Plugin interface { Start(server *PluginServer) Stop() error // Create and fully initialize new session. The param data is passed from // plugin to plugin, enabling one plugin to modify the input data for the next plugin. // Modify param if necessary and copy values from it. Do not store it. NewSession(param SessionParameter) (PluginSessionHandler, error) }
type PluginServer ¶
type PluginServer struct { *Server SessionStartedCallback func(session *PluginSession) SessionStoppedCallback func(session *PluginSession) // contains filtered or unexported fields }
func NewPluginServer ¶
func NewPluginServer(server *Server) *PluginServer
func (*PluginServer) AddPlugin ¶
func (server *PluginServer) AddPlugin(plugin Plugin)
func (*PluginServer) DeleteSession ¶
func (server *PluginServer) DeleteSession(client string) error
func (*PluginServer) NewSession ¶
func (server *PluginServer) NewSession(param SessionParameter) error
func (*PluginServer) StopServer ¶
func (server *PluginServer) StopServer()
func (*PluginServer) StopSession ¶
func (server *PluginServer) StopSession(client string) error
type PluginSession ¶
type PluginSession struct { Base *SessionBase Client string // From the originating SessionParameter Server *PluginServer Plugins []PluginSessionHandler }
func (*PluginSession) Cleanup ¶
func (session *PluginSession) Cleanup()
func (*PluginSession) Start ¶
func (session *PluginSession) Start(base *SessionBase)
func (*PluginSession) Tasks ¶
func (session *PluginSession) Tasks() (result []golib.Task)
type PluginSessionHandler ¶
type PluginSessionHandler interface { Start(sendingSession PluginSessionHandler) Tasks() []golib.Task Cleanup() error String() string }
type Protocol ¶
type Protocol interface { Name() string CheckIncludesFragment(fragmentName string) error Transport() TransportProvider // contains filtered or unexported methods }
type ProtocolFragment ¶
type ProtocolFragment interface { Name() string Decoders() DecoderMap }
type Server ¶
type Server struct { Stopped bool // contains filtered or unexported fields }
func (*Server) RegisterHandlers ¶
func (server *Server) RegisterHandlers(handlers ServerHandlerMap) error
func (*Server) RegisterStopHandler ¶
func (server *Server) RegisterStopHandler(handler ServerStopper)
func (*Server) ReplyCheck ¶
func (*Server) ReplyError ¶
type ServerHandlerMap ¶
type ServerHandlerMap map[Code]ServerRequestHandler
type ServerProtocolFragment ¶
type ServerProtocolFragment interface { ProtocolFragment ServerHandlers(server *Server) ServerHandlerMap }
If a ProtocolFragment implements this, the returned handlers will be automatically added to a Server
type ServerRequestHandler ¶
type ServerStopper ¶
type ServerStopper func()
type Session ¶
type Session interface { Start(base *SessionBase) Tasks() []golib.Task Cleanup() }
type SessionBase ¶
type SessionBase struct { Wg *sync.WaitGroup Stopped golib.StopChan CleanupErr error Session Session }
func (*SessionBase) Stop ¶
func (base *SessionBase) Stop()
func (*SessionBase) StopAndFormatError ¶
func (base *SessionBase) StopAndFormatError() error
type SessionParameter ¶
type SessionParameter interface { // This string will be used as key in the sessions dictionary Client() string }
type Sessions ¶
type Sessions map[interface{}]*SessionBase
func (Sessions) DeleteSession ¶
func (Sessions) DeleteSessions ¶
func (Sessions) ReKeySession ¶
func (sessions Sessions) ReKeySession(oldKey, newKey interface{}) (*SessionBase, error)
func (Sessions) StartSession ¶
func (Sessions) StopSession ¶
type TransportProvider ¶
type TransportProvider interface { Resolve(addr string) (Addr, error) ResolveIP(ip string) (Addr, error) ResolveLocal(remote_addr string) (Addr, error) Listen(local Addr, protocol Protocol) (Listener, error) Dial(remote Addr, protocol Protocol) (Conn, error) String() string }
func TcpTransport ¶
func TcpTransport() TransportProvider
func UdpTransport ¶
func UdpTransport() TransportProvider
func UdpTransportB ¶
func UdpTransportB(bufferSize int) TransportProvider
Source Files ¶
Click to show internal directories.
Click to hide internal directories.