svcpool

package
v0.0.0-...-b5d8682 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ReconnectDelay = 10 * time.Second

don't restart too quickly, or continuous os failures could create extreme system pressure

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer struct {
	sync.Mutex // embed a lock to be synced for thread safety

	// service pool address
	PoolAddr string

	// HBI connection to service pool
	PoolMaster *hbi.TCPConn

	// default context factory
	CtxFact func() hbi.HoContext

	// established service connections, first by proc address string, then by tunnel id string
	// direct access not recommended, but if so, should be synced when accessing from multiple goros
	SvcConns map[string]map[string]*hbi.TCPConn
}

func NewConsumer

func NewConsumer(

	poolAddr string,

	ctxFact func() hbi.HoContext,
) (consumer *Consumer, err error)

func (*Consumer) AssignProc

func (consumer *Consumer) AssignProc(session string, sticky bool) (string, error)

func (*Consumer) GetService

func (consumer *Consumer) GetService(

	ctxFact func() hbi.HoContext,

	tunnel string,

	session string, sticky bool,
) (service *hbi.TCPConn, err error)

get an HBI connection to an assigned service proc by session id

func (*Consumer) ReleaseProc

func (consumer *Consumer) ReleaseProc(procAddr string) error

type Master

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

func NewMaster

func NewMaster(
	poolSize int, hotBack int, processStartTimeout time.Duration,
) (*Master, error)

func (*Master) EnsureHot

func (pool *Master) EnsureHot() error

func (*Master) Serve

func (pool *Master) Serve(serviceAddr string)

type StaticRegistry

type StaticRegistry struct {
	// service address to resolve to
	ServiceAddr string
}

embed this struct with a static service address for simplest service resolving

func (StaticRegistry) AssignProc

func (reg StaticRegistry) AssignProc(session string, sticky bool) (procAddr string)

func (StaticRegistry) ReleaseProc

func (reg StaticRegistry) ReleaseProc(procAddr string) (idle bool)

type WorkerHoContext

type WorkerHoContext interface {
	hbi.HoContext

	// should prepare for the session and send verbatim session id string back via `PoToPeer().CoSendCode()`
	PrepareSession(session string) string
}

A service hosting worker process should communicate with service pool master at TCP address specified as `-team`, using a context struct embedding this interface, constructed by `NewWorkerHoContext()`, and optionally implement (override) methods defined by this interface.

And once it get ready for HBI service hosting, it should tell the pool master its service port by:

ctx.Ho().Po().Notif(`WorkerOnline(<pid int>, <procPort int>)`)

func NewWorkerHoContext

func NewWorkerHoContext() WorkerHoContext

Jump to

Keyboard shortcuts

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