public DocumentMessage fromDocumentOperation(Processing processing, DocumentOperation documentOperation) { DocumentMessage msg = newMessage(documentOperation); msg.setLoadType(loadType); msg.setPriority(priority); msg.setRoute(requestMsg.getRoute()); msg.setTimeReceivedNow(); msg.setTimeRemaining(requestMsg.getTimeRemainingNow()); msg.getTrace().setLevel(requestMsg.getTrace().getLevel()); if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, "Created '" + msg.getClass().getName() + "', route = '" + msg.getRoute() + "', priority = '" + msg.getPriority().name() + "', load type = '" + msg.getLoadType() + "', trace level = '" + msg.getTrace().getLevel() + "', time remaining = '" + msg.getTimeRemaining() + "'."); } return msg; }
@Override public int getApproxSize() { return super.getApproxSize() + 8; }
public MessageFactory(DocumentMessage requestMsg) { this.requestMsg = requestMsg; loadType = requestMsg.getLoadType(); priority = requestMsg.getPriority(); }
public Routable decode(DocumentDeserializer in, LoadTypeSet loadTypes) { byte pri = in.getByte(null); int loadType = in.getInt(null); DocumentMessage msg = doDecode(in); if (msg != null) { msg.setPriority(DocumentProtocol.getPriority(pri)); msg.setLoadType(loadTypes.getIdMap().get(loadType)); } return msg; } }
private void dispatchResponse(int status) { ResponseDispatch.newInstance(new MbusResponse(status, requestMsg.createReply())).dispatch(this); }
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); } }
private void setMessageParameters(DocumentOperationMessageV3 msg, FeederSettings settings) { msg.getMessage().setContext(new ReplyContext(msg.getOperationId(), feedReplies, DocumentOperationType.fromMessage(msg.getMessage()))); if (settings.traceLevel != null) { msg.getMessage().getTrace().setLevel(settings.traceLevel); } if (settings.priority != null) { try { DocumentProtocol.Priority priority = DocumentProtocol.Priority.valueOf(settings.priority); if (msg.getMessage() instanceof DocumentMessage) { ((DocumentMessage) msg.getMessage()).setPriority(priority); } } catch (IllegalArgumentException i) { log.severe(i.getMessage()); } } }
@Override public int getPriority() { return requestMsg.getPriority().getValue(); }
private static MessageFactory newMessageFactory(final DocumentMessage msg) { if (msg == null) { return null; } final Route route = msg.getRoute(); if (route == null || !route.hasHops()) { return null; } return new MessageFactory(msg); }
@Override public void processingDone(List<Processing> processings) { List<DocumentMessage> messages = new ArrayList<>(); if (messageFactory != null) { for (Processing processing : processings) { for (DocumentOperation documentOperation : processing.getDocumentOperations()) { messages.add(messageFactory.fromDocumentOperation(processing, documentOperation)); } } } if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, "Forwarding " + messages.size() + " messages from " + processings.size() + " processings."); } if (messages.isEmpty()) { dispatchResponse(Response.Status.OK); return; } long inputSequenceId = requestMsg.getSequenceId(); ResponseMerger responseHandler = new ResponseMerger(requestMsg, messages.size(), this); for (Message message : messages) { // See comment for internalNoThrottledSource. dispatchRequest(message, (inputSequenceId == message.getSequenceId()) ? getUri().getPath() : "/" + internalNoThrottledSource, responseHandler); } }
public boolean encode(Routable obj, DocumentSerializer out) { if (!(obj instanceof DocumentMessage)) { throw new AssertionError( "Document message factory (" + getClass().getName() + ") registered for incompatible " + "routable type " + obj.getType() + "(" + obj.getClass().getName() + ")."); } DocumentMessage msg = (DocumentMessage)obj; out.putByte(null, (byte)(msg.getPriority().getValue())); out.putInt(null, msg.getLoadType().getId()); return doEncode(msg, out); }
public void handleMessage(Message message) { Reply reply = ((DocumentMessage)message).createReply(); message.swapState(reply); params.getDataHandler().onMessage(message, new AckToken(reply)); }
@Override public int getApproxSize() { if (cachedApproxSize > 0) { return cachedApproxSize; } cachedApproxSize = requestMsg.getApproxSize(); return cachedApproxSize; }
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 int getApproxSize() { return super.getApproxSize() + 8 + bucketSpace.length(); }
@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); }
@Override public int getApproxSize() { return super.getApproxSize() + 8 + bucketSpace.length() + documentSelection.length(); }
@Override public int getApproxSize() { return super.getApproxSize() + 4 + documentId.toString().length(); }