use of edu.iu.dsc.tws.task.api.Message in project twister2 by DSC-SPIDAL.
the class RunnableFixedTask method run.
@Override
public void run() {
if (executableTask == null) {
throw new RuntimeException("Task needs to be set to execute");
}
LOG.info(String.format("Runnable task %d limit %d", executableTask.getTaskId(), messageProcessLimit));
Message result;
if (isMessageBased) {
// TODO: check if this part needs to be synced
while (!queueRef.isEmpty()) {
if (messageProcessCount < messageProcessLimit) {
result = executableTask.execute(queueRef.poll());
if (result != null && outQueues != null && !outQueues.isEmpty()) {
submitToOutputQueue(result);
}
messageProcessCount++;
} else {
// Need to make sure the remaining tasks are processed
LOG.info("Need to run more so resubmitting the task");
TaskExecutorFixedThread.executorPool.submit(new RunnableFixedTask(executableTask, queueRef, messageProcessLimit, taskExecutor, outQueues));
return;
}
}
synchronized (ExecutorContext.FIXED_EXECUTOR_LOCK) {
if (!queueRef.isEmpty()) {
LOG.info("Need to run more so resubmitting the task");
TaskExecutorFixedThread.executorPool.submit(new RunnableFixedTask(executableTask, queueRef, messageProcessLimit, taskExecutor, outQueues));
} else {
TaskExecutorFixedThread.removeSubmittedTask(executableTask.getTaskId());
}
}
} else {
result = executableTask.execute();
if (result != null && outQueues != null && !outQueues.isEmpty()) {
submitToOutputQueue(result);
}
TaskExecutorFixedThread.removeSubmittedTask(executableTask.getTaskId());
}
}
Aggregations