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    package org.apache.oozie.jms;
019    
020    import javax.jms.Message;
021    import javax.jms.MessageConsumer;
022    import javax.jms.MessageListener;
023    import javax.jms.Session;
024    
025    import org.apache.oozie.util.XLog;
026    
027    public class MessageReceiver implements MessageListener {
028    
029        private static XLog LOG = XLog.getLog(MessageReceiver.class);
030    
031        private MessageHandler msgHandler;
032        private Session session;
033        private MessageConsumer consumer;
034    
035        public MessageReceiver(MessageHandler handler, Session session, MessageConsumer consumer) {
036            this.msgHandler = handler;
037            this.session = session;
038            this.consumer = consumer;
039        }
040    
041        /**
042         * Get the JMS message consumer object for this message receiver
043         *
044         * @return MessageConsumer
045         */
046        public MessageConsumer getConsumer() {
047            return this.consumer;
048        }
049    
050        /**
051         * Get the MessageHandler that will process the message
052         *
053         * @return message handler
054         */
055        public MessageHandler getMessageHandler() {
056            return msgHandler;
057        }
058    
059        /**
060         * Get the JMS session for this message receiver
061         *
062         * @return JMS session
063         */
064        public Session getSession() {
065            return session;
066        }
067    
068        /*
069         * (non-Javadoc)
070         *
071         * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
072         */
073        @Override
074        public void onMessage(Message msg) {
075            LOG.trace("Received a JMS message ");
076            msgHandler.process(msg);
077        }
078    
079    }