Search in sources :

Example 1 with Result

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));
    }
}
Also used : Error(java.lang.Error) Result(com.yahoo.documentapi.Result)

Example 2 with Result

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);
    }
}
Also used : Result(com.yahoo.documentapi.Result) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 3 with Result

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);
}
Also used : DocumentResponse(com.yahoo.documentapi.DocumentResponse) DocumentPut(com.yahoo.document.DocumentPut) Result(com.yahoo.documentapi.Result)

Aggregations

Result (com.yahoo.documentapi.Result)3 DocumentPut (com.yahoo.document.DocumentPut)1 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)1 DocumentResponse (com.yahoo.documentapi.DocumentResponse)1 Error (java.lang.Error)1