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));
}
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);
}
Aggregations