use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
use Org\Mxchange\CoreFramework\Stack\BaseStacker;
-use Org\Mxchange\CoreFramework\Stack\File\InvalidMagicException;
-use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait;
use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-abstract class BaseFileStack extends BaseStacker implements StackableFile {
+abstract class BaseFileStack extends BaseStacker {
// Load traits
use IndexableTrait;
use IteratorTrait;
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->initCountersGapsArray() ...');
$this->getIteratorInstance()->initCountersGapsArray();
- // Default is not created/already exists
- $created = false;
-
// Is the file's header initialized?
if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
// First pre-allocate a bit
// Then create file header
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: this->iteratorInstance->createFileHeader() ...');
$this->getIteratorInstance()->createFileHeader();
-
- // Set flag
- $created = true;
}
// Load the file header
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->readFileHeader() ...');
$this->readFileHeader();
- // Not created/already exists?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: created=%d', intval($created)));
- if (!$created) {
- // Count all entries in file
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->analyzeFileStructure() ...');
- $this->getIteratorInstance()->analyzeFileStructure();
- }
-
/*
* Get stack index instance. This can be used for faster
* "defragmentation" and startup.
*/
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: fileInfoInstance[%s]=%s,type=%s', get_class($fileInfoInstance), $fileInfoInstance, $type));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Creating index instance for fileInfoInstance[%s]=%s,type=%s ...', get_class($fileInfoInstance), $fileInfoInstance, $type));
$indexInstance = FileStackIndexFactory::createFileStackIndexInstance($fileInfoInstance, $type);
// And set it here
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: indexInstance=%s', $indexInstance->__toString()));
$this->setIndexInstance($indexInstance);
+ // Is the index loaded correctly and the stack file is just created?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->indexInstance->isIndexFileLoaded() ...');
+ if (!$this->getIndexInstance()->isIndexFileLoaded()) {
+ /*
+ * Something horrible has happened to the index as it should be
+ * loaded at this point. The stack's file structure then needs to
+ * be analyzed and the index rebuild.
+ */
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->analyzeFileStructure() ...');
+ $this->getIteratorInstance()->analyzeFileStructure();
+
+ // Rebuild index from file
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Calling this->iteratorInstance->rebuildIndexFromStack(%s) ...', $this->__toString()));
+ $this->getIndexInstance()->rebuildIndexFromStack($this);
+ }
+
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
}
*/
protected function addValueToStack (string $stackerName, $value) {
// Validate parameter
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s,value[%s]=%s - CALLED!', $stackerName, gettype($value), print_r($value, true)));
+ /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s,value[%s]=%s', $stackerName, gettype($value), print_r($value, true)));
if (empty($stackerName)) {
// No empty stack name
throw new InvalidArgumentException('Parameter "stackerName" is empty');
$data = $this->getIteratorInstance()->writeValueToFile($stackerName, $value);
// Add the hash and gap position to the index
- $this->getIndexInstance()->addHashToIndex($stackerName, $data);
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: data=%s', print_r($data, true));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Calling this->indexInstance->addHashedDataToIndex(%s,data()=%d) ...', $stackerName, count($data)));
+ $this->getIndexInstance()->addHashedDataToIndex($stackerName, $data);
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
return $isEmpty;
}
- /**
- * Initializes given stacker
- *
- * @param $stackerName Name of the stack
- * @param $forceReInit Force re-initialization
- * @return void
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public function initStack (string $stackerName, bool $forceReInit = false) {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Initializes all stacks
- *
- * @return void
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public function initStacks (array $stacks, bool $forceReInit = false) {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
/**
* Checks whether the given stack is initialized (set in array $stackers)
*