component

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHubUnregistered = errors.New("Unregistered Component")
)

Functions

func StatusToString

func StatusToString(status Status) string

StatusToString returns a string representation of a component's status

Types

type ActorSpan added in v0.8.1

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

type BaseComponent

type BaseComponent struct {
	*log.Logger
	IActor
	// contains filtered or unexported fields
}

BaseComponent provides a basic implementations for IComponent interface

func NewBaseComponent

func NewBaseComponent(name string, actor IActor, logger *log.Logger) *BaseComponent

NewBaseComponent is a helper to create BaseComponent This func requires this component's name, implementation of IActor, and logger to record internal log msg Setting a logger with a same name with the component is recommended

func (*BaseComponent) GetName

func (base *BaseComponent) GetName() string

GetName returns a name of this component

func (*BaseComponent) Hub

func (base *BaseComponent) Hub() *ComponentHub

Hub returns a component hub set

func (*BaseComponent) MsgQueueLen

func (base *BaseComponent) MsgQueueLen() int32

MsgQueueLen gives a number of queued msgs in this component's mailbox

func (*BaseComponent) Receive

func (base *BaseComponent) Receive(context actor.Context)

Receive in the BaseComponent handles system messages and invokes actor's receive function; implementation to handle incomming messages

func (*BaseComponent) Request

func (base *BaseComponent) Request(message interface{}, sender *actor.PID)

Request passes a given message to this component. And a message sender will expect to get a response in form of an actor request

func (*BaseComponent) RequestFuture

func (base *BaseComponent) RequestFuture(message interface{}, timeout time.Duration, tip string) *actor.Future

RequestFuture is similar with Request; passes a given message to this component. And this returns a future, that represent an asynchronous result

func (*BaseComponent) RequestTo

func (base *BaseComponent) RequestTo(targetCompName string, message interface{})

RequestTo passes a given message to a target component And a message sender, this component, will expect to get a response from the target component in form of an actor request

func (*BaseComponent) RequestToFuture

func (base *BaseComponent) RequestToFuture(targetCompName string, message interface{}, timeout time.Duration) *actor.Future

RequestToFuture is similar with RequestTo; passes a given message to this component. And this returns a future, that represent an asynchronous result

func (*BaseComponent) RequestToFutureResult added in v0.8.2

func (base *BaseComponent) RequestToFutureResult(targetCompName string, message interface{}, timeout time.Duration, tip string) (interface{}, error)

RequestToFutureResult is wrapper of RequestToFuture, but this api doesn't return actor.Future. This api can be used when it is possible to use actor.Future type

func (*BaseComponent) SetHub

func (base *BaseComponent) SetHub(hub *ComponentHub)

SetHub assigns a component hub to be used internally

func (*BaseComponent) Start

func (base *BaseComponent) Start()

Start inits internal modules and spawns actor process let this component

func (*BaseComponent) Status

func (base *BaseComponent) Status() Status

Status returns status of this component; started, stopped, stopping, restarting This func is thread-safe

func (*BaseComponent) Stop

func (base *BaseComponent) Stop()

Stop lets this component stop and terminate

func (*BaseComponent) Tell

func (base *BaseComponent) Tell(message interface{})

Tell passes a given message to this component and forgets

func (*BaseComponent) TellTo

func (base *BaseComponent) TellTo(targetCompName string, message interface{})

TellTo tells (sends and forgets) a message to a target component Internally this component will try to find the target component using a hub set

type CompStatReq

type CompStatReq struct {
	SentTime time.Time
}

CompStatReq is an actor message; requesting component's statics When a component gets this message, then it collects infos and returns CompStatRsp to the requester

type CompStatRsp

type CompStatRsp struct {
	Status            string      `json:"status"`
	AccProcessedMsg   uint64      `json:"acc_processed_msg"`
	MsgQueueLen       uint64      `json:"msg_queue_len"`
	MsgProcessLatency string      `json:"msg_latency"`
	Error             string      `json:"error"`
	Actor             interface{} `json:"actor"`
}

CompStatRsp contains component's internal info, used to help debugging - Status is a string representation of a component's status - AccProcessedMsg is an accumulated number of message that this component processes - MsgQueueLen is an current number of message at this component's mailbox - MsgProcessLatency is an estimated latency to process a msg - Error is an error msg when a requester fails to get statics - Actor is a reserved field to get component's internal debug info

type ComponentHub

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

ComponentHub keeps a list of registered components

func NewComponentHub

func NewComponentHub() *ComponentHub

NewComponentHub creates and returns ComponentHub instance

func (*ComponentHub) DestroySpan added in v0.8.1

func (hub *ComponentHub) DestroySpan(id string)

func (*ComponentHub) Get

func (hub *ComponentHub) Get(targetName string) IComponent

Get returns a component which has a targetName

func (*ComponentHub) Register

func (hub *ComponentHub) Register(components ...IComponent)

Register assigns a component to this hub for management

func (*ComponentHub) RequestFuture

func (hub *ComponentHub) RequestFuture(
	targetName string, message interface{}, timeout time.Duration, tip string) *actor.Future

RequestFuture pass a message to a component, which has a targetName And this returns a future instance to be used in waiting a response

func (*ComponentHub) RequestFutureResult added in v0.8.1

func (hub *ComponentHub) RequestFutureResult(
	targetName string, message interface{}, timeout time.Duration, tip string) (interface{}, error)

func (*ComponentHub) RestoreSpan added in v0.8.1

func (hub *ComponentHub) RestoreSpan(id string) *opentracing.Span

func (*ComponentHub) SaveSpan added in v0.8.1

func (hub *ComponentHub) SaveSpan(span opentracing.Span) string

func (*ComponentHub) Start

func (hub *ComponentHub) Start()

Start invokes start funcs of registered components at this hub

func (*ComponentHub) Statistics

func (hub *ComponentHub) Statistics(timeOutSec time.Duration, target string) (map[string]*CompStatRsp, error)

Statistics invoke requests to all registered components, collect and return it's response An input argument, timeout, is used to set actor request's timeout. If it is over, than future: timeout string set at error field

func (*ComponentHub) Stop

func (hub *ComponentHub) Stop()

Stop invokes stop funcs of registered components at this hub

func (*ComponentHub) Tell

func (hub *ComponentHub) Tell(targetName string, message interface{})

Tell pass and forget a message to a component, which has a targetName

type IActor

type IActor interface {
	BeforeStart()
	AfterStart()
	BeforeStop()

	Receive(actor.Context)

	Statistics() *map[string]interface{}
}

IActor describes functions that each components have to implement A BeforeStart func is called before a IComponent.Start func So developers can write component specific initalization codes in here A BeforeStop func is called before a IComponent.Stop func In a Receive func, component's actions is described For each type of message, developer can define a behavior If there is component specific statics or debug info are exists, than developers can get those by defining it in Statistics func

type ICompSyncRequester

type ICompSyncRequester interface {
	RequestFuture(targetName string, message interface{}, timeout time.Duration, tip string) *actor.Future
}

ICompSyncRequester is the interface that wraps the RequestFuture method.

type IComponent

type IComponent interface {
	GetName() string
	Start()
	Stop()
	Status() Status
	SetHub(hub *ComponentHub)
	Hub() *ComponentHub
	MsgQueueLen() int32

	Tell(message interface{})
	Request(message interface{}, sender *actor.PID)
	RequestFuture(message interface{}, timeout time.Duration, tip string) *actor.Future

	Receive(actor.Context)
}

IComponent provides a common interface for easy management and providing a communication channel between components BaseComponent struct provides general implementation of this

type IComponentRequester added in v0.8.2

type IComponentRequester interface {
	TellTo(targetCompName string, message interface{})
	RequestTo(targetCompName string, message interface{})
	RequestToFutureResult(targetCompName string, message interface{}, timeout time.Duration, tip string) (interface{}, error)
}

type Status

type Status = uint32

Status represents a component's current running status

const (
	// StartedStatus means a component is working
	StartedStatus Status = 1 + iota
	// StoppingStatus means a component is stopping
	StoppingStatus
	// StoppedStatus means a component is already stopped
	StoppedStatus
	// RestartingStatus means a component is now restarting
	RestartingStatus
)

Jump to

Keyboard shortcuts

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