Example #1
0
 /**
  * make local file
  * @param $fileInfo InputFile
  * @return string
  */
 public function localize($fileInfo)
 {
     $file = Config::get(Config::KEY_LOCALIZE_DIR) . '/' . $fileInfo->id;
     if (file_exists($file)) {
         unlink($file);
     }
     foreach ($fileInfo->chunkIds as $chunkId) {
         $content = $this->fileNode->get($chunkId);
         FileUtil::appendStringToFile($content, $file);
     }
     return $file;
 }
Example #2
0
 /**
  * Make load balance and get storage node id
  * pick a storage node randomly
  * @return int
  */
 public function getNodeId()
 {
     if (Config::get(Config::KEY_LOAD_BALANCE_STRICT)) {
         $this->getUsedNodes();
         $nodeId = $this->pickStrictly();
     } else {
         $nodeId = $this->pickOneNodeRandomly();
     }
     if ($nodeId === false) {
         FileException::pop('Fail to select storage node.');
     }
     return $nodeId;
 }
Example #3
0
 public function __construct()
 {
     $this->model = (new BaseModel())->setConnection(Config::get(Config::KEY_FILE_META_CONNECTION))->setCollection(Config::get(Config::KEY_FILE_META_COLLECTION));
 }
Example #4
0
 public function __construct($nodeId)
 {
     $nodeConfig = Config::getFileNodeConfig($nodeId);
     $this->model = (new BaseModel())->setCollection($nodeConfig['collection'])->setConnection($nodeConfig['connection']);
 }
Example #5
0
 public function __construct(array $config, LockerInterface $locker = null)
 {
     Config::load($config);
     $this->locker = $locker ?: new FileLocker();
 }
Example #6
0
 private function getChunkSize()
 {
     if (!$this->chunkSize) {
         $this->chunkSize = Config::get(Config::KEY_FILE_CHUNK_SIZE);
     }
     if (!$this->chunkSize) {
         FileException::pop('File chunk size is not set');
     }
     return $this->chunkSize;
 }
Example #7
0
 private function getLockerFile($fid)
 {
     return Config::get(Config::KEY_LOCKER_FILES_DIR) . '/' . $this->prefix . $fid;
 }