Continued with indexes/stacks:
authorRoland Haeder <roland@mxchange.org>
Mon, 19 May 2014 21:10:35 +0000 (23:10 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 19 May 2014 21:16:39 +0000 (23:16 +0200)
- The FileStackIndexFactory now uses the Registry Pattern to have one index
  instance per given type.
- Passed through $prefix as "type"

Signed-off-by: Roland H├Ąder <roland@mxchange.org>
inc/classes/main/factories/index/class_FileStackIndexFactory.php
inc/classes/main/factories/stacks/class_FileStackFactory.php
inc/classes/main/stacker/file/class_BaseFileStack.php
inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php

index ca1fb7c..df10a1c 100644 (file)
@@ -38,9 +38,18 @@ class FileStackIndexFactory extends ObjectFactory {
         * @param       $stackName                      Name of the stack's file
         * @return      $indexInstance          An instance of a IndexableStack class
         */
-       public static final function createFileStackIndexInstance ($fileName) {
-               // Call parent factory
-               $indexInstance self::createObjectByConfiguredName('file_stack_index_class', array($fileName));
+       public static final function createFileStackIndexInstance ($fileName, $type) {
+               // If there is no handler?
+               if (Registry::getRegistry()->instanceExists($type . '_index')) {
+                       // Get handler from registry
+                       $indexInstance = Registry::getRegistry()->getInstance($type . '_index');
+               } else {
+                       // Get the handler instance
+                       $indexInstance = self::createObjectByConfiguredName('file_stack_' . $type . '_index_class', array($fileName));
+
+                       // Add it to the registry
+                       Registry::getRegistry()->addInstance($type . '_index', $indexInstance);
+               }
 
                // Return the instance
                return $indexInstance;
index 8242187..8f0494e 100644 (file)
@@ -54,7 +54,7 @@ class FileStackFactory extends ObjectFactory {
                        $stackInstance = Registry::getRegistry()->getInstance($stackName . '_stack');
                } else {
                        // Get the handler instance
-                       $stackInstance = self::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($stackFileName));
+                       $stackInstance = self::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($stackFileName, $prefix));
 
                        // Add it to the registry
                        Registry::getRegistry()->addInstance($stackName . '_stack', $stackInstance);
index f505089..4ff2dfc 100644 (file)
@@ -442,9 +442,10 @@ class BaseFileStack extends BaseStacker {
         * Initializes this file-based stack.
         *
         * @param       $fileName       File name of this stack
+        * @param       $type           Type of this stack (e.g. url_source for URL sources)
         * @return      void
         */
-       protected function initFileStack ($fileName) {
+       protected function initFileStack ($fileName, $type) {
                // Get a file i/o pointer instance for stack file
                $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileName));
 
@@ -476,7 +477,7 @@ class BaseFileStack extends BaseStacker {
                 * Get stack index instance. This can be used for faster
                 * "defragmentation" and startup.
                 */
-               $indexInstance = FileStackIndexFactory::createFileStackIndex($fileName);
+               $indexInstance = FileStackIndexFactory::createFileStackIndexInstance($fileName, $type);
 
                // And set it here
                $this->setIndexInstance($indexInstance);
index 8d49b74..899338d 100644 (file)
@@ -36,14 +36,15 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Registerable
         * Creates an instance of this class
         *
         * @param       $fileName               Absolute Name of stack file
+        * @param       $type                   Type of this stack (e.g. url_source for URL sources)
         * @return      $stackInstance  An instance of a Stackable class
         */
-       public final static function createFiFoFileStack ($fileName) {
+       public final static function createFiFoFileStack ($fileName, $type) {
                // Get new instance
                $stackInstance = new FiFoFileStack();
 
                // Init this stack
-               $stackInstance->initFileStack($fileName);
+               $stackInstance->initFileStack($fileName, $type);
 
                // Return the prepared instance
                return $stackInstance;