/** * This constructor is a convencience function to allow simpler instantiation of a result that contains an error. * It does nothing but proxy the {@link #Result(Error)} function with a new instance of {@link Error}. * * @param code The numerical code of the error. * @param message The description of the error. */ public Result(int code, String message) { this(new Error(code, message)); }
public static Error toMbusError(final int statusCode) { if (statusCode < 300) { return null; } else if (statusCode < 400) { return new Error(ErrorCode.APP_TRANSIENT_ERROR, statusCode + " Redirection"); } else if (statusCode < 500) { return new Error(ErrorCode.APP_FATAL_ERROR, statusCode + " Client Error"); } else if (statusCode < 600) { return new Error(ErrorCode.APP_FATAL_ERROR, statusCode + " Server Error"); } else { return new Error(ErrorCode.APP_FATAL_ERROR, statusCode + " Unknown Error"); } } }
/** * This is a convenience method to call {@link #addError(Error)}. * * @param code The code of the error to add. * @param msg The message of the error to add. */ public void addError(int code, String msg) { addError(new Error(code, msg)); }
/** * This is a convenience method to call {@link #setError(Error)}. * * @param code The code of the error to set. * @param msg The message of the error to set. */ public void setError(int code, String msg) { setError(new Error(code, msg)); }
private void receiveLater(ReplyEnvelope envelope) { byte[] payload = envelope.sender.encode(envelope.reply.getProtocol(), envelope.reply); executor.execute(new Runnable() { @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 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); }
boolean notifyIfExpired() { if (msg.isExpired()) { Error error = new Error(ErrorCode.TIMEOUT, "Timed out in sendQ"); notifyComplete(new Result(error)); replyHandler.handleReply(createSendTimedoutReply(msg, error)); return true; } return false; }
/** * <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 handleMessageProcessingException(Reply reply, Exception e, String what) { final String errorDesc = formatProcessingException(e, what); final String fullMsg = formatIdentifyingVisitorErrorString(errorDesc); log.log(LogLevel.ERROR, fullMsg, e); int errorCode; synchronized (progress.getToken()) { if (!params.skipBucketsOnFatalErrors()) { errorCode = ErrorCode.APP_FATAL_ERROR; transitionTo(new StateDescription(State.FAILED, errorDesc)); } else { errorCode = DocumentProtocol.ERROR_UNPARSEABLE; } } reply.addError(new Error(errorCode, errorDesc)); }
/** * 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; } }
@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); }
@Override public boolean allocServiceAddress(RoutingNode recipient) { String service = recipient.getRoute().getHop(0).getServiceName(); ServiceAddress address = wire.resolveServiceAddress(service); if (address == null) { recipient.setError(new Error(NO_ADDRESS_FOR_SERVICE, "No address for service '" + service + "'.")); return false; } recipient.setServiceAddress(address); return true; }
private MessageHandler createMessageHandler() { return (message) -> { try { taskExecutor.submitTask(new HandleMessageTask(message)); } catch (RejectedExecutionException e) { Reply reply = ((DocumentMessage)message).createReply(); message.swapState(reply); reply.addError(new Error( DocumentProtocol.ERROR_ABORTED, "Visitor session has been aborted")); receiver.reply(reply); } }; }
@Override public void processingFailed(ErrorCode errorCode, String errorMsg) { MbusResponse response = new MbusResponse(errorCode.getDiscStatus(), requestMsg.createReply()); response.getReply().addError(new com.yahoo.messagebus.Error(errorCode.getDocumentProtocolStatus(), errorMsg)); ResponseDispatch.newInstance(response).dispatch(this); }
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 void handleDocumentMessage(DocumentMessage msg) { Reply reply = msg.createReply(); msg.swapState(reply); if (params.getLocalDataHandler() == null) { log.log(LogLevel.ERROR, sessionName + ": Got visitor data back to client with no local data destination."); reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, "Visitor data with no local data destination")); receiver.reply(reply); return; } try { params.getLocalDataHandler().onMessage(msg, new AckToken(reply)); } catch (Exception e) { handleMessageProcessingException(reply, e, "DocumentMessage"); // Immediately reply since we cannot count on AckToken being registered receiver.reply(reply); } }
@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); } });