001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.wsn.jms;
018
019 import javax.jms.Connection;
020 import javax.jms.ConnectionFactory;
021
022 import org.apache.servicemix.wsn.AbstractNotificationBroker;
023 import org.apache.servicemix.wsn.AbstractPublisher;
024 import org.apache.servicemix.wsn.AbstractSubscription;
025
026 public abstract class JmsNotificationBroker extends AbstractNotificationBroker {
027
028 private ConnectionFactory connectionFactory;
029
030 private Connection connection;
031
032 public JmsNotificationBroker(String name) {
033 super(name);
034 }
035
036 public void init() throws Exception {
037 if (connection == null) {
038 connection = connectionFactory.createConnection();
039 connection.start();
040 }
041 super.init();
042 }
043
044 public void destroy() throws Exception {
045 if (connection != null) {
046 connection.close();
047 }
048 super.destroy();
049 }
050
051 @Override
052 protected AbstractPublisher createPublisher(String name) {
053 JmsPublisher publisher = createJmsPublisher(name);
054 publisher.setManager(getManager());
055 publisher.setConnection(connection);
056 return publisher;
057 }
058
059 @Override
060 protected AbstractSubscription createSubcription(String name) {
061 JmsSubscription subscription = createJmsSubscription(name);
062 subscription.setManager(getManager());
063 subscription.setConnection(connection);
064 return subscription;
065 }
066
067 protected abstract JmsSubscription createJmsSubscription(String name);
068
069 protected abstract JmsPublisher createJmsPublisher(String name);
070
071 public ConnectionFactory getConnectionFactory() {
072 return connectionFactory;
073 }
074
075 public void setConnectionFactory(ConnectionFactory connectionFactory) {
076 this.connectionFactory = connectionFactory;
077 }
078
079 }