Documentation ¶
Overview ¶
package octopus implements a simple goroutine pool like java concurrent pool.
octopus project octopus.go
Index ¶
- Constants
- Variables
- type Callable
- type DataProcessFunc
- type DataProcessPool
- func NewBaseDataProcessPool(MinPoolSize uint64, MaxPoolSize uint64, KeepAliveTime time.Duration, ...) (dataProcessPool *DataProcessPool, err error)
- func NewCachedDataProcessPool(fn DataProcessFunc) (dataProcessPool *DataProcessPool, err error)
- func NewFixDataProcessPool(workerNum uint64, fn DataProcessFunc) (dataProcessPool *DataProcessPool, err error)
- func (pool *DataProcessPool) CanDropJob() bool
- func (pool *DataProcessPool) GetActiveCount() uint64
- func (pool *DataProcessPool) GetAwaitWorkerTime() time.Duration
- func (pool *DataProcessPool) GetCompletedJobCount() uint64
- func (pool *DataProcessPool) GetKeepAliveTime() time.Duration
- func (pool *DataProcessPool) GetMaxPoolSize() uint64
- func (pool *DataProcessPool) GetMinPoolSize() uint64
- func (pool *DataProcessPool) GetPoolSize() uint64
- func (pool *DataProcessPool) IsShutDown() bool
- func (pool *DataProcessPool) SetDropJob(ok bool)
- func (pool *DataProcessPool) SetKeepAliveTime(keepAliveTime time.Duration) error
- func (pool *DataProcessPool) SetLogFunc(function LogFunc)
- func (pool *DataProcessPool) SetMaxPoolSize(maxPoolSize uint64)
- func (pool *DataProcessPool) SetMinPoolSize(minPoolSize uint64)
- func (pool *DataProcessPool) Shutdown()
- func (pool *DataProcessPool) ShutdownNow()
- func (pool *DataProcessPool) Submit(job interface{}) (future Future, err error)
- type Future
- type LogFunc
- type Runnable
- type WorkPool
- func (pool *WorkPool) CanDropJob() bool
- func (pool *WorkPool) GetActiveCount() uint64
- func (pool *WorkPool) GetAwaitWorkerTime() time.Duration
- func (pool *WorkPool) GetCompletedJobCount() uint64
- func (pool *WorkPool) GetKeepAliveTime() time.Duration
- func (pool *WorkPool) GetMaxPoolSize() uint64
- func (pool *WorkPool) GetMinPoolSize() uint64
- func (pool *WorkPool) GetPoolSize() uint64
- func (pool *WorkPool) InvokeAllCallable(jobs []Callable) (futures []Future, err error)
- func (pool *WorkPool) InvokeAllRunnable(jobs []Runnable) (futures []Future, err error)
- func (pool *WorkPool) IsShutDown() bool
- func (pool *WorkPool) SetDropJob(ok bool)
- func (pool *WorkPool) SetKeepAliveTime(keepAliveTime time.Duration) error
- func (pool *WorkPool) SetLogFunc(function LogFunc)
- func (pool *WorkPool) SetMaxPoolSize(maxPoolSize uint64)
- func (pool *WorkPool) SetMinPoolSize(minPoolSize uint64)
- func (pool *WorkPool) Shutdown()
- func (pool *WorkPool) ShutdownNow()
- func (pool *WorkPool) SubmitCallable(job Callable) (future Future, err error)
- func (pool *WorkPool) SubmitRunnable(job Runnable) (future Future, err error)
Constants ¶
const ( JOBUNSTART uint32 = 0 JOBDOING uint32 = 1 JOBDONE uint32 = 2 JOBCRASH uint32 = 3 )
const ( JOBUNSTART uint32 = 0 JOBDOING uint32 = 1 JOBDONE uint32 = 2 )
const ( UNINTERRUPT uint32 = 3 INTERRUPT uint32 = 4 )
const ( WORKERFREE uint32 = 5 WORKERRUNNING uint32 = 6 WORKERSTOP uint32 = 7 )
const ( POOLOPEN uint32 = 8 POOLCLOSE uint32 = 9 )
Variables ¶
var ( ErrPoolShutdown = errors.New("the pool is closed") ErrJobTimedOut = errors.New("job request timed out") ErrRunnableNoResult = errors.New("runnable job has not a result value") ErrResultChannelClose = errors.New("result channel close") ErrInvalidArguments = errors.New("Invalid Arguments") ErrKeepAliveTimeArguments = errors.New("KeepAliveTime must be greater than 1 second") )
Functions ¶
This section is empty.
Types ¶
type DataProcessFunc ¶
type DataProcessFunc func(interface{}) interface{}
type DataProcessPool ¶
type DataProcessPool struct {
// contains filtered or unexported fields
}
func NewBaseDataProcessPool ¶
func NewBaseDataProcessPool(MinPoolSize uint64, MaxPoolSize uint64, KeepAliveTime time.Duration, AwaitWokerTime time.Duration, ProcessFn DataProcessFunc) (dataProcessPool *DataProcessPool, err error)
Creates a goroutine pool for processing data by defining a DataProcessFunction with MinPoolSize , MaxPoolSize, the KeepAliveTime of a worker, the time of manager await worker. Please note that the KeepAliveTime must be greater than one second.
func NewCachedDataProcessPool ¶
func NewCachedDataProcessPool(fn DataProcessFunc) (dataProcessPool *DataProcessPool, err error)
Creates a goroutine pool that creates new goroutines as needed for processing data by defining a DataProcessFunction, but will reuse previously constructed goroutines when they are available.
func NewFixDataProcessPool ¶
func NewFixDataProcessPool(workerNum uint64, fn DataProcessFunc) (dataProcessPool *DataProcessPool, err error)
Creates a goroutine pool for processing data by defining a DataProcessFunction that reuses a fixed number of goroutines.
func (*DataProcessPool) CanDropJob ¶
func (pool *DataProcessPool) CanDropJob() bool
CanDropJob will return if the manager will drop job datas when pool is busy.
func (*DataProcessPool) GetActiveCount ¶
func (pool *DataProcessPool) GetActiveCount() uint64
Return the approximate total number of woker executing a job data in pool.
func (*DataProcessPool) GetAwaitWorkerTime ¶
func (pool *DataProcessPool) GetAwaitWorkerTime() time.Duration
Return the awaitWorkerTime of pool manager.
func (*DataProcessPool) GetCompletedJobCount ¶
func (pool *DataProcessPool) GetCompletedJobCount() uint64
Return the approximate total number of jobs that have completed execution.
func (*DataProcessPool) GetKeepAliveTime ¶
func (pool *DataProcessPool) GetKeepAliveTime() time.Duration
Return the KeepAliveTime of a worker.
func (*DataProcessPool) GetMaxPoolSize ¶
func (pool *DataProcessPool) GetMaxPoolSize() uint64
Return the maximum allowed number of goroutines.
func (*DataProcessPool) GetMinPoolSize ¶
func (pool *DataProcessPool) GetMinPoolSize() uint64
Return the minimum number of goroutines.
func (*DataProcessPool) GetPoolSize ¶
func (pool *DataProcessPool) GetPoolSize() uint64
Return approximate total number of goroutines in pool.
func (*DataProcessPool) IsShutDown ¶
func (pool *DataProcessPool) IsShutDown() bool
if pool is close it will return true.
func (*DataProcessPool) SetDropJob ¶
func (pool *DataProcessPool) SetDropJob(ok bool)
Set drop job data if await worker timeout, it will drop job datas when manager appears awaitWorkerTime timeout.
func (*DataProcessPool) SetKeepAliveTime ¶
func (pool *DataProcessPool) SetKeepAliveTime(keepAliveTime time.Duration) error
Set the KeepAliveTime of a worker. Please note that it must be greater than one second.
func (*DataProcessPool) SetLogFunc ¶
func (pool *DataProcessPool) SetLogFunc(function LogFunc)
Set a log function to record log infos.
func (*DataProcessPool) SetMaxPoolSize ¶
func (pool *DataProcessPool) SetMaxPoolSize(maxPoolSize uint64)
Set the maximum allowed number of goroutines.
func (*DataProcessPool) SetMinPoolSize ¶
func (pool *DataProcessPool) SetMinPoolSize(minPoolSize uint64)
Set the minimum number of goroutines.
func (*DataProcessPool) Shutdown ¶
func (pool *DataProcessPool) Shutdown()
Close the pool and wait for all goroutines done, it may be block.
func (*DataProcessPool) ShutdownNow ¶
func (pool *DataProcessPool) ShutdownNow()
Close the pool but will not wait for all goroutines done, it will be never block.
func (*DataProcessPool) Submit ¶
func (pool *DataProcessPool) Submit(job interface{}) (future Future, err error)
Submit a job data for execution and return a Future representing the calculating result of that job data.
type Future ¶
type Future interface { // Cancel method will set a cancel tag attempt to cancel execute job before starting this job represented by Future. Cancel() error // Get method can get value from Callable , if not ready it will block. Get() (interface{}, error) // GetTimed method can get value from Callable with setting timeout. GetTimed(time.Duration) (interface{}, error) // IsCancelled will return whether the job was setting a cancel tag, but it does not mean that the job has been terminated. IsCancelled() bool //default 0 ,interrupt 1 // IsDone will return whether the job was done. IsDone() bool }
type WorkPool ¶
type WorkPool interface { IsPoolOpen() bool Close() Release() SubmitRunnable(Runnable) (Future, error) SubmitCallable(job Callable) (Future, error) InvokeAllRunnable([]Runnable) ([]Future, error) InvokeAllCallable([]Callable) ([]Future, error) // contains filtered or unexported methods }
func NewBaseCachedWorkerPool ¶
func NewBaseCachedWorkerPool(MinPoolSize uint64, MaxPoolSize uint64, KeepAliveTime time.Duration, AwaitWokerTime time.Duration) (workpool *WorkPool, err error)
Creates a goroutine pool with MinPoolSize , MaxPoolSize, the KeepAliveTime of a worker, the time of manager await worker. Please note that the KeepAliveTime must be greater than one second.
func NewCachedWorkerPool ¶
func NewCachedWorkerPool() (workpool *WorkPool, err error)
Creates a goroutine pool that creates new goroutines as needed, but will reuse previously constructed goroutines when they are available.
func NewFixWorkerPool ¶
Creates a goroutine pool that reuses a fixed number of goroutines.
func (*WorkPool) CanDropJob ¶
func (pool *WorkPool) CanDropJob() bool
CanDropJob will return if the manager will drop jobs when pool is busy.
func (*WorkPool) GetActiveCount ¶
func (pool *WorkPool) GetActiveCount() uint64
Return the approximate total number of woker executing a job in pool.
func (*WorkPool) GetAwaitWorkerTime ¶
Return the awaitWorkerTime of pool manager.
func (*WorkPool) GetCompletedJobCount ¶
func (pool *WorkPool) GetCompletedJobCount() uint64
Return the approximate total number of jobs that have completed execution.
func (*WorkPool) GetKeepAliveTime ¶
Return the KeepAliveTime of a worker.
func (*WorkPool) GetMaxPoolSize ¶
func (pool *WorkPool) GetMaxPoolSize() uint64
Return the maximum allowed number of goroutines.
func (*WorkPool) GetMinPoolSize ¶
func (pool *WorkPool) GetMinPoolSize() uint64
Return the minimum number of goroutines.
func (*WorkPool) GetPoolSize ¶
func (pool *WorkPool) GetPoolSize() uint64
Return approximate total number of goroutines in pool.
func (*WorkPool) InvokeAllCallable ¶
func (pool *WorkPool) InvokeAllCallable(jobs []Callable) (futures []Future, err error)
Submit Callable jobs for execution and return Futures representing those jobs.
func (*WorkPool) InvokeAllRunnable ¶
func (pool *WorkPool) InvokeAllRunnable(jobs []Runnable) (futures []Future, err error)
Submit Runnable jobs for execution and return Futures representing those jobs.
func (*WorkPool) IsShutDown ¶
func (pool *WorkPool) IsShutDown() bool
if pool is close it will return true.
func (*WorkPool) SetDropJob ¶
func (pool *WorkPool) SetDropJob(ok bool)
Set drop job if await worker timeout, it will drop jobs when manager appears awaitWorkerTime timeout .
func (*WorkPool) SetKeepAliveTime ¶
Set the KeepAliveTime of a worker. Please note that it must be greater than one second.
func (*WorkPool) SetLogFunc ¶
func (pool *WorkPool) SetLogFunc(function LogFunc)
Set a log function to record log infos.
func (*WorkPool) SetMaxPoolSize ¶
func (pool *WorkPool) SetMaxPoolSize(maxPoolSize uint64)
Set the maximum allowed number of goroutines.
func (*WorkPool) SetMinPoolSize ¶
func (pool *WorkPool) SetMinPoolSize(minPoolSize uint64)
Set the minimum number of goroutines.
func (*WorkPool) Shutdown ¶
func (pool *WorkPool) Shutdown()
Close the pool and wait for all goroutines done, it may be block.
func (*WorkPool) ShutdownNow ¶
func (pool *WorkPool) ShutdownNow()
Close the pool but will not wait for all goroutines done, it will be never block.
func (*WorkPool) SubmitCallable ¶
func (pool *WorkPool) SubmitCallable(job Callable) (future Future, err error)
Submit a Callable job for execution and return a Future representing that job.
func (*WorkPool) SubmitRunnable ¶
func (pool *WorkPool) SubmitRunnable(job Runnable) (future Future, err error)
Submit a Runnable job for execution and return a Future representing that job.