Factory

package
v0.0.0-...-eedd94a Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {
	DispatcherId    string         //流水线ID
	MaxWorkers      int            //流水线上的员工(Worker)最大数量
	Workers         []*Worker      //流水线上所有员工(Worker)对象集合
	Closed          chan bool      //流水线工作状态通道
	EndDispatch     chan os.Signal //流水线停止工作信号
	GJobQueue       chan Job       //流水线上的所有代加工产品(Job)队列通道
	GWorkbenchQueue chan chan Job  //流水线上的所有操作台队列通道
}

func NewDispatcher

func NewDispatcher(maxWorkers, maxQueue int) *Dispatcher

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch()

func (*Dispatcher) Run

func (d *Dispatcher) Run()

type Job

type Job struct {
	Payload Payload
}

任务

type Payload

type Payload struct {
	Name     string
	IpMask   string
	CallFunc func(string, string)
}

参考模型:工厂流水线->流水线员工->待加工产品

func (*Payload) Play

func (p *Payload) Play()

type WorkFlow

type WorkFlow struct {
	GDispatch *Dispatcher
}

func (*WorkFlow) AddJob

func (wf *WorkFlow) AddJob(wJob Job)

func (*WorkFlow) CloseWorkFlow

func (wf *WorkFlow) CloseWorkFlow()

func (*WorkFlow) StartWorkFlow

func (wf *WorkFlow) StartWorkFlow(maxWorkers, maxQueue int)

type Worker

type Worker struct {
	WorkerId        string        //员工ID
	WorkerName      string        //员工名字
	Workbench       chan Job      //员工加工产品的工作台,即来即走(无缓冲)。
	GWorkbenchQueue chan chan Job //等待分配加工产品的员工工作台队列
	Finished        chan bool     //员工结束工作通知通道,无缓冲
}

func NewWorker

func NewWorker(WorkbenchQueue chan chan Job, Id, Name string) *Worker

新建一条工厂流水线

func (*Worker) Start

func (w *Worker) Start()

工人开始工作

func (*Worker) Stop

func (w *Worker) Stop()

Jump to

Keyboard shortcuts

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