From fa4a8357806244a39eb6e8dadf028190b03d34fb Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 19 May 2014 23:10:35 +0200 Subject: [PATCH] Continued with indexes/stacks: - The FileStackIndexFactory now uses the Registry Pattern to have one index instance per given type. - Passed through $prefix as "type" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../index/class_FileStackIndexFactory.php | 15 ++++++++++++--- .../factories/stacks/class_FileStackFactory.php | 2 +- .../main/stacker/file/class_BaseFileStack.php | 5 +++-- .../stacker/file/fifo/class_FiFoFileStack.php | 5 +++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/inc/classes/main/factories/index/class_FileStackIndexFactory.php b/inc/classes/main/factories/index/class_FileStackIndexFactory.php index ca1fb7cc..df10a1c8 100644 --- a/inc/classes/main/factories/index/class_FileStackIndexFactory.php +++ b/inc/classes/main/factories/index/class_FileStackIndexFactory.php @@ -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; diff --git a/inc/classes/main/factories/stacks/class_FileStackFactory.php b/inc/classes/main/factories/stacks/class_FileStackFactory.php index 82421879..8f0494e5 100644 --- a/inc/classes/main/factories/stacks/class_FileStackFactory.php +++ b/inc/classes/main/factories/stacks/class_FileStackFactory.php @@ -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); diff --git a/inc/classes/main/stacker/file/class_BaseFileStack.php b/inc/classes/main/stacker/file/class_BaseFileStack.php index f5050899..4ff2dfc5 100644 --- a/inc/classes/main/stacker/file/class_BaseFileStack.php +++ b/inc/classes/main/stacker/file/class_BaseFileStack.php @@ -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); diff --git a/inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php b/inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php index 8d49b74f..899338d5 100644 --- a/inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php +++ b/inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php @@ -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; -- 2.39.5