示例#1
0
 /**
  * Writes collection of {@link DefaultData} objects to the storage.
  *
  * @param storageData Storage to write.
  * @param dataToWrite Data to write.
  * @param dataProcessors Processors that will be used for data writing. Can be null. In this case,
  *     the direct write is done.
  * @param synchronously If write will be done synchronously or not.
  * @throws BusinessException If storage is used as a recording storage.
  * @throws SerializationException If serialization fails during auto-finalization.
  * @throws IOException If {@link IOException} occurs during auto-finalization.
  */
 public void writeToStorage(
     StorageData storageData,
     Collection<? extends DefaultData> dataToWrite,
     Collection<AbstractDataProcessor> dataProcessors,
     boolean synchronously)
     throws BusinessException, IOException, SerializationException {
   StorageData local = getLocalStorageDataObject(storageData);
   StorageWriter writer = openedStoragesMap.get(local);
   if (writer != null) {
     if (synchronously) {
       writer.processSynchronously(dataToWrite, dataProcessors);
     } else {
       writer.process(dataToWrite, dataProcessors);
     }
   } else if (Objects.equals(local, recorderStorageData)) {
     throw new BusinessException(
         "Write data to storage " + local + ".", StorageErrorCodeEnum.WRITE_FAILED);
   } else if (local.getState() == StorageState.CLOSED) {
     throw new BusinessException(
         "Write data to storage " + local + ".", StorageErrorCodeEnum.STORAGE_ALREADY_CLOSED);
   } else {
     log.error("Writer for the not closed storage " + local + " is not available.");
     throw new RuntimeException(
         "Writer for the not closed storage " + local + " is not available.");
   }
 }
示例#2
0
 /**
  * Returns the {@link WritingStatus} for the storage that is currently used as a recording one or
  * <code>null</code> if the recording is not active.
  *
  * @return {@link WritingStatus} if recording is active. <code>Null</code> otherwise.
  */
 public WritingStatus getRecordingStatus() {
   StorageWriter recordingStorageWriter = storageRecorder.getStorageWriter();
   if (null != recordingStorageWriter) {
     return recordingStorageWriter.getWritingStatus();
   } else {
     return null;
   }
 }
示例#3
0
 /**
  * Returns the status of the active storage writers. This can be used for logging purposes.
  *
  * @return Returns the status of the active storage writers.
  */
 public Map<StorageData, String> getWritersStatus() {
   Map<StorageData, String> map = new HashMap<StorageData, String>();
   for (Map.Entry<StorageData, StorageWriter> entry : openedStoragesMap.entrySet()) {
     map.put(entry.getKey(), entry.getValue().getExecutorServiceStatus());
   }
   if (storageRecorder.isRecordingOn()) {
     StorageData storageData = recorderStorageData;
     StorageWriter storageWriter = storageRecorder.getStorageWriter();
     if (null != storageData && null != storageWriter) {
       map.put(storageData, storageWriter.getExecutorServiceStatus());
     }
   }
   return map;
 }
示例#4
0
  /**
   * Returns the amount of writing tasks storage still has to process. Note that this is an
   * approximate number.
   *
   * @param storageData Storage data to get information for.
   * @return Returns number of queued tasks. Note that if the storage is not in writable mode <code>
   *     0</code> will be returned.
   */
  public long getStorageQueuedWriteTaskCount(StorageData storageData) {
    try {
      StorageData local = getLocalStorageDataObject(storageData);
      if (!isStorageOpen(local)) {
        return 0;
      }

      StorageWriter storageWriter = openedStoragesMap.get(local);
      if (null == storageWriter) {
        return 0;
      } else {
        return storageWriter.getQueuedTaskCount();
      }
    } catch (BusinessException e) {
      return 0;
    }
  }
示例#5
0
 /**
  * Deletes a storage information and files from disk.
  *
  * @param storageData {@link StorageData} to delete.
  * @throws BusinessException If storage is not closed.
  * @throws IOException If {@link IOException} occurs.
  */
 public void deleteStorage(StorageData storageData) throws BusinessException, IOException {
   StorageData local = getLocalStorageDataObject(storageData);
   synchronized (local) {
     if ((storageRecorder.isRecordingOn() || storageRecorder.isRecordingScheduled())
         && Objects.equals(local, recorderStorageData)) {
       throw new BusinessException(
           "Delete the storage " + local + ".", StorageErrorCodeEnum.STORAGE_ALREADY_CLOSED);
     }
     if (local.isStorageOpened()) {
       StorageWriter writer = openedStoragesMap.get(local);
       if (writer != null) {
         writer.cancel();
       }
       openedStoragesMap.remove(local);
     }
     deleteCompleteStorageDataFromDisk(local);
     existingStoragesSet.remove(local);
   }
 }
示例#6
0
 /**
  * Opens existing storage if it is not already opened.
  *
  * @param storageData Storage to open.
  * @return {@link StorageWriter} created for this storage. Of <code>null</code> if no new writer
  *     is created.
  * @throws IOException If {@link IOException} occurs.
  * @throws SerializationException If exception occurs during update of storage data.
  * @throws BusinessException If provided storage data does not exist or if the storage is closed.
  */
 public StorageWriter openStorage(StorageData storageData)
     throws IOException, SerializationException, BusinessException {
   StorageData local = getLocalStorageDataObject(storageData);
   synchronized (local) {
     if (isStorageClosed(local)) {
       throw new BusinessException(
           "Open the storage " + local + ".", StorageErrorCodeEnum.STORAGE_ALREADY_CLOSED);
     }
     if (!isStorageOpen(local)) {
       local.markOpened();
       StorageWriter writer = storageWriterProvider.getCmrStorageWriter();
       openedStoragesMap.put(local, writer);
       writer.prepareForWrite(local);
       writeStorageDataToDisk(local);
       return writer;
     }
   }
   return null;
 }
示例#7
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);
    }
  }