@Override public String getTo() { return taskMessage.getTo(); }
@Override public void reportUpdate(final String queueMsgId, final TaskMessage reportUpdateMessage) { Objects.requireNonNull(queueMsgId); Objects.requireNonNull(reportUpdateMessage); LOG.debug("Sending report updates to queue {})", reportUpdateMessage.getTo()); final byte[] output; try { output = codec.serialise(reportUpdateMessage); } catch (final CodecException ex) { throw new RuntimeException(ex); } final int priority = reportUpdateMessage.getPriority() == null ? 0 : reportUpdateMessage.getPriority(); try { workerQueue.publish("-1", output, reportUpdateMessage.getTo(), Collections.emptyMap(), priority); } catch (final QueueException ex) { throw new RuntimeException(ex); } }
/** * 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); } }
@Override public void send(final String queueMsgId, final TaskMessage responseMessage) { Objects.requireNonNull(queueMsgId); Objects.requireNonNull(responseMessage); LOG.debug("Sending task {} complete (message id: {})", responseMessage.getTaskId(), queueMsgId); final String queue = responseMessage.getTo(); checkForTrackingTermination(queueMsgId, queue, responseMessage); final byte[] output; try { output = codec.serialise(responseMessage); } catch (final CodecException ex) { throw new RuntimeException(ex); } final int priority = responseMessage.getPriority() == null ? 0 : responseMessage.getPriority(); try { workerQueue.publish("-1", output, queue, Collections.emptyMap(), priority); } catch (final QueueException ex) { throw new RuntimeException(ex); } }
private void registerNewTaskImpl(final String queueMsgId, final byte[] taskMessage, Map<String, Object> headers) throws InvalidTaskException, TaskRejectedException { try { TaskMessage tm = codec.deserialise(taskMessage, TaskMessage.class, DecodeMethod.LENIENT); LOG.debug("Received task {} (message id: {})", tm.getTaskId(), queueMsgId); boolean poison = isTaskPoisoned(headers); validateTaskMessage(tm); boolean taskIsActive = checkStatus(tm); if (taskIsActive) { if (tm.getTo() != null && tm.getTo().equalsIgnoreCase(workerQueue.getInputQueue())) { LOG.debug("Task {} (message id: {}) on input queue {} {}", tm.getTaskId(), queueMsgId, workerQueue.getInputQueue(), (tm.getTo() != null) ? "is intended for this worker" : "has no explicit destination, therefore assuming it is intended for this worker"); executor.executeTask(tm, queueMsgId, poison, headers, codec); } else { LOG.debug("Task {} (message id: {}) is not intended for this worker: input queue {} does not match message destination queue {}", tm.getTaskId(), queueMsgId, workerQueue.getInputQueue(), tm.getTo()); executor.forwardTask(tm, queueMsgId, headers); } } else { LOG.debug("Task {} is no longer active. The task message (message id: {}) will not be executed", tm.getTaskId(), queueMsgId); executor.discardTask(tm, queueMsgId); } } catch (CodecException e) { throw new InvalidTaskException("Queue data did not deserialise to a TaskMessage", e); } catch (InvalidJobTaskIdException ijte) { throw new InvalidTaskException("TaskMessage contains an invalid job task identifier", ijte); } }
taskStatus == TaskStatus.RESULT_FAILURE) { final String trackToPipe = tm.getTracking().getTrackTo(); final String toPipe = tm.getTo();
/** * 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); }