* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ abstract class BaseProducer extends BaseFrameworkSystem { /** * Outgoing work-queue */ private $outgoingQueueInstance = NULL; /** * Incoming raw data/items queue */ private $incomingQueueInstance = NULL; /** * Stacker name for incoming work */ const STACKER_NAME_IN_QUEUE = 'incoming_queue'; /** * Stacker name for outgoing work */ const STACKER_NAME_OUT_QUEUE = 'outgoing_queue'; /** * Protected constructor * * @param $className Name of the class * @return void */ protected function __construct ($className) { // Call parent constructor parent::__construct($className); // Initialize all producers $this->initProducer(); // Initialize work queue (out-going, produced items) $this->initWorkQueue(); } /** * Getter for outgoing work queue * * @param $outgoingQueueInstance The outgoing work queue instance */ protected final function getOutgoingQueueInstance () { return $this->outgoingQueueInstance; } /** * Setter for outgoing work queue * * @param $outgoingQueueInstance The outgoing work queue instance * @return void */ private final function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) { $this->outgoingQueueInstance = $outgoingQueueInstance; } /** * Getter for incoming raw data/items queue * * @param $incomingQueueInstance The incoming raw data/items queue instance */ protected final function getIncomingQueueInstance () { return $this->incomingQueueInstance; } /** * Setter for incoming raw data/items queue * * @param $incomingQueueInstance The incoming raw data/items queue instance * @return void */ private final function setIncomingQueueInstance (Stackable $incomingQueueInstance) { $this->incomingQueueInstance = $incomingQueueInstance; } /** * Initializes this producer, this method must be overwritten. * * @return void */ abstract protected function initProducer(); /** * Initializes the work queue which is being used for outgoing, produced * items. * * @return void */ protected function initWorkQueue () { // Get an instance and set it in this producer $this->setOutgoingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_outgoing_queue')); // Init the queue $this->initOutgoingQueue(); // Get an instance and set it in this producer $this->setIncomingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_incoming_queue')); // Init the queue $this->initIncomingQueue(); // Debug message self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: All queues have been initialized.'); } /** * Inits the out-going queue stack * * @return void */ protected function initOutgoingQueue () { $this->getOutgoingQueueInstance()->initStack(self::STACKER_NAME_OUT_QUEUE, TRUE); } /** * Adds an entry to the out-going work queue * * @param $value The value to be added to the out-going work queue * @return void */ protected function addValueToOutgoingQueue ($value) { $this->getOutgoingQueueInstance()->pushNamed(self::STACKER_NAME_OUT_QUEUE, $value); } /** * Checks whether a configurable out-going queue limit has been reached * * @param $configEntry Configuration entry where the limit is stored * @return $isReached Whether the limit is reached */ protected function isOutgoingQueueLimitReached ($configEntry) { return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getOutgoingQueueInstance()->getStackCount(self::STACKER_NAME_OUT_QUEUE)); } /** * Inits the incoming queue stack * * @return void */ protected function initIncomingQueue () { $this->getIncomingQueueInstance()->initStack(self::STACKER_NAME_IN_QUEUE, TRUE); } /** * Adds an entry to the incoming work queue * * @param $value The value to be added to the incoming work queue * @return void */ protected function addValueToIncomingQueue ($value) { $this->getIncomingQueueInstance()->pushNamed(self::STACKER_NAME_IN_QUEUE, $value); } /** * Checks whether a configurable incoming queue limit has been reached * * @param $configEntry Configuration entry where the limit is stored * @return $isReached Whether the limit is reached */ protected function isIncomingQueueLimitReached($configEntry) { return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getIncomingQueueInstance()->getStackCount(self::STACKER_NAME_IN_QUEUE)); } } // [EOF] ?>