@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 void run() { Reply reply = decode(envelope.reply.getProtocol(), payload, Reply.class); reply.setRetryDelay(envelope.reply.getRetryDelay()); reply.getTrace().getRoot().addChild(TraceNode.decode(envelope.reply.getTrace().getRoot().encode())); for (int i = 0, len = envelope.reply.getNumErrors(); i < len; ++i) { Error error = envelope.reply.getError(i); reply.addError(new Error(error.getCode(), error.getMessage(), error.getService() != null ? error.getService() : envelope.sender.hostId)); } owner.deliverReply(reply, envelope.parent.recipient); } });
@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; } }
private void mergeAllReplyErrors(Reply r) { if (handleReplyWithOnlyIgnoredErrors(r)) { return; } if (error == null) { error = new EmptyReply(); r.swapState(error); return; } for (int j = 0; j < r.getNumErrors(); ++j) { error.addError(r.getError(j)); } }
/** * 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 static int fromMbusReply(final Reply reply) { int statusCode = Response.Status.OK; for (int i = 0, len = reply.getNumErrors(); i < len; ++i) { statusCode = Math.max(statusCode, fromMbusError(reply.getError(i))); } return statusCode; }
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)) { log.log(LogLevel.SPAM, "Trace for reply:\n" + reply.getTrace()); trace.getRoot().addChild(reply.getTrace().getRoot()); trace.getRoot().normalize(); reply.swapState(msg); reply.setMessage(msg); for (int i = 0; i < reply.getNumErrors(); i++) { metrics.addFailure(reply.getError(i)); if (reply.getNumErrors() == 0) { metrics.latency.addValue(msg.getTimeReceived() - sendTime); ReplyHandler handler = reply.popHandler(); handler.handleReply(reply);
@Override protected void createResponse(Values ret, Reply reply, Version version, byte [] payload) { int[] eCodes = new int[reply.getNumErrors()]; String[] eMessages = new String[reply.getNumErrors()]; String[] eServices = new String[reply.getNumErrors()]; for (int i = 0; i < reply.getNumErrors(); ++i) { Error error = reply.getError(i); eCodes[i] = error.getCode(); eMessages[i] = error.getMessage(); eServices[i] = error.getService() != null ? error.getService() : ""; } ret.add(new StringValue(version.toString())); ret.add(new DoubleValue(reply.getRetryDelay())); ret.add(new Int32Array(eCodes)); ret.add(new StringArray(eMessages)); ret.add(new StringArray(eServices)); ret.add(new StringValue(reply.getProtocol())); ret.add(new DataValue(payload)); ret.add(new StringValue(reply.getTrace().getRoot() != null ? reply.getTrace().getRoot().encode() : "")); }
@Override public final void handleReply(Reply reply) { ReplyContext ctx = (ReplyContext)reply.getContext(); reply.setContext(null); // Add trace information. if (reply.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) { reply.getTrace().trace(TraceLevel.SEND_RECEIVE, "Sending reply (version " + ctx.version + ") from " + serverIdent + "."); } // Encode and return the reply through the RPC request. byte[] payload = new byte[0]; if (reply.getType() != 0) { Protocol protocol = net.getOwner().getProtocol(reply.getProtocol()); if (protocol != null) { payload = protocol.encode(ctx.version, reply); } if (payload == null || payload.length == 0) { reply.addError(new Error(ErrorCode.ENCODE_ERROR, "An error occured while encoding the reply.")); } } createResponse(ctx.request.returnValues(), reply, ctx.version, payload); ctx.request.returnRequest(); }
public Reply awaitReply() { Reply reply = null; try { reply = client.awaitReply(60, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (reply != null) { System.out.println(reply.getTrace()); } return reply; }
/** * This is a convenience method to add an error to this. If a reply has already been set, this method will add the * error to it. If no reply is set, this method calls {@link #setError(Error)}. This method also fiddles with the * trace object so that the error gets written to it. * * @param err The error to add. */ public void addError(Error err) { if (reply != null) { reply.getTrace().swap(trace); reply.addError(err); reply.getTrace().swap(trace); } else { setError(err); } }
/** * <p>Constructs and schedules a Reply containing an error to the handler of the given Message.</p> * * @param msg The message to reply to. * @param errCode The code of the error to set. * @param errMsg The message of the error to set. */ private void deliverError(Message msg, int errCode, String errMsg) { Reply reply = new EmptyReply(); reply.swapState(msg); reply.addError(new Error(errCode, errMsg)); deliverReply(reply, reply.popHandler()); }
public void handleReply(Reply reply) { if (destroyed.get()) { reply.discard(); return; long seqId = (Long)reply.getContext(); // non-sequenced messages do not enter here if (reply.getTrace().shouldTrace(TraceLevel.COMPONENT)) { reply.getTrace().trace(TraceLevel.COMPONENT, "Sequencer received reply with sequence id '" + seqId + "'."); sequencedSend(msg); ReplyHandler handler = reply.popHandler(); handler.handleReply(reply);
@Override public void handleReply(final Reply reply) { reply.getTrace().trace(6, "Reply received by MbusClient."); final ResponseHandler handler = (ResponseHandler)reply.getContext(); reply.popHandler(); // restore user context try { handler.handleResponse(new MbusResponse(StatusCodes.fromMbusReply(reply), reply)) .close(IgnoredCompletionHandler.INSTANCE); } catch (final Exception e) { log.log(LogLevel.WARNING, "Ignoring exception thrown by ResponseHandler.", e); } }
public void merge(RoutingContext context) { List<String> lst = new ArrayList<String>(); Reply ret = new EmptyReply(); for (RoutingNodeIterator it = context.getChildIterator(); it.isValid(); it.next()) { lst.add(it.getRoute().toString()); Reply reply = it.getReplyRef(); for (int i = 0; i < reply.getNumErrors(); ++i) { ret.addError(reply.getError(i)); } } context.setReply(ret); context.trace(1, "Merged " + lst + "."); }
@Override public void select(RoutingContext routingContext) { synchronized (this) { if (initException != null) { Reply reply = new EmptyReply(); reply.addError(new com.yahoo.messagebus.Error(ErrorCode.POLICY_ERROR, "Policy threw exception during init:" + exceptionMessageWithTrace(initException))); routingContext.setReply(reply); return; } checkStartInit(); if (initState == InitState.RUNNING) { Reply reply = new EmptyReply(); reply.addError(new com.yahoo.messagebus.Error(ErrorCode.SESSION_BUSY, "Policy is waiting to be initialized.")); routingContext.setReply(reply); return; } } doSelect(routingContext); }
/** * Send an error reply for a given request. * * @param request The JRT request to reply to. * @param version The version to serialize for. * @param traceLevel The trace level to set in the reply. * @param err The error to reply with. */ private void replyError(Request request, Version version, int traceLevel, Error err) { Reply reply = new EmptyReply(); reply.setContext(new ReplyContext(request, version)); reply.getTrace().setLevel(traceLevel); reply.addError(err); handleReply(reply); }