Documentation
¶
Index ¶
- Constants
- func ShutdownRoutinePools() bool
- type Job
- type JobResult
- type RoutinePool
- func (routPool *RoutinePool) ExecuteJob(job Job) bool
- func (routPool *RoutinePool) GetActiveRoutines() int32
- func (routPool *RoutinePool) GetCompletedJobsChannel() chan Job
- func (routPool *RoutinePool) GetLogger() *glog.Logger
- func (routPool *RoutinePool) GetQueuedWork() int32
- func (routPool *RoutinePool) GetResultChannel() chan Job
- func (routPool *RoutinePool) GetShutdownChannel() chan bool
- func (routPool *RoutinePool) HandleShutdown()
- func (routPool *RoutinePool) PerformanceStats()
- func (routPool *RoutinePool) SetLogger(logger *glog.Logger)
- type RoutinePoolConfig
- type WorkRoutine
Constants ¶
const ( // MaxRoutinePoolSize denotes the maximum number of goroutines that can be created in a RoutinePool MaxRoutinePoolSize int = 500 // MaxQueueCapacity denotes the maximum number of jobs that can added to the RoutinePool's queue MaxQueueCapacity int = 1000 )
Variables ¶
This section is empty.
Functions ¶
func ShutdownRoutinePools ¶
func ShutdownRoutinePools() bool
ShutdownRoutinePools closes all the channels related to the RoutinePools present in the routinePoolMap
Types ¶
type Job ¶
type Job interface { GetID() int DoJob(routinePool *RoutinePool) }
Job is the interface that denotes the job that will be execute by the WorkRoutine in the RoutinePool. It groups the DoJob and GetID methods
type JobResult ¶
type JobResult struct {
Result map[string]interface{}
}
JobResult contains the result of the job that has been executed by the WorkRoutine in the RoutinePool.
type RoutinePool ¶
type RoutinePool struct {
// contains filtered or unexported fields
}
RoutinePool is responsible for executing jobs added to it in separate goroutines
func GetRoutinePool ¶
func GetRoutinePool(routinePoolName string) *RoutinePool
GetRoutinePool returns the instance of the RoutinePool corresponding to the given name
func NewRoutinePool ¶
func NewRoutinePool(routinePoolConfig RoutinePoolConfig) (*RoutinePool, error)
NewRoutinePool creates a new RoutinePool with the given RoutinePoolConfig
func (*RoutinePool) ExecuteJob ¶
func (routPool *RoutinePool) ExecuteJob(job Job) bool
ExecuteJob adds the job to the jobChannel of the RoutinePool.
func (*RoutinePool) GetActiveRoutines ¶
func (routPool *RoutinePool) GetActiveRoutines() int32
GetActiveRoutines will return the number of routines performing work.
func (*RoutinePool) GetCompletedJobsChannel ¶
func (routPool *RoutinePool) GetCompletedJobsChannel() chan Job
GetCompletedJobsChannel returns the completed jobs channel of the RoutinePool
func (*RoutinePool) GetLogger ¶
func (routPool *RoutinePool) GetLogger() *glog.Logger
GetLogger returns the logger used by the RoutinePool
func (*RoutinePool) GetQueuedWork ¶
func (routPool *RoutinePool) GetQueuedWork() int32
GetQueuedWork will return the number of work items in queue.
func (*RoutinePool) GetResultChannel ¶
func (routPool *RoutinePool) GetResultChannel() chan Job
GetResultChannel returns the result channel of the RoutinePool
func (*RoutinePool) GetShutdownChannel ¶
func (routPool *RoutinePool) GetShutdownChannel() chan bool
GetShutdownChannel returns the shutdown channel of the RoutinePool
func (*RoutinePool) HandleShutdown ¶
func (routPool *RoutinePool) HandleShutdown()
HandleShutdown prints the performance stats of the RoutinePool RoutinePool listens for shutdown by implementing the HandleShutdown of the ShutdownListener
func (*RoutinePool) PerformanceStats ¶
func (routPool *RoutinePool) PerformanceStats()
PerformanceStats prints the performance stats related to the RoutinePool
func (*RoutinePool) SetLogger ¶
func (routPool *RoutinePool) SetLogger(logger *glog.Logger)
SetLogger sets the logger for the RoutinePool
type RoutinePoolConfig ¶
type RoutinePoolConfig struct { RoutinePoolName string RoutinePoolSize int QueueCapacity int //Maximum number of jobs that can be added to the routinepool without blocking the calling thread. Logger *glog.Logger }
RoutinePoolConfig contains necessary attributes for creating a RoutinePool
func (RoutinePoolConfig) String ¶
func (poolConfig RoutinePoolConfig) String() string
type WorkRoutine ¶
type WorkRoutine struct {
// contains filtered or unexported fields
}
WorkRoutine runs the job in individual goroutines
func NewWorkRoutine ¶
func NewWorkRoutine(routinePool *RoutinePool, routineID int) *WorkRoutine
NewWorkRoutine returns a WorkRoutine with a name and an ID
func (WorkRoutine) String ¶
func (workRoutine WorkRoutine) String() string