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; }
/** * <p>Add an error to this reply. This method will also trace the error as long as there is any tracing * enabled.</p> * * @param error The error object to add. */ public void addError(Error error) { errors.add(error); getTrace().trace(TraceLevel.ERROR, error.toString()); }
public void handleErrorReply(Reply reply, Object untypedContext) { MessageContext messageContext = (MessageContext) untypedContext; if (messageContext.calculatedDistributor != null) { persistentFailureChecker.addFailure(messageContext.calculatedDistributor); if (reply.getTrace().shouldTrace(1)) { reply.getTrace().trace(1, "Failed with " + messageContext.toString()); } } } }
/** * This method may only be invoked on a root node, as it passes the current reply to the member {@link * ReplyHandler}. */ private void notifySender() { reply.getTrace().swap(trace); handler.handleReply(reply); reply = null; }
public void sendReply(Reply reply) { reply.getTrace().trace(0, "Sending reply from RemoteServer."); server.sendReply(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); } }
/** * Sets the reply of this routing node. This method also updates the internal state of this node; it is tagged for * resending if the reply has only transient errors, and the reply's {@link Trace} is copied. This method <u>does * not</u> call the parent node's {@link #notifyMerge()}. * * @param reply The reply to set. */ public void setReply(Reply reply) { if (reply != null) { shouldRetry = resender != null && resender.shouldRetry(reply); trace.getRoot().addChild(reply.getTrace().getRoot()); reply.getTrace().clear(); } this.reply = reply; }
/** * Removes and returns the reply of the current child. This is the correct way of reusing a reply of a child node, * the {@link #getReplyRef()} should be used when just inspecting a child reply. * * @return The reply. */ public Reply removeReply() { Reply ret = entry.getReply(); ret.getTrace().setLevel(entry.getTrace().getLevel()); ret.getTrace().swap(entry.getTrace()); entry.setReply(null); return ret; }
@Override public void handleReply(Reply reply) { if (destroyed.get()) { reply.discard(); return; } boolean done; synchronized (lock) { --pendingCount; if (throttlePolicy != null) { throttlePolicy.processReply(reply); } done = (closed && pendingCount == 0); sendBlockedMessages(); } if (reply.getTrace().shouldTrace(TraceLevel.COMPONENT)) { reply.getTrace().trace(TraceLevel.COMPONENT, "Source session received reply. " + pendingCount + " message(s) now pending."); } ReplyHandler handler = reply.popHandler(); handler.handleReply(reply); if (done) { this.done.countDown(); } }
@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); } }
/** * This is a convenience method to assign an {@link EmptyReply} containing a single error to this. This also fiddles * with the trace object so that the error gets written to it. * * @param err The error to set. * @see #setReply(Reply) */ public void setError(Error err) { Reply reply = new EmptyReply(); reply.getTrace().setLevel(trace.getLevel()); reply.addError(err); setReply(reply); }
/** * Deliver an error reply to the recipients of a {@link SendContext} in a way that avoids entanglement. * * @param ctx The send context that contains the recipient data. * @param errCode The error code to return. * @param errMsg The error string to return. */ private void replyError(SendContext ctx, int errCode, String errMsg) { for (RoutingNode recipient : ctx.recipients) { Reply reply = new EmptyReply(); reply.getTrace().setLevel(ctx.traceLevel); reply.addError(new Error(errCode, errMsg)); owner.deliverReply(reply, recipient); } }
/** * 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); }
@Override public ContentChannel handleResponse(Response response) { synchronized (this) { if (response instanceof MbusResponse) { Reply reply = ((MbusResponse)response).getReply(); requestTrace.addChild(reply.getTrace().getRoot()); replies.add(reply); } if (--numPending != 0) { return null; } } requestMsg.getTrace().getRoot().addChild(requestTrace); Reply reply = DocumentProtocol.merge(replies); Response mbusResponse = new MbusResponse(StatusCodes.fromMbusReply(reply), reply); ResponseDispatch.newInstance(mbusResponse).dispatch(responseHandler); return null; }
@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(); }
@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 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 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 send(RoutingNode recipient, Version version, byte[] payload, long timeRemaining) { SendContext ctx = new SendContext(recipient, timeRemaining); RPCServiceAddress address = (RPCServiceAddress)recipient.getServiceAddress(); Message msg = recipient.getMessage(); Route route = new Route(recipient.getRoute()); Hop hop = route.removeHop(0); Request req = encodeRequest(version, route, address,msg, timeRemaining, payload, ctx.trace.getLevel()); if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) { ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Sending message (version " + version + ") from " + clientIdent + " to '" + address.getServiceName() + "' with " + ctx.timeout + " seconds timeout."); } if (hop.getIgnoreResult()) { address.getTarget().getJRTTarget().invokeVoid(req); if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) { ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Not waiting for a reply from '" + address.getServiceName() + "'."); } Reply reply = new EmptyReply(); reply.getTrace().swap(ctx.trace); net.getOwner().deliverReply(reply, recipient); } else { req.setContext(ctx); address.getTarget().getJRTTarget().invokeAsync(req, ctx.timeout, this); } req.discardParameters(); // allow garbage collection of request parameters }