public function main() { @(include_once 'phing/contrib/DocBlox/Parallel/Manager.php'); @(include_once 'phing/contrib/DocBlox/Parallel/Worker.php'); @(include_once 'phing/contrib/DocBlox/Parallel/WorkerPipe.php'); if (!class_exists('DocBlox_Parallel_Worker')) { throw new BuildException('ParallelTask depends on DocBlox being installed and on include_path.', $this->getLocation()); } $mgr = new DocBlox_Parallel_Manager(); $mgr->setProcessLimit($this->threadCount); foreach ($this->nestedTasks as $task) { $worker = new DocBlox_Parallel_Worker(array($task, 'perform'), array($task)); $mgr->addWorker($worker); } $mgr->execute(); }
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://docblox-project.org */ /** Include the manager as we do not autoload */ require_once 'Manager.php'; /** Include the worker as we do not autoload */ require_once 'Worker.php'; /** Include the worker's pipe as we do not autoload */ require_once 'WorkerPipe.php'; // ----------------------------------------------------------------------------- // method 1: using a fluent interface and the addWorker helper. // ----------------------------------------------------------------------------- $mgr = new DocBlox_Parallel_Manager(); $mgr->addWorker(new DocBlox_Parallel_Worker(function () { sleep(1); return 'a'; }))->addWorker(new DocBlox_Parallel_Worker(function () { sleep(1); return 'b'; }))->addWorker(new DocBlox_Parallel_Worker(function () { sleep(1); return 'c'; }))->addWorker(new DocBlox_Parallel_Worker(function () { sleep(1); return 'd'; }))->addWorker(new DocBlox_Parallel_Worker(function () { sleep(1); return 'e'; }))->execute(); /** @var DocBlox_Parallel_Worker $worker */ foreach ($mgr as $worker) {
/** * Processes a list of files & directories * * @param Task $callee * @param PhingFile $fromDir * @param array $srcFiles * @param array $srcDirs */ protected function process(DocBlox_Parallel_Manager $parallelManager, Task $callee, PhingFile $fromDir, $srcFiles, $srcDirs) { $mapper = null; if ($this->mapperElement !== null) { $mapper = $this->mapperElement->getImplementation(); } $filecount = count($srcFiles); $this->total_files += $filecount; for ($j = 0; $j < $filecount; $j++) { $value = $srcFiles[$j]; $premapped = ""; if ($this->absparam) { $prop = $callee->createProperty(); $prop->setOverride(true); $prop->setName($this->absparam); $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value); } if ($mapper !== null) { $premapped = $value; $value = $mapper->main($value); if ($value === null) { continue; } $value = array_shift($value); } if ($this->param) { $this->log("Setting param '{$this->param}' to value '{$value}'" . ($premapped ? " (mapped from '{$premapped}')" : ''), Project::MSG_VERBOSE); $prop = $callee->createProperty(); $prop->setOverride(true); $prop->setName($this->param); $prop->setValue($value); } $worker = new DocBlox_Parallel_Worker(array($callee, 'main'), array($callee)); $parallelManager->addWorker($worker); } $dircount = count($srcDirs); $this->total_dirs += $dircount; for ($j = 0; $j < $dircount; $j++) { $value = $srcDirs[$j]; $premapped = ""; if ($this->absparam) { $prop = $callee->createProperty(); $prop->setOverride(true); $prop->setName($this->absparam); $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value); } if ($mapper !== null) { $premapped = $value; $value = $mapper->main($value); if ($value === null) { continue; } $value = array_shift($value); } if ($this->param) { $this->log("Setting param '{$this->param}' to value '{$value}'" . ($premapped ? " (mapped from '{$premapped}')" : ''), Project::MSG_VERBOSE); $prop = $callee->createProperty(); $prop->setOverride(true); $prop->setName($this->param); $prop->setValue($value); } $worker = new DocBlox_Parallel_Worker(array($callee, 'main'), array($callee)); $parallelManager->addWorker($worker); } }