Search in sources :

Example 1 with Extractor

use of org.vitrivr.cineast.core.features.extractor.Extractor in project cineast by vitrivr.

the class ExtractionPipeline method shutdown.

/**
 * Shuts the ExtractionPipeline down. Stops the ExecutorService and finishes the extractors.
 */
private void shutdown() {
    try {
        LOGGER.debug("Shutting down executor service");
        this.executorService.shutdown();
        LOGGER.debug("Waiting for termination of executor");
        this.executorService.awaitTermination(15, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        LOGGER.warn("Interrupted while waiting for Executor to shut down!");
    } finally {
        for (Extractor extractor : this.extractors) {
            try {
                extractor.finish();
            } catch (Exception e) {
                LOGGER.error("Error while shutting down extractor {} : {}", extractor.getClass().getSimpleName(), LogHelper.getStackTrace(e));
            }
        }
        LOGGER.debug("All extractors termination, executor service terminated. Exiting shutdown.");
    }
}
Also used : Extractor(org.vitrivr.cineast.core.features.extractor.Extractor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with Extractor

use of org.vitrivr.cineast.core.features.extractor.Extractor in project cineast by vitrivr.

the class ExtractionPipeline method run.

/**
 * When an object implementing interface <code>Runnable</code> is used to create a thread, starting the thread causes the object's
 * <code>run</code> method to be called in that separately executing
 * thread.
 * <p>
 * The general contract of the method <code>run</code> is that it may take any action whatsoever.
 *
 * @see Thread#run()
 */
@Override
public void run() {
    /* Set running flag to true. */
    synchronized (this) {
        this.running = true;
    }
    /* Process SegmentContainers in Queue: For each Extractor in list dispatch an extraction task. */
    while (this.isRunning() || !this.segmentQueue.isEmpty()) {
        if (!this.isRunning()) {
            LOGGER.debug("Received stop signal, still {} elements left", this.segmentQueue.size());
        }
        try {
            SegmentContainer s = this.segmentQueue.poll(500, TimeUnit.MILLISECONDS);
            if (s != null) {
                LOGGER.debug("Segment {} is being handed to the extraction pipeline.", s.getId());
                for (Extractor f : extractors) {
                    try {
                        this.executorService.execute(new ExtractionTask(f, s, this));
                        LOGGER.debug("Submitted segment {} for feature {}", s.getId(), f.getClass().getSimpleName());
                    } catch (RejectedExecutionException e) {
                        this.segmentQueue.clear();
                        LOGGER.fatal("Failed to submit segment {} for feature {}. Aborting...\n{}", s.getId(), f.getClass().getSimpleName(), LogHelper.getStackTrace(e));
                        break;
                    }
                }
                /* Sort list of extractors by execution time. */
                (this.extractors).sort((o1, o2) -> Long.compare(getAverageExecutionTime(o2.getClass().getSimpleName()), getAverageExecutionTime(o1.getClass().getSimpleName())));
            }
        } catch (InterruptedException e) {
            LOGGER.warn("ShotDispatcher was interrupted: {}", LogHelper.getStackTrace(e));
        }
    }
    this.shutdown();
    synchronized (this) {
        this.running = false;
    }
}
Also used : SegmentContainer(org.vitrivr.cineast.core.data.segments.SegmentContainer) Extractor(org.vitrivr.cineast.core.features.extractor.Extractor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 3 with Extractor

use of org.vitrivr.cineast.core.features.extractor.Extractor in project cineast by vitrivr.

the class ExtractionPipeline method startup.

/**
 * Starts the ExtractionPipeline by initializing the Extractors.
 */
private void startup() {
    LOGGER.info("Warming up extraction pipeline....");
    for (Extractor extractor : this.context.extractors()) {
        try {
            extractor.init(this.context.persistencyWriter());
            this.extractors.add(extractor);
        } catch (Throwable t) {
            LOGGER.warn("Failed to initialize extractor {} due to an exception: {}", extractor.getClass().getSimpleName(), t.getMessage());
        }
    }
    for (Extractor exporter : this.context.exporters()) {
        try {
            exporter.init(this.context.persistencyWriter());
            this.extractors.add(exporter);
        } catch (Throwable t) {
            LOGGER.warn("Failed to exporter extractor {} due to an exception: {}", exporter.getClass().getSimpleName(), t.getMessage());
        }
    }
    LOGGER.info("Extraction pipeline is ready with {} extractors.", this.extractors.size());
}
Also used : Extractor(org.vitrivr.cineast.core.features.extractor.Extractor)

Aggregations

Extractor (org.vitrivr.cineast.core.features.extractor.Extractor)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 SegmentContainer (org.vitrivr.cineast.core.data.segments.SegmentContainer)1