final Message responseMessage = createResponseMessage(message, Type.OK);
if (sign) {
responseMessage.setPublicKeyAndSign(getPeerBean().getKeyPair());
}
if (message.getType() == Type.REQUEST_1) {
Number160 taskId = message.getKey();
// request 1 is task creation
Map<Number160, Data> dataMap = message.getDataMap();
ChannelBuffer channelBuffer = message.getPayload1();
Object obj = Utils.decodeJavaObject(channelBuffer);
Worker mapper = (Worker) obj;
int queuePosition = taskManager.submitTask(getPeerBean().getPeer(), taskId, mapper, dataMap,
message.getSender(), sign);
responseMessage.setInteger(queuePosition);
} else if (message.getType() == Type.REQUEST_2) {
Collection<Number160> taskIDs = message.getKeys();
Map<Number160, Data> dataMap = new HashMap<Number160, Data>();
for (Number160 taskId : taskIDs) {
Number320 taskKey = new Number320(taskId, message.getSender().getPeerId());
TaskStatus taskStatus = taskManager.taskStatus(taskKey);
Data data = new Data(taskStatus);
dataMap.put(taskId, data);
}
responseMessage.setDataMap(dataMap);
if (logger.isDebugEnabled()) {
logger.debug("finished task status for tasks " + taskIDs);
}
} else if (message.getType() == Type.REQUEST_3) {
Number160 taskId = message.getKey();
Map<Number160, Data> dataMap = message.getDataMap();
Number320 taskKey = new Number320(taskId, message.getSender().getPeerId());
taskManager.notifyListeners(taskKey, dataMap);
} else {
responseMessage.setType(Type.NOT_FOUND);