예제 #1
0
  /**
   * Close the network file
   *
   * @param sess SrvSession
   * @param netFile NetworkFile
   * @exception IOException
   */
  public void closeFile(SrvSession sess, NetworkFile netFile) throws IOException {

    // Close the cached network file

    if (netFile instanceof CachedNetworkFile) {

      // Get the cached network file

      CachedNetworkFile cacheFile = (CachedNetworkFile) netFile;
      cacheFile.closeFile();

      // Get the file segment details

      FileSegment fileSeg = cacheFile.getFileSegment();

      // Check if the file data has been updated, if so then queue a file save

      if (fileSeg.isUpdated() && netFile.hasDeleteOnClose() == false) {

        // Set the modified date/time and file size for the file

        File tempFile = new File(fileSeg.getTemporaryFile());

        netFile.setModifyDate(tempFile.lastModified());
        netFile.setFileSize(tempFile.length());

        // Queue a file save request to save the data back to the repository, if not already queued

        if (fileSeg.isSaveQueued() == false) {

          // Create a file save request for the updated file segment

          SingleFileRequest fileReq =
              new SingleFileRequest(
                  FileRequest.SAVE,
                  cacheFile.getFileId(),
                  cacheFile.getStreamId(),
                  fileSeg.getInfo(),
                  netFile.getFullName(),
                  cacheFile.getFileState());

          // Check if there are any attributes to be added to the file request

          if (hasRequiredAttributes() && sess != null) {

            // Check if the user name is required

            if (m_reqAttributes.containsString(FileRequest.AttrUserName)) {

              // Add the user name attribute

              ClientInfo cInfo = sess.getClientInformation();
              String userName = "";

              if (cInfo != null && cInfo.getUserName() != null) userName = cInfo.getUserName();

              fileReq.addAttribute(new NameValue(FileRequest.AttrUserName, userName));
            }

            // Check if the protocol type is required

            if (m_reqAttributes.containsString(FileRequest.AttrProtocol)) {

              // Add the protocol type attribute

              fileReq.addAttribute(new NameValue(FileRequest.AttrProtocol, sess.getProtocolName()));
            }
          }

          // Set the file segment status

          fileSeg.setStatus(FileSegmentInfo.SaveWait, true);

          // Queue the file save request

          queueFileRequest(fileReq);
        } else if (Debug.EnableInfo && hasDebug()) {

          // DEBUG

          Debug.println("## FileLoader Save already queued for " + fileSeg);
        }
      }

      // Update the cache timeout for the temporary file if there are no references to the file. If
      // the file was
      // opened for sequential access only it will be expired quicker.

      else if (cacheFile.getFileState().getOpenCount() == 0) {

        // If the file was opened for sequential access only then we can delete it from the
        // temporary area
        // sooner

        long tmo = System.currentTimeMillis();

        if (cacheFile.isSequentialOnly()) tmo += SequentialFileExpire;
        else tmo += m_stateCache.getFileStateExpireInterval();

        // Set the file state expiry, the local file data will be deleted when the file state
        // expires (if there
        // are still no references to the file).

        cacheFile.getFileState().setExpiryTime(tmo);
      }

      // If the database is not online and the file is marked for delete then queue a delete file
      // request to do
      // the
      // delete when the database is back online

      if (m_dbCtx.isAvailable() == false && netFile.hasDeleteOnClose()) {

        // Queue an offline delete request for the file

        DeleteFileRequest deleteReq =
            new DeleteFileRequest(
                cacheFile.getFileId(),
                cacheFile.getStreamId(),
                fileSeg.getTemporaryFile(),
                cacheFile.getFullNameStream(),
                cacheFile.getFileState());
        m_dbCtx.addOfflineFileDelete(deleteReq);

        // DEBUG

        if (Debug.EnableInfo && hasDebug())
          Debug.println("## FileLoader queued offline delete, " + deleteReq);
      }
    }
  }
  /** Inactivity checker, run in a seperate thread */
  public void run() {

    // DEBUG

    if (logger.isDebugEnabled()) logger.debug("Content quota manager checker thread starting");

    // Loop forever

    StringList removeNameList = new StringList();

    m_shutdown = false;

    while (m_shutdown == false) {

      // Sleep for the required interval

      try {
        Thread.sleep(UserQuotaCheckInterval);
      } catch (InterruptedException ex) {
      }

      //  Check for shutdown

      if (m_shutdown == true) {
        //  Debug

        if (logger.isDebugEnabled()) logger.debug("Content quota manager checker thread closing");

        return;
      }

      // Check if there are any user quota details to check
      synchronized (m_liveUsageLock) {
        if (m_liveUsage != null && m_liveUsage.size() > 0) {
          try {
            // Timestamp to check if the quota details is inactive

            long checkTime = System.currentTimeMillis() - UserQuotaExpireInterval;

            // Loop through the user quota details

            removeNameList.remoteAllStrings();
            Iterator<String> userNames = m_liveUsage.keySet().iterator();

            while (userNames.hasNext()) {

              // Get the user quota details and check if it has been inactive in the last check
              // interval

              String userName = userNames.next();
              UserQuotaDetails quotaDetails = m_liveUsage.get(userName);

              synchronized (quotaDetails) {
                if (quotaDetails.getLastUpdated() < checkTime) {

                  // Add the user name to the remove list, inactive

                  removeNameList.addString(userName);
                }
              }
            }

            // Remove inactive records from the live quota tracking

            while (removeNameList.numberOfStrings() > 0) {

              // Get the current user name and remove the record

              String userName = removeNameList.removeStringAt(0);
              UserQuotaDetails quotaDetails = m_liveUsage.remove(userName);

              // DEBUG

              if (logger.isDebugEnabled())
                logger.debug("Removed inactive usage tracking, " + quotaDetails);
            }
          } catch (Exception ex) {
            // Log errors if not shutting down

            if (m_shutdown == false) logger.debug(ex);
          }
        }
      }
    }
  }