airport.services.dispatcher.ConsumerFlightJMS.java Source code

Java tutorial

Introduction

Here is the source code for airport.services.dispatcher.ConsumerFlightJMS.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package airport.services.dispatcher;

import airport.database.dispatcher.airplane.Flight;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author mcdoker
 */
public class ConsumerFlightJMS implements MessageListener {

    private final static Logger LOG = Logger.getLogger(ConsumerFlightJMS.class);

    @Autowired
    private ServiceDispatcher serviceDispatcher;

    @Override
    public void onMessage(Message message) {
        if (message instanceof ObjectMessage) {
            try {
                Flight flight = (Flight) ((ObjectMessage) message).getObject();

                serviceDispatcher.addFlight(flight);

                if (LOG.isInfoEnabled()) {
                    LOG.info("recieve message. Flight : " + flight);
                }
            } catch (JMSException ex) {
                throw new RuntimeException(ex);
            }
        } else {
            throw new IllegalArgumentException("Message must be of type ObjectMessage");
        }
    }

}