/**
* A general Producer class
*
- * @author Roland Haeder <webmaster@ship-simu.org>
+ * @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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
*/
abstract class BaseProducer extends BaseFrameworkSystem {
/**
- * Out-going work-queue
+ * Outgoing work-queue
*/
- private $outgoingQueueInstance = null;
+ private $outgoingQueueInstance = NULL;
/**
- * Every procuded item/unit/etc. usually have a source
+ * Incoming raw data/items queue
*/
- private $sourceInstance = null;
+ 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
// Initialize all producers
$this->initProducer();
+ // Get miner instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Change state to next state
+ $minerInstance->blockProducerHasInitialized($this);
+
// Initialize work queue (out-going, produced items)
$this->initWorkQueue();
}
/**
- * Setter for out-going work queue
+ * Getter for outgoing work queue
*
- * @param $outgoingQueueInstance The out-going work queue instance
- * @return void
+ * @param $outgoingQueueInstance The outgoing work queue instance
*/
- private function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) {
- $this->outgoingQueueInstance = $outgoingQueueInstance;
+ protected final function getOutgoingQueueInstance () {
+ return $this->outgoingQueueInstance;
}
/**
- * Getter for out-going work queue
+ * Setter for outgoing work queue
*
- * @param $outgoingQueueInstance The out-going work queue instance
+ * @param $outgoingQueueInstance The outgoing work queue instance
+ * @return void
*/
- protected function getOutgoingQueueInstance () {
- return $this->outgoingQueueInstance;
+ private final function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) {
+ $this->outgoingQueueInstance = $outgoingQueueInstance;
}
/**
- * Setter for a Sourceable instance
+ * Getter for incoming raw data/items queue
*
- * @param $sourceInstance The Sourceable instance
- * @return void
+ * @param $incomingQueueInstance The incoming raw data/items queue instance
*/
- protected function setSourceInstance (Sourceable $sourceInstance) {
- $this->sourceInstance = $sourceInstance;
+ protected final function getIncomingQueueInstance () {
+ return $this->incomingQueueInstance;
}
/**
- * Getter for a Sourceable instance
+ * Setter for incoming raw data/items queue
*
- * @param $sourceInstance The Sourceable instance
+ * @param $incomingQueueInstance The incoming raw data/items queue instance
+ * @return void
*/
- protected function getSourceInstance () {
- return $this->sourceInstance;
+ private final function setIncomingQueueInstance (Stackable $incomingQueueInstance) {
+ $this->incomingQueueInstance = $incomingQueueInstance;
}
/**
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));
}
}