View Javadoc

1   /***
2    * 
3    * Copyright RAJD Consultancy Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11   * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12   * specific language governing permissions and limitations under the License.
13   * 
14   */
15  package org.logicblaze.lingo.jmx.remote.jms;
16  
17  import java.util.Map;
18  import javax.jms.Connection;
19  import javax.jms.Destination;
20  import javax.jms.JMSException;
21  import javax.jms.Session;
22  import javax.management.MBeanServerConnection;
23  import javax.management.ObjectName;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
27  /***
28   * @version $Revision: 1.1 $
29   */
30  public class  MBeanJmsServerConnectionImpl extends  MBeanServerConnectionDelegate implements MBeanJmsServerConnection{
31      private static final Log log=LogFactory.getLog(MBeanJmsServerConnectionImpl.class);
32      private Session jmsSession;
33      private Map notificationListeners = new ConcurrentHashMap();
34      /***
35       * Construct this thing
36       * @param connection
37       * @param jmsConnection 
38       * @throws JMSException 
39       */
40      public MBeanJmsServerConnectionImpl(MBeanServerConnection connection, Connection jmsConnection) throws JMSException{
41          super(connection);
42          this.jmsSession =jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
43      }
44      /***
45       * Add a Notification listener
46       * @param listenerId
47       * @param name
48       * @param replyToDestination
49       */
50      public void addNotificationListener(String listenerId, ObjectName name, Destination replyToDestination){
51          try{
52              ServerListenerInfo info = new ServerListenerInfo(listenerId,notificationListeners,replyToDestination,jmsSession);
53              notificationListeners.put(listenerId,info);
54              connection.addNotificationListener(name, info,null,null);
55          }catch(Exception e){
56              log.error("Failed to addNotificationListener ",e);
57          }
58          
59      }
60      
61      /***
62       * Remove a Notification listener
63       * @param listenerId
64       */
65      public void removeNotificationListener(String listenerId){
66          ServerListenerInfo info = (ServerListenerInfo) notificationListeners.remove(listenerId);
67          if (info != null){
68              info.close();
69          }
70      }
71      
72  }