KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > wsn > jms > JmsNotificationBroker


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.wsn.jms;
18
19 import javax.jms.Connection JavaDoc;
20 import javax.jms.ConnectionFactory JavaDoc;
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 JavaDoc connectionFactory;
29     private Connection JavaDoc connection;
30     
31     public JmsNotificationBroker(String JavaDoc name) {
32         super(name);
33     }
34
35     public void init() throws Exception JavaDoc {
36         if (connection == null) {
37             connection = connectionFactory.createConnection();
38             connection.start();
39         }
40         super.init();
41     }
42     
43     @Override JavaDoc
44     protected AbstractPublisher createPublisher(String JavaDoc name) {
45         JmsPublisher publisher = createJmsPublisher(name);
46         publisher.setManager(getManager());
47         publisher.setConnection(connection);
48         return publisher;
49     }
50
51     @Override JavaDoc
52     protected AbstractSubscription createSubcription(String JavaDoc 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 JavaDoc name);
60
61     protected abstract JmsPublisher createJmsPublisher(String JavaDoc name);
62
63     public ConnectionFactory JavaDoc getConnectionFactory() {
64         return connectionFactory;
65     }
66
67     public void setConnectionFactory(ConnectionFactory JavaDoc connectionFactory) {
68         this.connectionFactory = connectionFactory;
69     }
70
71 }
72
Popular Tags