private Tuple2<Integer, Reply> createEmptyReplyResult() { return new Tuple2<>(null, (Reply)new EmptyReply()); }
@SuppressWarnings("unchecked") private <T extends Routable> T decode(Utf8String protocolName, byte[] toDecode, Class<T> clazz) { if (toDecode.length == 0) { return clazz.cast(new EmptyReply()); } return clazz.cast(owner.getProtocol(protocolName).decode(Vtag.currentVersion, toDecode)); }
Reply createSendTimedoutReply(Message msg, Error error) { Reply reply = new EmptyReply(); reply.setMessage(msg); reply.addError(error); msg.swapState(reply); return reply; }
private boolean handleReplyWithOnlyIgnoredErrors(Reply r) { if (DocumentProtocol.hasOnlyErrorsOfType(r, DocumentProtocol.ERROR_MESSAGE_IGNORED)) { if (ignore == null) { ignore = new EmptyReply(); } ignore.addError(r.getError(0)); return true; } return false; }
/** * Conveniece method for acknowledging a message back to the sender. * * This is equivalent to: * <pre> * Reply ack = new EmptyReply(); * ack.swapState(msg); * reply(ack); * </pre> * * Messages should be acknowledged when * <ul> * <li>this destination has safely and permanently applied the message, or * <li>an intermediate determines that the purpose of the message is fullfilled without forwarding the message * </ul> * * @param msg The message to acknowledge back to the sender. * @see #reply */ public void acknowledge(Message msg) { Reply ack = new EmptyReply(); msg.swapState(ack); reply(ack); }
@Override public void handleMessage(Message msg) { MessageHandler msgHandler = this.msgHandler.get(); if (msgHandler == null) { Reply reply = new EmptyReply(); reply.swapState(msg); reply.addError(new Error(ErrorCode.SESSION_BUSY, "Session not fully configured yet.")); sendReply(reply); return; } msgHandler.handleMessage(msg); }
@Override public void handleMessage(Message msg) { MessageHandler msgHandler = this.msgHandler.get(); if (msgHandler == null) { Reply reply = new EmptyReply(); reply.swapState(msg); reply.addError(new Error(ErrorCode.SESSION_BUSY, "Session not fully configured yet.")); sendReply(reply); return; } msgHandler.handleMessage(msg); }
private void dispatchErrorReply(Message msg, int errCode, String errMsg) { Reply reply = new EmptyReply(); reply.swapState(msg); reply.addError(new Error(errCode, errMsg)); session.sendReply(reply); }
/** * 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; }
/** * 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); }
/** * <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()); }
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)); } }
@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); }
/** * 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); } }
public BucketId handleBucketIdCalculation(RoutingContext context) { BucketId id = getBucketId(context.getMessage()); if (id == null || id.getRawId() == 0) { Reply reply = new EmptyReply(); reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, "No bucket id available in message.")); context.setReply(reply); } return id; } }
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 + "."); }
/** * 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); }
public void select(RoutingContext ctx) { Hop hop = getRecipient(ctx); if (hop != null) { Route route = new Route(ctx.getRoute()); route.setHop(0, hop); ctx.addChild(route); } else { Reply reply = new EmptyReply(); reply.addError(new Error(ErrorCode.NO_ADDRESS_FOR_SERVICE, "None of the configured recipients are currently available.")); ctx.setReply(reply); } }
private boolean sendMessage(final MbusRequest request) { Error error; final Long millis = request.timeRemaining(TimeUnit.MILLISECONDS); if (millis != null && millis <= 0) { error = new Error(ErrorCode.TIMEOUT, request.getTimeout(TimeUnit.MILLISECONDS) + " millis"); } else if (request.isCancelled()) { error = new Error(ErrorCode.APP_FATAL_ERROR, "request cancelled"); } else { try { error = session.sendMessage(request.getMessage()).getError(); } catch (final Exception e) { error = new Error(ErrorCode.FATAL_ERROR, e.toString()); } } if (error == null) { return true; } if (error.isFatal()) { final Reply reply = new EmptyReply(); reply.swapState(request.getMessage()); reply.addError(error); reply.popHandler().handleReply(reply); return true; } return false; }
@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); }