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 java.util.Properties;
022
023import javax.jms.ExceptionListener;
024import javax.jms.JMSException;
025import javax.jms.MessageConsumer;
026import javax.jms.MessageProducer;
027import javax.jms.Session;
028import javax.naming.NamingException;
029
030/**
031 * Maintains a JMS connection for creating session, consumer and producer
032 */
033public interface ConnectionContext {
034
035    /**
036     * Create connection using properties
037     *
038     * @param props the properties used for creating jndi context
039     * @throws JMSException
040     */
041    void createConnection(Properties props) throws NamingException, JMSException;
042
043    /**
044     * Set the exception Listener
045     *
046     * @param exceptionListener
047     */
048    void setExceptionListener(ExceptionListener exceptionListener) throws JMSException;
049
050    /**
051     * Checks whether connection is initialized or not
052     *
053     * @return
054     */
055    boolean isConnectionInitialized();
056
057    /**
058     * Creates session using the specified session opts
059     *
060     * @param sessionOpts
061     * @return
062     * @throws JMSException
063     */
064    Session createSession(int sessionOpts) throws JMSException;
065
066    /**
067     * Creates consumer using session and topic name
068     *
069     * @param session
070     * @param topicName
071     * @return
072     * @throws JMSException
073     */
074    MessageConsumer createConsumer(Session session, String topicName) throws JMSException;
075
076    /**
077     * Creates consumer using session, topic name and selector
078     *
079     * @param session
080     * @param topicName
081     * @return
082     * @throws JMSException
083     */
084    MessageConsumer createConsumer(Session session, String topicName, String selector) throws JMSException;
085
086    /**
087     * Creates producer using session and topic
088     *
089     * @param session
090     * @param topicName
091     * @return
092     * @throws JMSException
093     */
094    MessageProducer createProducer(Session session, String topicName) throws JMSException;
095
096    /**
097     * Creates a threadlocal session using session opts
098     *
099     * @param sessionOpts
100     * @return
101     * @throws JMSException
102     */
103    Session createThreadLocalSession(final int sessionOpts) throws JMSException;
104
105    /**
106     * Closes the connection
107     */
108    void close();
109
110}