faces

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package faces implements the full list of Interfaces.

Index

Constants

View Source
const (
	// ChanStdGo is wrapper for nodes.ChanType_CHAN_STD_GO.
	ChanStdGo = ChanType(nodes.ChanType_CHAN_STD_GO)

	// ChanStack is wrapper for nodes.ChanType_CHAN_STACK.
	ChanStack = ChanType(nodes.ChanType_CHAN_STACK)

	// ChaPriorityQueue is wrapper for nodes.ChanType_CHAN_PRIORITY_QUEUE.
	ChaPriorityQueue = ChanType(nodes.ChanType_CHAN_PRIORITY_QUEUE)
)
View Source
const (
	// StartTestHandlerPrefix is a prefix for tests start method.
	StartTestHandlerPrefix = "StartTest"
	// StopTestHandlerPrefix is a prefix for tests stop method.
	StopTestHandlerPrefix = "StopTest"
	// RunTestHandlerPrefix is a prefix for tests stop method.
	RunTestHandlerPrefix = "RunTest"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChanType

type ChanType nodes.ChanType

ChanType is a global type.

type EmptyHandler added in v0.0.3

type EmptyHandler struct{}

EmptyHandler realizes the empty handler which do nothing. It is useful for replace empty Start and Stop methods by inherited objects.

Example:

type MySimpleHandler struct {
   EmptyHandler
}

func Handler(_ faces.Name) (faces.IHandler, error) {
	return &MySimpleHandler{}, nil
}

func (m *MySimpleHandler) Run(item faces.IItem) error {s
	// do something here
	return nil
}

func (*EmptyHandler) Run added in v0.0.3

func (m *EmptyHandler) Run(_ IItem) error

Run does nothing.

func (*EmptyHandler) Start added in v0.0.3

func (m *EmptyHandler) Start(_ context.Context) error

Start does nothing.

func (*EmptyHandler) Stop added in v0.0.3

func (m *EmptyHandler) Stop(_ context.Context)

Stop does nothing.

func (*EmptyHandler) TickerDuration added in v0.0.14

func (m *EmptyHandler) TickerDuration() time.Duration

TickerDuration returns 0 by default.

func (*EmptyHandler) TickerRun added in v0.0.14

func (m *EmptyHandler) TickerRun(ctx context.Context)

TickerRun does nothing by default.

type GiveBirth

type GiveBirth func(name Name) (IHandler, error)

GiveBirth return new handler. Type Name is string which was passed with AddHandler(...).

type IChan

type IChan interface {

	// ChanIn returns reference to input channel.
	ChanIn() MainCh
	// ChanOut returns reference to output channel.
	ChanOut() MainCh

	// Push adds item index to queue.
	Push(int)
	Close()
	IsActive() bool
	// Count returns the number of items in the stack channel.
	Count() int
	// Len returns the max available number items in the stack channel.
	Len() int

	Info() *nodes.ChanData
}

IChan is interface for support queue oin conveyor.

type IConveyor

type IConveyor interface {
	Start(ctx context.Context) error
	Stop()
	WaitAndStop()

	// simple pushing
	Run(IInput)
	RunRes(IInput) (interface{}, error)

	// simple pushing in test mode
	RunTest(i IInput, object ITestObject)
	RunResTest(i IInput, object ITestObject) (interface{}, error)

	SetDefaultPriority(defaultPriority int)
	GetDefaultPriority() int

	SetName(name string) IConveyor
	GetName() string

	SetWorkersCounter(wc IWorkersCounter) IConveyor
	AddHandler(manageName Name, minCount, maxCount int, handler GiveBirth) error
	AddErrorHandler(manageName Name, minCount, maxCount int, handler GiveBirth) error
	AddFinalHandler(manageName Name, minCount, maxCount int, handler GiveBirth) error
	Statistic() *nodes.SlaveNodeInfoRequest
	SetTracer(tr ITrace, duration time.Duration) IConveyor

	// The period between metric evaluations.
	// By default 10 second
	MetricPeriod(duration time.Duration) IConveyor

	// Master node is single node for control the conveyor
	SetMasterNode(addr string, masterNodePeriod time.Duration)

	DefaultPriority() int

	// Simple getter
	WorkBench() IWorkBench
}

IConveyor is interface for support the conveyor.

type IHandler

type IHandler interface {
	// Start() function is called one time for each handler right after it's created with GiveBirth().
	Start(ctx context.Context) error

	// Run() function is called for processing single item.
	Run(item IItem) error

	// TickerRun() function is called for processing by timer (ticker).
	TickerRun(ctx context.Context) // error is not processing
	TickerDuration() time.Duration

	// Stop() function is called before destruction of handler.
	Stop(ctx context.Context)
}

IHandler is interface for support the single handler.

func MakeEmptyHandler added in v0.0.3

func MakeEmptyHandler(_ Name) (IHandler, error)

MakeEmptyHandler is a constructor for EmptyHandler.

type IInput added in v0.0.9

type IInput interface {
	Context(ctx context.Context) IInput // by default the context.Background()
	Trace(tr ITrace) IInput             // nil is by default
	Data(data interface{}) IInput       // nil is by default
	Priority(priority int) IInput       // by default is IConveyor.DefaultPriority()
	SkipToName(name Name) IInput        // by default is ""

	// return all data above
	Values() (ctx context.Context, tr ITrace, data interface{}, priority *int, name Name)
	Ctx() context.Context
}

IInput is interface for support input data to conveyor.

type IItem

type IItem interface {
	GetID() int64
	SetID(id int64)

	Get() (data interface{})
	Set(data interface{})
	InitEmpty()

	// processing functions
	GetContext() context.Context
	SetLock()
	SetUnlock()

	AddError(err error)
	GetError() error
	CleanError()

	SetSkipNames(label ...Name)
	SetSkipToName(label Name)
	GetSkipToName() Name
	GetSkipNames() []Name
	NeedToSkip(worker IWorker) (bool, error)

	LogTraceFinishTimef(format string, a ...interface{})
	LogTracef(format string, a ...interface{})

	Start()
	Cancel()
	Finish()

	PushedToChannel(label Name)
	ReceivedFromChannel()
	BeforeProcess(label Name)
	AfterProcess(label Name, err error)

	// >>>>>>> Priority Queue Supports
	GetPriority() int
	SetPriority(priority int)

	SetHandlerError(handlerNameWithError Name)
	GetHandlerError() Name

	SetLastHandler(handlerName Name)
	GetLastHandler() Name

	// Using for test mode only
	GetTestObject() ITestObject
	SetTestObject(ITestObject)
}

IItem is interface for support the single part on conveyor.

type IManager

type IManager interface {
	SetHandler(handler GiveBirth) IManager

	Start(ctx context.Context) error
	Stop()

	SetWorkersCounter(wc IWorkersCounter) IManager
	SetChanIn(in IChan) IManager
	SetChanOut(out IChan) IManager
	SetChanErr(errCh IChan) IManager

	GetNextManager() IManager
	SetNextManager(next IManager) IManager

	GetPrevManager() IManager
	SetPrevManager(previous IManager) IManager

	SetIsLast(isLast bool) IManager
	IsLast() bool

	SetWaitGroup(wg *sync.WaitGroup) IManager

	MetricPeriod(duration time.Duration) IManager

	Statistic() *nodes.ManagerData

	Name() Name

	// test mode
	// testObject - object for checking tests
	// startTestSuffix - suffix for start and stop workers methods
	SetTestMode(testObject ITestObject) IManager
}

IManager is an interface to rule the workers for single handler.

type ITestObject added in v0.0.21

type ITestObject interface {
	// Return
	Suffix() string
	IsTestMode() bool
	TestObject() *check.C
}

ITestObject is an interface to use conveyor in setup and troubleshooting mode.

type ITrace

type ITrace interface {
	// LazyPrintf evaluates its arguments with fmt.Sprintf each time the
	// /debug/requests page is rendered. Any memory referenced by a will be
	// pinned until the trace is finished and later discarded.
	LazyPrintf(format string, a ...interface{})

	// SetError declares that this trace resulted in an error.
	SetError()

	// Flush will call at the end on cycle.
	Flush()

	// Flush will call at the end on cycle.
	ForceFlush()
}

ITrace is an interface to support outside loggers.

type IWorkBench added in v0.2.0

type IWorkBench interface {
	// Set puts new IItem by number in WorkBench
	Add(item IItem) int
	// Get returns item by number in WorkBench
	Get(i int) (IItem, error)
	// Len returns the total length of WorkBench
	Len() int
	// Count returns the number of active IItem in WorkBench
	Count() int
	// Clean removes IItem from WorkBench (makes no-active)
	Clean(i int)
	// GetPriority returns the priority for item by number. If item is not fund, return 0.
	GetPriority(i int) int
}

IWorkBench is interface for support the storage for IItem.

type IWorker

type IWorker interface {
	Start(ctx context.Context) error

	Stop()

	SetTestMode(testObject ITestObject)

	SetBorderCond(typ ManagerType, isLast bool, nextManagerName Name)
	GetBorderCond() (Name, ManagerType, bool)

	Name() Name
	ID() string
}

IWorker is an interface to support using one handler from IManager.

type IWorkersCounter

type IWorkersCounter interface {
	Check(mc *nodes.ManagerData) (*nodes.ManagerAction, error)
}

IWorkersCounter realizes the interface to rule the numbers of workers for each manage. It gets the current information about workers and in/out channels for a manager and returns action for increase or decrease numbers of workers.

See simple realization in workerscounter directory.

type MainCh

type MainCh chan int

MainCh is a global type.

type ManagerType

type ManagerType string

ManagerType is a global type for define the manager position inside of conveyor.

const (
	// WorkerManagerType is a simple handler.
	WorkerManagerType ManagerType = "worker"
	// ErrorManagerType is a manager which gets all defective parts.
	ErrorManagerType ManagerType = "error"
	// FinalManagerType is a manager in th end of conveyor. "Test of the quality".
	FinalManagerType ManagerType = "final"
)

type Name

type Name string

Name is a global type for define the name of manager.

const (
	// UnknownName is a simple default name.
	UnknownName Name = "unknown"

	// ErrorName is a simple default name for error handler.
	ErrorName Name = "error"
)
const (
	// EmptySkipName is constant for skipped handlers.
	EmptySkipName Name = ""

	// SkipAll is constant to skip all rest handlers.
	SkipAll Name = "###SKIP_EVERYTHING_BY_THE_END"
)

Directories

Path Synopsis
Package mmock is a generated GoMock package.
Package mmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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