コード例 #1
0
  /**
   * @param request The archive request to handle.
   * @param results The previous identification results for the archive format.
   * @return
   */
  private boolean handleArchive(
      IdentificationRequest request, IdentificationResultCollection results) {

    boolean jobCountDecremented = false;

    String archiveFormat = getArchiveFormat(results);
    if (archiveFormat != null) {
      results.setArchive(true);
      ResourceId id = resultHandler.handle(results);
      jobCounter.incrementPostProcess();
      RequestIdentifier identifier = request.getIdentifier();
      identifier.setResourceId(id);
      if (identifier.getAncestorId() == null) {
        identifier.setAncestorId(id.getId());
      }
      submissionQueue.add(request.getIdentifier());
      jobCounter.decrement();
      jobCountDecremented = true;
      try {
        // BNO: Does this always return the same archive handler for any given container format?
        // And will it end up using the same submission gateway, or a new one with a different
        // thread pool?
        ArchiveHandler handler = archiveHandlerFactory.getHandler(archiveFormat);
        handler.handle(request);
        // CHECKSTYLE:OFF
      } catch (Exception e) {
        // CHECKSTYLE:ON
        String causeMessage = "";
        if (e.getCause() != null) {
          causeMessage = e.getCause().getMessage();
        }
        final String message =
            String.format(
                ARCHIVE_ERROR,
                archiveFormat,
                request.getIdentifier().getUri().toString(),
                e.getMessage(),
                causeMessage);
        log.warn(message);
        resultHandler.handleError(
            new IdentificationException(request, IdentificationErrorType.OTHER, e));
      } finally {
        submissionQueue.remove(request.getIdentifier());
        jobCounter.decrementPostProcess();
      }
    } else {
      ResourceId id = resultHandler.handle(results);
      request.getIdentifier().setNodeId(id.getId());
    }
    return jobCountDecremented;
  }
コード例 #2
0
  /** {@inheritDoc} */
  @Override
  @PauseBefore
  public Future<IdentificationResultCollection> submit(final IdentificationRequest request) {
    jobCounter.increment();
    requests.add(request);

    // old code blocking identification:
    Callable<IdentificationResultCollection> callable =
        new Callable<IdentificationResultCollection>() {
          @Override
          public IdentificationResultCollection call() throws IOException {
            droidCore.setMaxBytesToScan(maxBytesToScan);
            IdentificationResultCollection results = droidCore.matchBinarySignatures(request);
            return results;
          }
        };

    FutureTask<IdentificationResultCollection> task = new SubmissionFutureTask(callable, request);
    executorService.submit(task);
    return task;
  }
コード例 #3
0
 /**
  * Waits until the job queue is empty AND all sub-tasks (archives etc.) have finished.
  *
  * @throws InterruptedException if the calling thread was interrupted.
  */
 @Override
 public void awaitFinished() throws InterruptedException {
   jobCounter.awaitFinished();
 }
コード例 #4
0
 /**
  * Waits until all in-process jobs have completed.
  *
  * @throws InterruptedException if the calling thread was interrupted.
  */
 @Override
 public void awaitIdle() throws InterruptedException {
   jobCounter.awaitIdle();
 }