예제 #1
0
 /**
  * Updates size of the given storage and saves information to this.
  *
  * @param storageData Storage data.
  * @throws IOException If {@link IOException} happened during operation.
  * @throws SerializationException If serialization failed.
  */
 private void updateExistingStorageSize(StorageData storageData)
     throws IOException, SerializationException {
   if (null != storageData) {
     synchronized (storageData) {
       long newSize = getDiskSizeForStorage(storageData);
       if (newSize != storageData.getDiskSize()) {
         storageData.setDiskSize(newSize);
         writeStorageDataToDisk(storageData);
       }
     }
   }
 }
예제 #2
0
  /**
   * Closes the storage if it is open.
   *
   * @param storageData Storage.
   * @throws BusinessException When storage that should be closed is used for recording or it is
   *     already closed.
   * @throws SerializationException If serialization fails.
   * @throws IOException If {@link IOException} occurs.
   */
  public void closeStorage(StorageData storageData)
      throws BusinessException, IOException, SerializationException {
    StorageData local = getLocalStorageDataObject(storageData);
    synchronized (local) {
      if ((storageRecorder.isRecordingOn() || storageRecorder.isRecordingScheduled())
          && Objects.equals(local, recorderStorageData)) {
        throw new BusinessException(
            "Close the storage " + local + ".", StorageErrorCodeEnum.STORAGE_CAN_NOT_BE_CLOSED);
      } else if (isStorageClosed(local)) {
        throw new BusinessException(
            "Close the storage " + local + ".", StorageErrorCodeEnum.STORAGE_ALREADY_CLOSED);
      }

      StorageWriter writer = openedStoragesMap.get(local);
      if (writer != null) {
        writer.closeStorageWriter();
      }
      openedStoragesMap.remove(local);
      local.setDiskSize(getDiskSizeForStorage(local));
      local.markClosed();
      writeStorageDataToDisk(local);
    }
  }