1 17 package org.apache.servicemix.wsn.jms; 18 19 import javax.jms.Connection ; 20 import javax.jms.ConnectionFactory ; 21 22 import org.apache.servicemix.wsn.AbstractNotificationBroker; 23 import org.apache.servicemix.wsn.AbstractPublisher; 24 import org.apache.servicemix.wsn.AbstractSubscription; 25 26 public abstract class JmsNotificationBroker extends AbstractNotificationBroker { 27 28 private ConnectionFactory connectionFactory; 29 private Connection connection; 30 31 public JmsNotificationBroker(String name) { 32 super(name); 33 } 34 35 public void init() throws Exception { 36 if (connection == null) { 37 connection = connectionFactory.createConnection(); 38 connection.start(); 39 } 40 super.init(); 41 } 42 43 @Override 44 protected AbstractPublisher createPublisher(String name) { 45 JmsPublisher publisher = createJmsPublisher(name); 46 publisher.setManager(getManager()); 47 publisher.setConnection(connection); 48 return publisher; 49 } 50 51 @Override 52 protected AbstractSubscription createSubcription(String name) { 53 JmsSubscription subscription = createJmsSubscription(name); 54 subscription.setManager(getManager()); 55 subscription.setConnection(connection); 56 return subscription; 57 } 58 59 protected abstract JmsSubscription createJmsSubscription(String name); 60 61 protected abstract JmsPublisher createJmsPublisher(String name); 62 63 public ConnectionFactory getConnectionFactory() { 64 return connectionFactory; 65 } 66 67 public void setConnectionFactory(ConnectionFactory connectionFactory) { 68 this.connectionFactory = connectionFactory; 69 } 70 71 } 72 | Popular Tags |