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 ca1fb7cc1363b6d63ca247f428d2e03585f49930..df10a1c84f0cb742b4067faf1c08402d7fd91443 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
         */
         * @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;
 
                // Return the instance
                return $indexInstance;
index 824218796c6d34ad30b1974d39a752f77e314f54..8f0494e5801b8203e7a27badd6b2adbd1f523cc4 100644 (file)
@@ -54,7 +54,7 @@ class FileStackFactory extends ObjectFactory {
                        $stackInstance = Registry::getRegistry()->getInstance($stackName . '_stack');
                } else {
                        // Get the handler instance
                        $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);
 
                        // Add it to the registry
                        Registry::getRegistry()->addInstance($stackName . '_stack', $stackInstance);
index f5050899ae5bca521b466e209daf0cb99fe97366..4ff2dfc5179d3afd32462d8ac5c6a4c4e6eb2988 100644 (file)
@@ -442,9 +442,10 @@ class BaseFileStack extends BaseStacker {
         * Initializes this file-based stack.
         *
         * @param       $fileName       File name of this stack
         * 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
         */
         * @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));
 
                // 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.
                 */
                 * 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);
 
                // And set it here
                $this->setIndexInstance($indexInstance);
index 8d49b74f26ab19f1c276e6be78ac23471cafbad0..899338d5983f60d03a959bf63fe239075b9eeb06 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
         * 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
         */
         * @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
                // Get new instance
                $stackInstance = new FiFoFileStack();
 
                // Init this stack
-               $stackInstance->initFileStack($fileName);
+               $stackInstance->initFileStack($fileName, $type);
 
                // Return the prepared instance
                return $stackInstance;
 
                // Return the prepared instance
                return $stackInstance;