Search in sources :

Example 1 with MessageHandler

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);
            }
        }
    };
}
Also used : MessageType(org.apache.airavata.model.messaging.event.MessageType) Type(org.apache.airavata.messaging.core.Type) Options(org.apache.commons.cli.Options) LoggerFactory(org.slf4j.LoggerFactory) TaskStatusChangeEvent(org.apache.airavata.model.messaging.event.TaskStatusChangeEvent) ArrayList(java.util.ArrayList) ServerSettings(org.apache.airavata.common.utils.ServerSettings) CommandLine(org.apache.commons.cli.CommandLine) OutputStreamWriter(java.io.OutputStreamWriter) PosixParser(org.apache.commons.cli.PosixParser) TBase(org.apache.thrift.TBase) MessagingFactory(org.apache.airavata.messaging.core.MessagingFactory) ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) Logger(org.slf4j.Logger) CommandLineParser(org.apache.commons.cli.CommandLineParser) BufferedWriter(java.io.BufferedWriter) TException(org.apache.thrift.TException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ThriftUtils(org.apache.airavata.common.utils.ThriftUtils) File(java.io.File) MessageHandler(org.apache.airavata.messaging.core.MessageHandler) List(java.util.List) JobStatusChangeEvent(org.apache.airavata.model.messaging.event.JobStatusChangeEvent) ParseException(org.apache.commons.cli.ParseException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Subscriber(org.apache.airavata.messaging.core.Subscriber) TException(org.apache.thrift.TException) TaskStatusChangeEvent(org.apache.airavata.model.messaging.event.TaskStatusChangeEvent) ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) JobStatusChangeEvent(org.apache.airavata.model.messaging.event.JobStatusChangeEvent) TBase(org.apache.thrift.TBase) IOException(java.io.IOException)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 ServerSettings (org.apache.airavata.common.utils.ServerSettings)1 ThriftUtils (org.apache.airavata.common.utils.ThriftUtils)1 MessageHandler (org.apache.airavata.messaging.core.MessageHandler)1 MessagingFactory (org.apache.airavata.messaging.core.MessagingFactory)1 Subscriber (org.apache.airavata.messaging.core.Subscriber)1 Type (org.apache.airavata.messaging.core.Type)1 ExperimentStatusChangeEvent (org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent)1 JobStatusChangeEvent (org.apache.airavata.model.messaging.event.JobStatusChangeEvent)1 MessageType (org.apache.airavata.model.messaging.event.MessageType)1 TaskStatusChangeEvent (org.apache.airavata.model.messaging.event.TaskStatusChangeEvent)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1