Search in sources :

Example 1 with MessageFuture

use of org.apache.asterix.common.messaging.api.MessageFuture in project asterixdb by apache.

the class NCQueryServiceServlet method executeStatement.

@Override
protected void executeStatement(String statementsText, SessionOutput sessionOutput, IStatementExecutor.ResultDelivery delivery, IStatementExecutor.Stats stats, RequestParameters param, String handleUrl, long[] outExecStartEnd) throws Exception {
    // Running on NC -> send 'execute' message to CC
    INCServiceContext ncCtx = (INCServiceContext) serviceCtx;
    INCMessageBroker ncMb = (INCMessageBroker) ncCtx.getMessageBroker();
    IStatementExecutor.ResultDelivery ccDelivery = delivery == IStatementExecutor.ResultDelivery.IMMEDIATE ? IStatementExecutor.ResultDelivery.DEFERRED : delivery;
    ExecuteStatementResponseMessage responseMsg;
    MessageFuture responseFuture = ncMb.registerMessageFuture();
    try {
        ExecuteStatementRequestMessage requestMsg = new ExecuteStatementRequestMessage(ncCtx.getNodeId(), responseFuture.getFutureId(), queryLanguage, statementsText, sessionOutput.config(), ccDelivery, param.clientContextID, handleUrl);
        outExecStartEnd[0] = System.nanoTime();
        ncMb.sendMessageToCC(requestMsg);
        responseMsg = (ExecuteStatementResponseMessage) responseFuture.get(ExecuteStatementResponseMessage.DEFAULT_TIMEOUT_MILLIS, java.util.concurrent.TimeUnit.MILLISECONDS);
        outExecStartEnd[1] = System.nanoTime();
    } finally {
        ncMb.deregisterMessageFuture(responseFuture.getFutureId());
    }
    Throwable err = responseMsg.getError();
    if (err != null) {
        if (err instanceof Error) {
            throw (Error) err;
        } else if (err instanceof Exception) {
            throw (Exception) err;
        } else {
            throw new Exception(err.toString(), err);
        }
    }
    IStatementExecutor.ResultMetadata resultMetadata = responseMsg.getMetadata();
    if (delivery == IStatementExecutor.ResultDelivery.IMMEDIATE && !resultMetadata.getResultSets().isEmpty()) {
        for (Triple<JobId, ResultSetId, ARecordType> rsmd : resultMetadata.getResultSets()) {
            ResultReader resultReader = new ResultReader(getHyracksDataset(), rsmd.getLeft(), rsmd.getMiddle());
            ResultUtil.printResults(appCtx, resultReader, sessionOutput, stats, rsmd.getRight());
        }
    } else {
        sessionOutput.out().append(responseMsg.getResult());
    }
}
Also used : ResultReader(org.apache.asterix.app.result.ResultReader) ExecuteStatementResponseMessage(org.apache.asterix.app.message.ExecuteStatementResponseMessage) INCMessageBroker(org.apache.asterix.common.messaging.api.INCMessageBroker) ExecuteStatementRequestMessage(org.apache.asterix.app.message.ExecuteStatementRequestMessage) IStatementExecutor(org.apache.asterix.translator.IStatementExecutor) INCServiceContext(org.apache.hyracks.api.application.INCServiceContext) ResultSetId(org.apache.hyracks.api.dataset.ResultSetId) MessageFuture(org.apache.asterix.common.messaging.api.MessageFuture) ARecordType(org.apache.asterix.om.types.ARecordType) JobId(org.apache.hyracks.api.job.JobId)

Example 2 with MessageFuture

use of org.apache.asterix.common.messaging.api.MessageFuture in project asterixdb by apache.

the class ExecuteStatementResponseMessage method handle.

@Override
public void handle(INcApplicationContext appCtx) throws HyracksDataException, InterruptedException {
    NCMessageBroker mb = (NCMessageBroker) appCtx.getServiceContext().getMessageBroker();
    MessageFuture future = mb.deregisterMessageFuture(requestMessageId);
    if (future != null) {
        future.complete(this);
    }
}
Also used : MessageFuture(org.apache.asterix.common.messaging.api.MessageFuture) NCMessageBroker(org.apache.asterix.messaging.NCMessageBroker)

Example 3 with MessageFuture

use of org.apache.asterix.common.messaging.api.MessageFuture in project asterixdb by apache.

the class NCMessageBroker method registerMessageFuture.

@Override
public MessageFuture registerMessageFuture() {
    long futureId = futureIdGenerator.incrementAndGet();
    MessageFuture future = new MessageFuture(futureId);
    synchronized (futureMap) {
        if (futureMap.containsKey(futureId)) {
            throw new IllegalStateException();
        }
        futureMap.put(futureId, future);
    }
    return future;
}
Also used : MessageFuture(org.apache.asterix.common.messaging.api.MessageFuture)

Aggregations

MessageFuture (org.apache.asterix.common.messaging.api.MessageFuture)3 ExecuteStatementRequestMessage (org.apache.asterix.app.message.ExecuteStatementRequestMessage)1 ExecuteStatementResponseMessage (org.apache.asterix.app.message.ExecuteStatementResponseMessage)1 ResultReader (org.apache.asterix.app.result.ResultReader)1 INCMessageBroker (org.apache.asterix.common.messaging.api.INCMessageBroker)1 NCMessageBroker (org.apache.asterix.messaging.NCMessageBroker)1 ARecordType (org.apache.asterix.om.types.ARecordType)1 IStatementExecutor (org.apache.asterix.translator.IStatementExecutor)1 INCServiceContext (org.apache.hyracks.api.application.INCServiceContext)1 ResultSetId (org.apache.hyracks.api.dataset.ResultSetId)1 JobId (org.apache.hyracks.api.job.JobId)1