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