Rewrote to use constants and newly introduced method initStackers()
authorRoland Häder <roland@mxchange.org>
Wed, 17 Jul 2013 22:25:56 +0000 (22:25 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 17 Jul 2013 22:25:56 +0000 (22:25 +0000)
application/hub/main/cruncher/class_BaseHubCruncher.php
application/hub/main/handler/chunks/class_ChunkHandler.php
application/hub/main/producer/class_BaseProducer.php

index d55ba6bef23fe34867bdfa2c4632678d1f123b17..4f55a45a50fc20bcc40d07a21dabbddb93e295fc 100644 (file)
@@ -37,6 +37,16 @@ abstract class BaseHubCruncher extends BaseHubSystem implements Updateable {
         */
        private $bufferInstance = NULL;
 
+       /**
+        * Stacker name for incoming queue
+        */
+       const STACKER_NAME_IN_QUEUE = 'in_queue';
+
+       /**
+        * Stacker name for outcoming queue
+        */
+       const STACKER_NAME_OUT_QUEUE = 'out_queue';
+
        /**
         * Protected constructor
         *
@@ -148,8 +158,10 @@ abstract class BaseHubCruncher extends BaseHubSystem implements Updateable {
                $this->bufferInstance = ObjectFactory::createObjectByConfiguredName('cruncher_buffer_stacker_class');
 
                // Initialize common stackers, like in/out
-               $this->bufferInstance->initStacker('in_queue');
-               $this->bufferInstance->initStacker('out_queue');
+               $this->bufferInstance->initStackers(array(
+                       self::STACKER_NAME_IN_QUEUE,
+                       self::STACKER_NAME_OUT_QUEUE
+               ));
 
                // Output debug message
                self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER: All buffers are now initialized.');
index 03f51495770d26cd263ba2bb55825bc4fda4c575..5a188e5257160f1a479401c290bfc1e08d8246cd 100644 (file)
@@ -91,9 +91,11 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
                $stackerInstance = ObjectFactory::createObjectByConfiguredName('chunk_handler_stacker_class');
 
                // Init all stacker
-               $stackerInstance->initStacker(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP);
-               $stackerInstance->initStacker(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL);
-               $stackerInstance->initStacker(self::STACKER_NAME_ASSEMBLED_RAW_DATA);
+               $stackerInstance->initStackers(array(
+                       self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP,
+                       self::STACKER_NAME_CHUNKS_WITHOUT_FINAL,
+                       self::STACKER_NAME_ASSEMBLED_RAW_DATA
+               ));
 
                // Set the stacker in this handler
                $handlerInstance->setStackerInstance($stackerInstance);
index 898c9edf838781e73e8f30cbde8dc0dd03a0d20b..0dca07cadbdddaee24df6bbb1eda32304673f94d 100644 (file)
@@ -32,6 +32,16 @@ abstract class BaseProducer extends BaseFrameworkSystem {
         */
        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
         *
@@ -123,7 +133,7 @@ abstract class BaseProducer extends BaseFrameworkSystem {
         * @return      void
         */
        protected function initOutgoingQueue () {
-               $this->getOutgoingQueueInstance()->initStacker('outgoing_queue', true);
+               $this->getOutgoingQueueInstance()->initStacker(self::STACKER_NAME_OUT_QUEUE, true);
        }
 
        /**
@@ -133,7 +143,7 @@ abstract class BaseProducer extends BaseFrameworkSystem {
         * @return      void
         */
        protected function addValueToOutgoingQueue ($value) {
-               $this->getOutgoingQueueInstance()->pushNamed('outgoing_queue', $value);
+               $this->getOutgoingQueueInstance()->pushNamed(self::STACKER_NAME_OUT_QUEUE, $value);
        }
 
        /**
@@ -143,7 +153,7 @@ abstract class BaseProducer extends BaseFrameworkSystem {
         * @return      $isReached              Whether the limit is reached
         */
        protected function isOutgoingQueueLimitReached($configEntry) {
-               return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getOutgoingQueueInstance()->getStackCount('outgoing_queue'));
+               return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getOutgoingQueueInstance()->getStackCount(self::STACKER_NAME_OUT_QUEUE));
        }
 
        /**
@@ -152,7 +162,7 @@ abstract class BaseProducer extends BaseFrameworkSystem {
         * @return      void
         */
        protected function initIncomingQueue () {
-               $this->getIncomingQueueInstance()->initStacker('incoming_queue', true);
+               $this->getIncomingQueueInstance()->initStacker(self::STACKER_NAME_IN_QUEUE, true);
        }
 
        /**
@@ -162,7 +172,7 @@ abstract class BaseProducer extends BaseFrameworkSystem {
         * @return      void
         */
        protected function addValueToIncomingQueue ($value) {
-               $this->getIncomingQueueInstance()->pushNamed('incoming_queue', $value);
+               $this->getIncomingQueueInstance()->pushNamed(self::STACKER_NAME_IN_QUEUE, $value);
        }
 
        /**
@@ -172,7 +182,7 @@ abstract class BaseProducer extends BaseFrameworkSystem {
         * @return      $isReached              Whether the limit is reached
         */
        protected function isIncomingQueueLimitReached($configEntry) {
-               return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getIncomingQueueInstance()->getStackCount('incoming_queue'));
+               return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getIncomingQueueInstance()->getStackCount(self::STACKER_NAME_IN_QUEUE));
        }
 }