/** * Checks whether tracking of this task message should end when publishing to the specified queue. If tracking is to end then this * method removes and returns the tracking info from the task message. * * @param queueMsgId the reference to the message this task arrived on * @param queueToSend the queue to which the message is to be published * @param tm task message whose tracking info is to be checked * @return if tracking of the message terminates on publishing to the specified queue then the removed tracking info is returned; * otherwise null is returned and the tracking info is not removed from the message */ private TrackingInfo checkForTrackingTermination(final String queueMsgId, final String queueToSend, TaskMessage tm) { Objects.requireNonNull(queueMsgId); Objects.requireNonNull(tm); // queueToSend can be null for a dead end worker final TrackingInfo tracking = tm.getTracking(); if (tracking != null) { final String trackTo = tracking.getTrackTo(); if ((trackTo == null && queueToSend == null) || (trackTo != null && trackTo.equalsIgnoreCase(queueToSend))) { LOG.debug("Task {} (message id: {}): removing tracking info from this message as tracking ends on publishing to the queue {}.", tm.getTaskId(), queueMsgId, queueToSend); tm.setTracking(null); } } return tracking; } }
/** * Updates the specified {@link TaskMessage} with the specified subtask identifier. */ private static void updateTaskId(final TaskMessage responseMessage, final int subtaskId, final boolean isFinalResponse) { // Put together the suffix to be added final String subtaskSuffix; { final StringBuilder builder = new StringBuilder(); builder.append('.'); builder.append(subtaskId); if (isFinalResponse) { builder.append('*'); } subtaskSuffix = builder.toString(); } // Update the task id responseMessage.setTaskId(responseMessage.getTaskId() + subtaskSuffix); // Update the tracking info final TrackingInfo taskMessageTracking = responseMessage.getTracking(); if (taskMessageTracking != null) { final String trackingTaskId = taskMessageTracking.getJobTaskId(); if (trackingTaskId != null) { final TrackingInfo trackingInfo = new TrackingInfo(taskMessageTracking); trackingInfo.setJobTaskId(trackingTaskId + subtaskSuffix); responseMessage.setTracking(trackingInfo); } } }