use of com.yahoo.documentapi.Result in project vespa by vespa-engine.
the class MessageBusAsyncSession method send.
/**
* A convenience method for assigning the internal trace level and route string to a message before sending it
* through the internal mbus session object.
*
* @param msg The message to send.
* @return The document api result object.
*/
public Result send(Message msg) {
try {
long reqId = requestId.incrementAndGet();
msg.setContext(reqId);
msg.getTrace().setLevel(traceLevel);
if (route != null) {
return toResult(reqId, session.send(msg, route, true));
} else {
return toResult(reqId, session.send(msg));
}
} catch (Exception e) {
return new Result(Result.ResultType.FATAL_ERROR, new Error(e.getMessage(), e));
}
}
use of com.yahoo.documentapi.Result in project vespa by vespa-engine.
the class MessageBusSyncSession method syncSend.
private Reply syncSend(Message msg, Duration timeout) {
if (timeout != null) {
msg.setTimeRemaining(timeout.toMillis());
}
try {
RequestMonitor monitor = new RequestMonitor();
msg.setContext(monitor);
// store monitor
msg.pushHandler(this);
Result result = null;
while (result == null || result.type() == Result.ResultType.TRANSIENT_ERROR) {
result = session.send(msg);
if (result != null && result.isSuccess()) {
break;
}
Thread.sleep(100);
}
if (!result.isSuccess()) {
throw new DocumentAccessException(result.getError().toString());
}
return monitor.waitForReply();
} catch (InterruptedException e) {
throw new DocumentAccessException(e);
}
}
use of com.yahoo.documentapi.Result in project vespa by vespa-engine.
the class LocalAsyncSession method put.
@Override
public Result put(Document document, DocumentProtocol.Priority pri) {
long req = getNextRequestId();
try {
syncSession.put(new DocumentPut(document), pri);
addResponse(new DocumentResponse(req));
} catch (Exception e) {
addResponse(new DocumentResponse(req, document, e.getMessage(), false));
}
return new Result(req);
}
Aggregations