use of org.vitrivr.cineast.api.messages.result.QueryError in project cineast by vitrivr.
the class AbstractQueryMessageHandler method handle.
/**
* Handles a {@link Query} message
*
* @param session WebSocketSession for which the message arrived.
* @param message Message of type a that needs to be handled.
*/
public final void handle(Session session, T message) {
if (message == null) {
LOGGER.warn("Received null message. Ignoring.");
return;
}
try {
final QueryConfig qconf = new ConstrainedQueryConfig(message.getQueryConfig());
final String uuid = qconf.getQueryId().toString();
final int max = Math.min(qconf.getMaxResults().orElse(Config.sharedConfig().getRetriever().getMaxResults()), Config.sharedConfig().getRetriever().getMaxResults());
qconf.setMaxResults(max);
final int resultsPerModule = Math.min(qconf.getRawResultsPerModule() == -1 ? Config.sharedConfig().getRetriever().getMaxResultsPerModule() : qconf.getResultsPerModule(), Config.sharedConfig().getRetriever().getMaxResultsPerModule());
qconf.setResultsPerModule(resultsPerModule);
String qid = uuid.substring(0, 3);
Thread.currentThread().setName("query-msg-handler-" + uuid.substring(0, 3));
try {
/* Begin of Query: Send QueryStart Message to Client.
* We could wait for future-completion here, but there will likely never be a case where a simple write would fall behind the first message we send to the client.
* Additionally, QR_START is informational - the client already knows that they sent a request.
*/
this.write(session, new QueryStart(uuid));
/* Execute actual query. */
LOGGER.trace("Executing query with id {} from message {}", qid, message);
final Set<String> segmentIdsForWhichMetadataIsFetched = new HashSet<>();
final Set<String> objectIdsForWhichMetadataIsFetched = new HashSet<>();
this.execute(session, qconf, message, segmentIdsForWhichMetadataIsFetched, objectIdsForWhichMetadataIsFetched);
} catch (Exception e) {
/* Error: Send QueryError Message to Client. */
LOGGER.error("An exception occurred during execution of similarity query message {}.", LogHelper.getStackTrace(e));
this.write(session, new QueryError(uuid, e.getMessage()));
return;
}
/* End of Query: Send QueryEnd Message to Client. */
this.write(session, new QueryEnd(uuid));
} catch (Throwable t) {
t.printStackTrace();
}
}
Aggregations