]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php
Cruncher continued and rewritten to use states:
[hub.git] / application / hub / main / producer / cruncher / work_units / class_CruncherTestUnitProducer.php
index 673e9d037f47431af0ccc824fd2ab25d46ef25a9..4c88ff6f4f536632dfb64cc75d38014494d112c5 100644 (file)
@@ -72,12 +72,13 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer,
        }
 
        /**
-        * Produces some test units and pushes them onto the queue
+        * Prepares the produces of some test units and pushes them onto the queue
         *
+        * @param       $stateInstance  An instance of a Stateable instance
         * @return      void
-        * @todo        ~30% done
+        * @todo        ~60% done
         */
-       public function produceUnits () {
+       public function prepareUnitProduction (Stateable $stateInstance) {
                // First get a database wrapper because we want to permanently store test units
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('cruncher_unit_db_wrapper_class');
 
@@ -97,6 +98,9 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer,
                        // Entries found
                        // @TODO Unfinished work here
                        $this->debugInstance();
+
+                       // The state must be changed because ...
+                       $stateInstance->someFooStateChange();
                } else {
                        // Get an encrypted, random message from our source
                        $encryptedMessage = $this->getHelperInstance()->generateRandomMessage();
@@ -107,31 +111,8 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer,
                        // Set the encrypted message in the template instance
                        $this->getTemplateInstance()->assignVariable('encrypted_message', $encryptedMessage);
 
-                       /*
-                        * Now we need to create an iterator, just as for the work units,
-                        * to create new keys from the encrypted message. The iterator will
-                        * not iterate over an object nor a collection. It will instead
-                        * encapsulate the "key production" into a class and not in a simple
-                        * for() loop. These keys then needs to be bundled into test units
-                        * and stored to database for later re-usage.
-                        */
-
-                       // First get an iterator, again the helper will do that for us
-                       $iteratorInstance = $this->getHelperInstance()->getKeyIterator();
-
-                       // Begin the "key production"
-                       while ($iteratorInstance->valid()) {
-                               // Get current key (which is not the key of the iterator)
-                               $currentKey = $iteratorInstance->current();
-
-                               // @TODO Do something with it
-                               $this->debugOutput('currentKey=' . $currentKey . ' needs to be processed.');
-
-                               // Continue with next one
-                               $iteratorInstance->next();
-                       } // END - while
-
-                       die(__METHOD__ . ": Ended the key production.\n");
+                       // The state must be changed because we have a new message
+                       $stateInstance->encryptedMessageGenerated();
                }
        }
 }