use of org.apache.airavata.messaging.core.MessageHandler in project airavata by apache.
the class RabbitMQListener method getMessageHandler.
private static MessageHandler getMessageHandler(final BufferedWriter bw) {
return message -> {
try {
long latency = System.currentTimeMillis() - message.getUpdatedTime().getTime();
bw.write(message.getMessageId() + " :" + latency);
bw.newLine();
bw.flush();
} catch (IOException e) {
e.printStackTrace();
}
if (message.getType().equals(MessageType.EXPERIMENT)) {
try {
ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
System.out.println(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getType() + "' and with state : '" + event.getState().toString() + " for Gateway " + event.getGatewayId());
} catch (TException e) {
logger.error(e.getMessage(), e);
}
} else if (message.getType().equals(MessageType.PROCESS)) {
/*try {
WorkflowNodeStatusChangeEvent event = new WorkflowNodeStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
System.out.println(" Message Received with message id '" + message.getMessageId()
+ "' and with message type '" + message.getType() + "' and with state : '" + event.getState().toString() +
" for Gateway " + event.getWorkflowNodeIdentity().getGatewayId());
} catch (TException e) {
logger.error(e.getMessage(), e);
}*/
} else if (message.getType().equals(MessageType.TASK)) {
try {
TaskStatusChangeEvent event = new TaskStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
System.out.println(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getType() + "' and with state : '" + event.getState().toString() + " for Gateway " + event.getTaskIdentity().getGatewayId());
} catch (TException e) {
logger.error(e.getMessage(), e);
}
} else if (message.getType().equals(MessageType.JOB)) {
try {
JobStatusChangeEvent event = new JobStatusChangeEvent();
TBase messageEvent = message.getEvent();
byte[] bytes = ThriftUtils.serializeThriftObject(messageEvent);
ThriftUtils.createThriftFromBytes(bytes, event);
System.out.println(" Message Received with message id '" + message.getMessageId() + "' and with message type '" + message.getType() + "' and with state : '" + event.getState().toString() + " for Gateway " + event.getJobIdentity().getGatewayId());
} catch (TException e) {
logger.error(e.getMessage(), e);
}
}
};
}
Aggregations