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