/** * Discard the supplied task message. * * @param tm the task message to be discarded * @param queueMessageId the reference to the message this task arrived on */ public void discardTask(final TaskMessage tm, final String queueMessageId) throws TaskRejectedException { LOG.warn("Discarding task {} (message id: {})", tm.getTaskId(), queueMessageId); callback.discard(queueMessageId); }
@Override public void sendMessage(final TaskMessage tm) { Objects.requireNonNull(tm); // Publish this message workerCallback.send("-1", tm); }
@Override public void setResponse(final TaskRejectedException taskRejectedException) { incrementResponseCount(true); LOG.info("Worker requested to abandon task {} (message id: {})", taskMessage.getTaskId(), taskMessage, taskRejectedException); workerCallback.abandon(messageId, taskRejectedException); }
/** * Decide whether the message is to be forwarded or discarded. * * @param tm the task message * @param queueMessageId the reference to the message this task arrived on * @param headers the map of key/value paired headers to be stamped on the message */ public void forwardTask(final TaskMessage tm, final String queueMessageId, Map<String, Object> headers) throws TaskRejectedException { //Check whether this worker application can evaluate messages for forwarding. if (factory instanceof TaskMessageForwardingEvaluator) { ((TaskMessageForwardingEvaluator) factory).determineForwardingAction(tm, queueMessageId, headers, callback); } else { //Messages are forwarded by default. callback.forward(queueMessageId, tm.getTo(), tm, headers); } }
workerCallback.reportUpdate(messageId, reportUpdateMessage);
/** * Finalises the final response message and publishes it (after any subtasks). */ private void completeResponse(final TaskMessage responseMessage) { // Get the final number of responses final int finalResponseCount = getFinalResponseCount(); // Check if there are multiple responses if (finalResponseCount > 1) { // Ensure the buffer is flushed singleMessageBuffer.flush(); // Add a suffix the task id updateTaskId(responseMessage, finalResponseCount, true); // Ensure that all the subtasks have been published before continuing subtasksPublishedSemaphore.acquireUninterruptibly(finalResponseCount - 1); } // Add task response message to progress report buffer. progressReportBuffer.add(responseMessage); // Ensure all report updates have been sent. progressReportBuffer.flush(); // Complete the task workerCallback.complete(messageId, responseMessage.getTo(), responseMessage); }
/** * Gets the next subtask identifier, appends it to the message and publishes it. */ private void publishSubtask(final TaskMessage responseMessage) { // Do not do anything if the message is null if (responseMessage == null) { return; } // Get the next subtask identifier final int subtaskId = currentSubtaskId.incrementAndGet(); // Append the subtask id to the task id updateTaskId(responseMessage, subtaskId, false); // Add task response message to progress report buffer. progressReportBuffer.add(responseMessage); // Publish this message workerCallback.send(messageId, responseMessage); // Allow the final task to complete (in case it was blocking waiting on the message to be published) subtasksPublishedSemaphore.release(); }