Search in sources :

Example 1 with MediaSegmentMetadataQueryResult

use of org.vitrivr.cineast.api.messages.result.MediaSegmentMetadataQueryResult in project cineast by vitrivr.

the class FindSegmentMetadataGetHandler method doGet.

@Override
public MediaSegmentMetadataQueryResult doGet(Context ctx) {
    final Map<String, String> parameters = ctx.pathParamMap();
    final String segmentId = parameters.get(ID_QUALIFIER);
    final MetadataRetrievalService service = new MetadataRetrievalService();
    return new MediaSegmentMetadataQueryResult("", service.lookupSegmentMetadata(segmentId));
}
Also used : MetadataRetrievalService(org.vitrivr.cineast.api.rest.services.MetadataRetrievalService) MediaSegmentMetadataQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentMetadataQueryResult)

Example 2 with MediaSegmentMetadataQueryResult

use of org.vitrivr.cineast.api.messages.result.MediaSegmentMetadataQueryResult in project cineast by vitrivr.

the class AbstractQueryMessageHandler method loadAndWriteSegmentMetadata.

/**
 * Performs a lookup for {@link MediaSegmentMetadataDescriptor} identified by the provided segment IDs and writes them to the WebSocket stream.
 *
 * @param session                             The WebSocket session to write the data to.
 * @param queryId                             The current query id used for transmitting data back.
 * @param segmentIds                          List of segment IDs for which to lookup metadata.
 * @param segmentIdsForWhichMetadataIsFetched segmentids for which metadata is already fetched
 * @param metadataAccessSpec                  if this parameter is null, no metadata is fetched.
 */
synchronized List<Thread> loadAndWriteSegmentMetadata(Session session, String queryId, List<String> segmentIds, Collection<String> segmentIdsForWhichMetadataIsFetched, List<MetadataAccessSpecification> metadataAccessSpec) {
    if (segmentIds.isEmpty()) {
        return new ArrayList<>();
    }
    segmentIds.removeAll(segmentIdsForWhichMetadataIsFetched);
    segmentIdsForWhichMetadataIsFetched.addAll(segmentIds);
    // chunk for memory safety-purposes
    if (segmentIds.size() > 100_000) {
        return Lists.partition(segmentIds, 100_000).stream().map(list -> loadAndWriteSegmentMetadata(session, queryId, list, segmentIdsForWhichMetadataIsFetched, metadataAccessSpec)).flatMap(Collection::stream).collect(Collectors.toList());
    }
    Thread fetching = new Thread(() -> {
        final List<MediaSegmentMetadataDescriptor> segmentMetadata = this.segmentMetadataReader.findBySpec(segmentIds, metadataAccessSpec);
        if (segmentMetadata.isEmpty()) {
            return;
        }
        List<Thread> threads = new ArrayList<>();
        AtomicInteger i = new AtomicInteger(0);
        Lists.partition(segmentMetadata, 100_000).forEach(list -> {
            Thread writing = new Thread(() -> {
                this.write(session, new MediaSegmentMetadataQueryResult(queryId, list)).join();
            });
            writing.setName("metadata-ws-write-queryId" + i.getAndIncrement());
            writing.start();
            threads.add(writing);
        });
        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                LOGGER.error(e);
            }
        }
    });
    fetching.setName("metadata-load-write-" + queryId);
    fetching.start();
    return Lists.newArrayList(fetching);
}
Also used : MediaSegmentMetadataDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentMetadataDescriptor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MediaSegmentMetadataQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentMetadataQueryResult) ArrayList(java.util.ArrayList)

Aggregations

MediaSegmentMetadataQueryResult (org.vitrivr.cineast.api.messages.result.MediaSegmentMetadataQueryResult)2 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MetadataRetrievalService (org.vitrivr.cineast.api.rest.services.MetadataRetrievalService)1 MediaSegmentMetadataDescriptor (org.vitrivr.cineast.core.data.entities.MediaSegmentMetadataDescriptor)1