public Reply awaitSuccess() { Reply reply = awaitReply(); if (reply == null || reply.hasErrors()) { return null; } return reply; }
@Override public void processReply(Reply reply) { super.processReply(reply); if ( ! reply.hasErrors()) { ++numOk; } }
/** * Returns a concatenated error string from the errors contained in a reply. * * @param reply The reply whose errors to concatenate. * @return The error string. */ static String getErrorMessage(Reply reply) { if (!reply.hasErrors()) { return null; } StringBuilder errors = new StringBuilder(); for (int i = 0; i < reply.getNumErrors(); ++i) { errors.append(reply.getError(i)).append(" "); } return errors.toString(); }
public void merge(int i, Reply r) { if (r.hasErrors()) { mergeAllReplyErrors(r); } else { updateStateWithSuccessfulReply(i, r); } }
private static Response toResponse(Reply reply) { long reqId = (Long)reply.getContext(); return reply.hasErrors() ? toError(reply, reqId) : toSuccess(reply, reqId); }
/** * Returns true if the given reply has at least one error, and all errors are of the given type. * * @param reply The reply to check for error. * @param errCode The error code to check for. * @return Whether or not the reply has only the given error code. */ public static boolean hasOnlyErrorsOfType(Reply reply, int errCode) { if (!reply.hasErrors()) { return false; } for (int i = 0; i < reply.getNumErrors(); ++i) { if (reply.getError(i).getCode() != errCode) { return false; } } return true; }
private void syncSendPutDocumentMessage(PutDocumentMessage putDocumentMessage) { Reply reply = syncSend(putDocumentMessage); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply), reply.getErrorCodes()); } } }
assert(pendingMessageCount > 0); --pendingMessageCount; if (reply.hasErrors()) { handleErrorReply(reply); } else if (reply instanceof CreateVisitorReply) {
/** * If a reply has been set containing an error, and {@link #shouldIgnoreResult()} returns <code>true</code>, this method * replaces that reply with one that has no error. * * @return Whether or not the reply was replaced. */ private boolean tryIgnoreResult() { if (!shouldIgnoreResult()) { return false; } if (reply == null || !reply.hasErrors()) { return false; } setReply(new EmptyReply()); trace.trace(TraceLevel.SPLIT_MERGE, "Ignoring errors in reply."); return true; }
private boolean remove(RemoveDocumentMessage msg) { Reply reply = syncSend(msg); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply)); } if (reply.getType() != DocumentProtocol.REPLY_REMOVEDOCUMENT) { throw new DocumentAccessException("Received unknown response: " + reply); } return ((RemoveDocumentReply)reply).wasFound(); }
@Override public boolean update(DocumentUpdate update, DocumentProtocol.Priority pri) { UpdateDocumentMessage msg = new UpdateDocumentMessage(update); msg.setPriority(pri); Reply reply = syncSend(msg); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply), reply.getErrorCodes()); } if (reply.getType() != DocumentProtocol.REPLY_UPDATEDOCUMENT) { throw new DocumentAccessException("Received unknown response: " + reply); } return ((UpdateDocumentReply)reply).wasFound(); }
@Override public Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority pri, Duration timeout) { GetDocumentMessage msg = new GetDocumentMessage(id, fieldSet); msg.setPriority(pri); Reply reply = syncSend(msg, timeout != null ? timeout : defaultTimeout); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply)); } if (reply.getType() != DocumentProtocol.REPLY_GETDOCUMENT) { throw new DocumentAccessException("Received unknown response: " + reply); } GetDocumentReply docReply = ((GetDocumentReply)reply); Document doc = docReply.getDocument(); if (doc != null) { doc.setLastModified(docReply.getLastModified()); } return doc; }
@Override public void merge(RoutingContext context) { RoutingNodeIterator it = context.getChildIterator(); Reply reply = (it.hasReply()) ? it.removeReply() : context.getReply(); if (reply == null) { reply = new EmptyReply(); reply.addError(new Error(ErrorCode.NO_ADDRESS_FOR_SERVICE, "No reply in any children, nor in the routing context: " + context)); } if (reply instanceof WrongDistributionReply) { distributorSelectionLogic.handleWrongDistribution((WrongDistributionReply) reply, context); } else if (reply.hasErrors()) { distributorSelectionLogic.handleErrorReply(reply, context.getContext()); } else if (reply instanceof WriteDocumentReply) { if (context.shouldTrace(9)) { context.trace(9, "Modification timestamp: " + ((WriteDocumentReply)reply).getHighestModificationTimestamp()); } } context.setReply(reply); }
Trace trace = msg.getTrace(); if (logTrace) { if (reply.hasErrors()) { log.log(LogLevel.DEBUG, "Trace for reply with error(s):\n" + reply.getTrace()); } else if (log.isLoggable(LogLevel.SPAM)) {
@Override public void handleReply(Reply reply) { Object o = reply.getContext(); if (!(o instanceof ReplyContext)) { return; } ReplyContext context = (ReplyContext) o; final double latencyInSeconds = (System.currentTimeMillis() - context.creationTime) / 1000.0d; metric.set(MetricNames.LATENCY, latencyInSeconds, null); if (reply.hasErrors()) { Set<Integer> errorCodes = reply.getErrorCodes(); metricsHelper.reportFailure(DocumentOperationType.fromMessage(reply.getMessage()), DocumentOperationStatus.fromMessageBusErrorCodes(errorCodes)); metric.add(MetricNames.FAILED, 1, null); enqueue(context, reply.getError(0).getMessage(), ErrorCode.ERROR, reply.getError(0).getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED, reply.getTrace()); } else { metricsHelper.reportSuccessful(DocumentOperationType.fromMessage(reply.getMessage()), latencyInSeconds); metric.add(MetricNames.SUCCEEDED, 1, null); enqueue(context, "Document processed.", ErrorCode.OK, false, reply.getTrace()); } }
@Override public ContentChannel handleResponse(Response response) { Reply reply; if (response instanceof MbusResponse) { reply = ((MbusResponse)response).getReply(); } else { reply = new EmptyReply(); reply.swapState(msg); } Error err = StatusCodes.toMbusError(response.getStatus()); if (err != null) { if (err.isFatal()) { if (!reply.hasFatalErrors()) { reply.addError(err); } } else { if (!reply.hasErrors()) { reply.addError(err); } } } if (reply.getTrace().shouldTrace(6)) { reply.getTrace().trace(6, "Sending reply from MbusServer."); } session.sendReply(reply); return null; } }