Search in sources :

Example 1 with QueryError

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();
    }
}
Also used : ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) QueryEnd(org.vitrivr.cineast.api.messages.result.QueryEnd) QueryStart(org.vitrivr.cineast.api.messages.result.QueryStart) QueryError(org.vitrivr.cineast.api.messages.result.QueryError) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 QueryEnd (org.vitrivr.cineast.api.messages.result.QueryEnd)1 QueryError (org.vitrivr.cineast.api.messages.result.QueryError)1 QueryStart (org.vitrivr.cineast.api.messages.result.QueryStart)1 QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)1 ConstrainedQueryConfig (org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig)1