]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/producer/class_BaseProducer.php
Updated 'core'.
[hub.git] / application / hub / main / producer / class_BaseProducer.php
index 920c38b66f71b0fbad4a938fa7fba34dbdf50e00..8ac4cdfa13439cb832b7ee908bef428631d36bc1 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * 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;
+
+       /**
+        * 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
@@ -40,14 +55,29 @@ abstract class BaseProducer extends BaseFrameworkSystem {
                // 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 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 final function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) {
@@ -55,12 +85,22 @@ abstract class BaseProducer extends BaseFrameworkSystem {
        }
 
        /**
-        * 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 final 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 +111,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->initOutgoingQueue();
+
+               // Get an instance and set it in this producer
+               $this->setIncomingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_incoming_queue'));
 
                // Init the queue
-               $this->getOutgoingQueueInstance()->initStacker('work_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));
        }
 }