예제 #1
0
  /**
   * Copies the content of the current CMR buffer to the Storage.
   *
   * @param storageData Storage to copy data to.
   * @param platformIdents List of agent IDs.
   * @param dataProcessors Processors that will be used for data writing.
   * @param autoFinalize If the storage where action is performed should be auto-finalized after the
   *     write.
   * @throws BusinessException If storage is used as a recording storage.
   * @throws SerializationException If storage needs to be created, and serialization fails.
   * @throws IOException If IO exception occurs.
   */
  public void copyBufferToStorage(
      StorageData storageData,
      List<Long> platformIdents,
      Collection<AbstractDataProcessor> dataProcessors,
      boolean autoFinalize)
      throws BusinessException, IOException, SerializationException {
    if (!isStorageExisting(storageData)) {
      this.createStorage(storageData);
    }
    StorageData local = getLocalStorageDataObject(storageData);
    if (!isStorageOpen(local)) {
      this.openStorage(local);
    }

    DefaultData oldestBufferElement = buffer.getOldestElement();
    // only copy if we have smth in the buffer
    if (null != oldestBufferElement) {

      // oldest date is the buffer oldest date, we don't include data from before
      Date fromDate = new Date(oldestBufferElement.getTimeStamp().getTime());
      Date toDate = null;

      // check if we have the time-frame limit
      for (AbstractDataProcessor dataProcessor : dataProcessors) {
        if (dataProcessor instanceof TimeFrameDataProcessor) {
          TimeFrameDataProcessor timeFrameDataProcessor = (TimeFrameDataProcessor) dataProcessor;
          // update dates
          if (timeFrameDataProcessor.getFromDate().after(fromDate)) {
            fromDate = timeFrameDataProcessor.getFromDate();
          }
          toDate = timeFrameDataProcessor.getToDate();
          break;
        }
      }

      for (Long platformId : platformIdents) {
        List<DefaultData> toWriteList =
            storageDataDao.getAllDefaultDataForAgent(platformId.longValue(), fromDate, toDate);
        this.writeToStorage(local, toWriteList, dataProcessors, true);
      }
    }

    if (autoFinalize) {
      this.closeStorage(local);
    }
    updateExistingStorageSize(local);
  }
예제 #2
0
  /**
   * Copies set of template data to storage. The storage does not have to be opened before action
   * can be executed (storage will be created/opened first in this case)
   *
   * @param storageData {@link StorageData} to copy to.
   * @param elementIds IDs of the elements to be saved.
   * @param platformIdent Platform ident elements belong to.
   * @param dataProcessors Processors to process the data. Can be null, then the data is only copied
   *     with no processing.
   * @param autoFinalize If the storage where action is performed should be auto-finalized after the
   *     write.
   * @throws IOException If {@link IOException} occurs.
   * @throws SerializationException If serialization fails when storage needs to be created/opened.
   * @throws BusinessException If {@link BusinessException} occurs.
   */
  public void copyDataToStorage(
      StorageData storageData,
      Collection<Long> elementIds,
      long platformIdent,
      Collection<AbstractDataProcessor> dataProcessors,
      boolean autoFinalize)
      throws IOException, SerializationException, BusinessException {
    if (!isStorageExisting(storageData)) {
      this.createStorage(storageData);
    }
    StorageData local = getLocalStorageDataObject(storageData);
    if (!isStorageOpen(local)) {
      this.openStorage(local);
    }

    List<DefaultData> toWriteList = storageDataDao.getDataFromIdList(elementIds, platformIdent);
    this.writeToStorage(local, toWriteList, dataProcessors, true);
    if (autoFinalize) {
      this.closeStorage(local);
    }
    updateExistingStorageSize(local);
  }
예제 #3
0
 /**
  * Updates the size of each existing storage, if it changed.
  *
  * <p>This method is called from a Spring configured job.
  *
  * @throws IOException If {@link IOException} happened during operation.
  * @throws SerializationException If serialization failed.
  */
 @Scheduled(fixedRate = UPDATE_RATE)
 protected void updateExistingStoragesSize() throws IOException, SerializationException {
   for (StorageData storageData : existingStoragesSet) {
     updateExistingStorageSize(storageData);
   }
 }