queue

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 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 BufferMap

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

缓冲键值表

func NewBufferMap

func NewBufferMap() *BufferMap

新建缓冲键值表对象

func (*BufferMap) Clear

func (m *BufferMap) Clear()

清空键值表

func (*BufferMap) Get

func (m *BufferMap) Get(id interface{}) IBufferItem

读取键值

func (*BufferMap) Keys

func (m *BufferMap) Keys() []interface{}

读取全部键

func (*BufferMap) Pop

func (m *BufferMap) Pop(id interface{}) IBufferItem

读取并移除键值

func (*BufferMap) PopAll

func (m *BufferMap) PopAll() []IBufferItem

读取并移除全部键值

func (*BufferMap) Push

func (m *BufferMap) Push(item IBufferItem) int

置入键值

func (*BufferMap) Remove

func (m *BufferMap) Remove(id interface{})

移除键值

func (*BufferMap) Size

func (m *BufferMap) Size() int

获取大小

func (*BufferMap) Values

func (m *BufferMap) Values() []IBufferItem

读取全部值

type BufferPostman

type BufferPostman struct {
	Buffer *BufferMap
	// contains filtered or unexported fields
}

缓冲投递员

func NewBufferPostman

func NewBufferPostman(limit int, duration time.Duration, target chan interface{}) *BufferPostman

新建缓冲投递员对象

func (*BufferPostman) Push

func (p *BufferPostman) Push(item IBufferItem)

置入消息

type ChanDispatcher

type ChanDispatcher struct {
	MsgQueue   chan interface{}      // 消息输入管道
	WorkerPool chan chan interface{} // 工作管道池
	// contains filtered or unexported fields
}

调度对象

func NewChanDispatcher

func NewChanDispatcher(msgQueue chan interface{}, maxWorkers int) *ChanDispatcher

func (*ChanDispatcher) Run

func (d *ChanDispatcher) Run(callback func(workerId int, msg interface{}))

type ChanWorker

type ChanWorker struct {
	ID         int                   // 工作对象编号
	WorkerPool chan chan interface{} // 工作管道池,实例化时由调度器传入
	JobChannel chan interface{}      // 工作管道
	// contains filtered or unexported fields
}

工作对象封装

func NewChanWorker

func NewChanWorker(workerId int, workerPool chan chan interface{}) *ChanWorker

func (*ChanWorker) Start

func (w *ChanWorker) Start(callback func(workerId int, msg interface{}))

type IBufferItem

type IBufferItem interface {
	BufferID() interface{}                 // 去重用的键,包括后续消费消息,如果需要也可以根据这个键做散列处理
	Reduce(oldVal IBufferItem) IBufferItem // 接口实现类中实现此方法,以实现累加之类的多态的业务逻辑,当然最简单不做其他处理直接返回新的对象值自身也行
}

缓冲消息接口

Jump to

Keyboard shortcuts

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