001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.oozie.jms;
020
021import javax.jms.Message;
022import javax.jms.MessageConsumer;
023import javax.jms.MessageListener;
024import javax.jms.Session;
025
026import org.apache.oozie.util.XLog;
027
028public class MessageReceiver implements MessageListener {
029
030    private static XLog LOG = XLog.getLog(MessageReceiver.class);
031
032    private MessageHandler msgHandler;
033    private Session session;
034    private MessageConsumer consumer;
035
036    public MessageReceiver(MessageHandler handler, Session session, MessageConsumer consumer) {
037        this.msgHandler = handler;
038        this.session = session;
039        this.consumer = consumer;
040    }
041
042    /**
043     * Get the JMS message consumer object for this message receiver
044     *
045     * @return MessageConsumer
046     */
047    public MessageConsumer getConsumer() {
048        return this.consumer;
049    }
050
051    /**
052     * Get the MessageHandler that will process the message
053     *
054     * @return message handler
055     */
056    public MessageHandler getMessageHandler() {
057        return msgHandler;
058    }
059
060    /**
061     * Get the JMS session for this message receiver
062     *
063     * @return JMS session
064     */
065    public Session getSession() {
066        return session;
067    }
068
069    /*
070     * (non-Javadoc)
071     *
072     * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
073     */
074    @Override
075    public void onMessage(Message msg) {
076        LOG.trace("Received a JMS message ");
077        msgHandler.process(msg);
078    }
079
080}