X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fproducer%2Fclass_BaseProducer.php;h=a60634a899d7d3b157d811a6c6e002f4378769bb;hb=62f2546efa5ec7585c5ce216e6a9676595b1b30b;hp=2b20adeea3e121ea4fbc2a034d7f458fc9dacdce;hpb=d5598a16aba413db79b4e319cfabfb62da29d364;p=hub.git diff --git a/application/hub/main/producer/class_BaseProducer.php b/application/hub/main/producer/class_BaseProducer.php index 2b20adeea..a60634a89 100644 --- a/application/hub/main/producer/class_BaseProducer.php +++ b/application/hub/main/producer/class_BaseProducer.php @@ -2,11 +2,11 @@ /** * A general Producer class * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @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 @@ -23,9 +23,24 @@ */ abstract class BaseProducer extends BaseFrameworkSystem { /** - * Out-going work-queue + * Outgoing work-queue */ - private $outgoingQueueInstance = null; + 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 @@ -45,22 +60,41 @@ abstract class BaseProducer extends BaseFrameworkSystem { } /** - * Setter for out-going work queue + * 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 out-going work queue instance + * @param $outgoingQueueInstance The outgoing work queue instance * @return void */ - private function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) { + private final function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) { $this->outgoingQueueInstance = $outgoingQueueInstance; } /** - * Getter for out-going work queue + * Getter for incoming raw data/items queue * - * @param $outgoingQueueInstance The out-going work queue instance + * @param $incomingQueueInstance The incoming raw data/items queue instance */ - protected function getOutgoingQueueInstance () { - return $this->outgoingQueueInstance; + 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; } /** @@ -71,20 +105,84 @@ abstract class BaseProducer extends BaseFrameworkSystem { abstract protected function initProducer(); /** - * Initializes the work queue which is being used for out-going, produced + * 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_work_queue')); + $this->setOutgoingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_outgoing_queue')); // Init the queue - $this->getOutgoingQueueInstance()->initStacker('work_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 - $this->debugOutput('PRODUCER: Out-going work queue initialized.'); + 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)); } }