Documentation
¶
Index ¶
- func Aggregate(results <-chan Result, done <-chan bool, ...) <-chan Result
- func Gather(files <-chan FileInfo, results chan<- Result, wg *sync.WaitGroup, ...)
- func Generate(done <-chan bool, generate func(chan<- FileInfo, chan<- Result)) (<-chan FileInfo, <-chan Result)
- func StartEngine(runner Runner, nprocs uint, generateHandler func(Result), ...) (err error)
- type AggregateFinalizerState
- type BasicResult
- type FileInfo
- type Priority
- type Result
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Aggregate ¶
func Aggregate(results <-chan Result, done <-chan bool, resultHandler func(Result, chan<- Result) bool, finalizer func(chan<- Result, *AggregateFinalizerState)) <-chan Result
Aggregate is a general purpose implementation to gather fileInfo results
func Gather ¶
func Gather(files <-chan FileInfo, results chan<- Result, wg *sync.WaitGroup, done <-chan bool, makeResult func(*FileInfo) (Result, *BasicResult), ctrl *utility.ReadChannelController)
Reads
func Generate ¶
func Generate( done <-chan bool, generate func(chan<- FileInfo, chan<- Result)) (<-chan FileInfo, <-chan Result)
Generate does all boilerplate required to be a valid generator
func StartEngine ¶
func StartEngine(runner Runner, nprocs uint, generateHandler func(Result), aggregateHandler func(Result)) (err error)
Runner Init must have been called beforehand as we don't know the values here The handlers receive a result of the respective stage and may perform whichever operation Returns the last error we received in either generator or aggregation stage
Types ¶
type AggregateFinalizerState ¶
type AggregateFinalizerState struct {
WasCancelled bool
FileCount, ErrCount uint
SizeBytes uint64
Elapsed float64
}
func (*AggregateFinalizerState) String ¶
func (a *AggregateFinalizerState) String() string
String generates a string with performance information
type BasicResult ¶
Implements information about any operation It's the minimum we need to work
func (*BasicResult) Error ¶
func (s *BasicResult) Error() error
func (*BasicResult) FileInformation ¶
func (s *BasicResult) FileInformation() *FileInfo
func (*BasicResult) Info ¶
func (s *BasicResult) Info() (string, Priority)
type FileInfo ¶
type FileInfo struct {
// path to file to handle
Path string
// size of file
Size int64
// hash of file
Sha1 []byte
MD5 []byte
}
A struct holding information about a task, including
type Result ¶
type Result interface {
// Return a string indicating the result, which can can also state an error
// The priority show the kind of result messgae, allowing you to filter them effectively
Info() (string, Priority)
// Return an error instance indicating what exactly when wrong
Error() error
// Return the FileInformation we represent
FileInformation() *FileInfo
}
type Runner ¶
type Runner interface {
// Intialize required members to deal with controlled reading and writing. numReaders and numWriters
// can be assumed to be valid
// Sets the items we are supposed to be working on - must be checked by implementation, as they are
// very generic in nature
Init(numReaders, numWriters int, items []string) error
// Launches a go-routine which fills the returned FileInfo channel
// Must close FileInfo channel when done
// Must listen for SIGTERM|SIGINT signals and abort if received
// May report errrors or information about the progress through generateResult, which must NOT be closed when done. Return nothing
// if there is nothing to report
// Must listen on done and return asap
Generate(done <-chan bool) (files <-chan FileInfo, generateResult <-chan Result)
// Will be launched as go routine and perform whichever operation on the FileInfo received from input channel
// Produces one result per input FileInfo and returns it in the given results channel
// Must listen for SIGTERM|SIGINT signals
// Use the wait group to mark when done
// Must listen on done and return asap
Gather(files <-chan FileInfo, results chan<- Result, wg *sync.WaitGroup, done <-chan bool)
// Aggregate the result channel and produce whatever you have to produce from the result of the Gather steps
// When you are done, place a single result instance into accumResult and close the channel
// You must listen on done to know if the operation was aborted prematurely. This information should be useful
// for your result.
Aggregate(results <-chan Result, done <-chan bool) <-chan Result
}
Click to show internal directories.
Click to hide internal directories.