예제 #1
0
  /**
   * Store a file
   *
   * @param req FileRequest
   * @return int
   * @exception Exception
   */
  public int storeFile(FileRequest req) throws Exception {

    // Check for a single file request

    int saveSts = StsError;
    SingleFileRequest saveReq = (SingleFileRequest) req;

    // Check if the temporary file still exists, if not then the file has been deleted from the
    // filesystem

    File tempFile = new File(saveReq.getTemporaryFile());
    FileSegment fileSeg = findFileSegmentForPath(saveReq.getVirtualPath());

    if (tempFile.exists() == false || fileSeg == null) {

      // DEBUG

      if (Debug.EnableInfo && hasDebug()) Debug.println("  Temporary file deleted");

      // Return an error status

      return StsError;
    }

    // Run any file store processors

    runFileStoreProcessors(m_dbCtx, saveReq.getFileState(), fileSeg);

    // Update the segment status, and clear the updated flag

    fileSeg.setStatus(FileSegmentInfo.Saving);
    fileSeg.getInfo().setUpdated(false);

    // Save the file data

    try {

      // Save the file data and get the assigned object id

      String objectId =
          saveFileData(saveReq.getFileId(), saveReq.getStreamId(), fileSeg, req.getAttributes());

      // Save the object id to the mapping database

      getDBObjectIdInterface().saveObjectId(saveReq.getFileId(), saveReq.getStreamId(), objectId);

      // Indicate that the save was successful

      saveSts = StsSuccess;
    } catch (DBException ex) {

      // DEBUG

      if (Debug.EnableError && hasDebug()) Debug.println(ex);

      // Indicate the file save failed

      saveSts = StsError;
    } catch (IOException ex) {

      // DEBUG

      if (Debug.EnableError && hasDebug()) Debug.println(ex);

      // Indicate the file save failed

      saveSts = StsError;
    }

    // Update the segment status

    if (saveSts == StsSuccess) fileSeg.setStatus(FileSegmentInfo.Saved, false);
    else fileSeg.setStatus(FileSegmentInfo.Error, false);

    // Return the data save status

    return saveSts;
  }
예제 #2
0
  /**
   * Load a file
   *
   * @param req FileRequest
   * @return int
   * @exception Exception
   */
  public int loadFile(FileRequest req) throws Exception {

    // DEBUG

    long startTime = 0L;
    SingleFileRequest loadReq = (SingleFileRequest) req;

    if (Debug.EnableInfo && hasDebug()) {
      Debug.println(
          "## ObjIdLoader loadFile() req="
              + loadReq.toString()
              + ", thread="
              + Thread.currentThread().getName());
      startTime = System.currentTimeMillis();
    }

    // Check if the temporary file still exists, if not then the file has been deleted from the
    // filesystem

    File tempFile = new File(loadReq.getTemporaryFile());
    FileSegment fileSeg = findFileSegmentForPath(loadReq.getVirtualPath());

    if (tempFile.exists() == false || fileSeg == null) {

      // DEBUG

      if (Debug.EnableInfo && hasDebug()) Debug.println("  Temporary file deleted");

      // Return an error status

      fileSeg.setStatus(FileSegmentInfo.Error, false);
      return StsError;
    }

    // DEBUG

    if (Debug.EnableInfo && hasDebug())
      Debug.println(
          "## ObjIdLoader fileSeg="
              + fileSeg.getTemporaryFile()
              + ", virtPath="
              + loadReq.getVirtualPath());

    // Load the file data

    int loadSts = StsRequeue;
    String objectId = null;

    int fileId = loadReq.getFileId();
    int strmId = loadReq.getStreamId();

    try {

      // Update the segment status

      fileSeg.setStatus(FileSegmentInfo.Loading);

      // Get the object id for the file

      objectId = getDBObjectIdInterface().loadObjectId(fileId, strmId);

      if (objectId != null) {

        // Load the file data

        loadFileData(fileId, strmId, objectId, fileSeg);

        // Set the load status

        loadSts = StsSuccess;

        // DEBUG

        if (Debug.EnableInfo && hasDebug()) {
          long endTime = System.currentTimeMillis();
          Debug.println(
              "## ObjIdLoader loaded fid="
                  + loadReq.getFileId()
                  + ", stream="
                  + loadReq.getStreamId()
                  + ", time="
                  + (endTime - startTime)
                  + "ms");
        }
      } else {

        // DEBUG

        if (Debug.EnableInfo && hasDebug())
          Debug.println(
              "## ObjIdLoader No object id mapping for fid="
                  + loadReq.getFileId()
                  + ", stream="
                  + loadReq.getStreamId());

        // Indicate a load success

        loadSts = StsSuccess;
      }
    } catch (DBException ex) {

      // DEBUG

      if (Debug.EnableError && hasDebug()) Debug.println(ex);

      // Indicate the file load failed

      loadSts = StsError;
    } catch (FileOfflineException ex) {

      // DEBUG

      if (Debug.EnableError && hasDebug()) Debug.println(ex);

      // Indicate the file load failed

      loadSts = StsError;
    } catch (IOException ex) {

      // DEBUG

      if (Debug.EnableError && hasDebug()) Debug.println(ex);

      // Indicate the file load failed

      loadSts = StsRequeue;
    } catch (Exception ex) {

      // DEBUG

      if (Debug.EnableError && hasDebug()) Debug.println(ex);

      // Indicate the file load failed

      loadSts = StsError;
    }

    // Clear the last modified date/time of the temporary file to indicate it has not been updated

    tempFile.setLastModified(0L);

    // Check if the file was loaded successfully

    if (loadSts == StsSuccess) {

      // Signal that the file data is available

      fileSeg.signalDataAvailable();

      // Update the file status

      fileSeg.setStatus(FileSegmentInfo.Available, false);

      // Run the file load processors

      runFileLoadedProcessors(getContext(), loadReq.getFileState(), fileSeg);
    } else if (loadSts == StsError) {

      // Set the file status to indicate error to any client reading threads

      fileSeg.setStatus(FileSegmentInfo.Error, false);

      // Wakeup any threads waiting on data for this file

      fileSeg.setReadableLength(0L);
      fileSeg.signalDataAvailable();

      // Delete the temporary file

      fileSeg.deleteTemporaryFile();
    }

    // Return the load file status

    return loadSts;
  }