KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > system > MQJMXConnectorInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.connectors.system;
25
26 import java.io.IOException JavaDoc;
27 import java.net.MalformedURLException JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import java.util.logging.Logger JavaDoc;
31
32 import javax.management.MBeanServerConnection JavaDoc;
33 import javax.management.remote.JMXConnector JavaDoc;
34 import javax.management.remote.JMXConnectorFactory JavaDoc;
35 import javax.management.remote.JMXServiceURL JavaDoc;
36
37 import com.sun.enterprise.connectors.ConnectorRuntimeException;
38 import com.sun.logging.LogDomains;
39
40 /**
41  * The <code>MQJMXConnectorInfo</code> holds MBean Server connection information
42  * to a SJSMQ broker instance. This API is used by the admin infrastructure for
43  * performing MQ administration/configuration operations on a broker instance.
44  *
45  * @author Sivakumar Thyagarajan
46  * @since SJSAS 9.0
47  */

48 public class MQJMXConnectorInfo {
49     private String JavaDoc jmxServiceURL = null;
50     private Map JavaDoc<String JavaDoc,?> jmxConnectorEnv = null;
51     private String JavaDoc asInstanceName = null;
52     private String JavaDoc brokerInstanceName = null;
53     private String JavaDoc brokerType = null;
54     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
55     private JMXConnector JavaDoc connector = null;
56
57     public MQJMXConnectorInfo(String JavaDoc asInstanceName, String JavaDoc brokerInstanceName,
58                               String JavaDoc brokerType, String JavaDoc jmxServiceURL,
59                                        Map JavaDoc<String JavaDoc, ?> jmxConnectorEnv) {
60         this.brokerInstanceName = brokerInstanceName;
61         this.asInstanceName = asInstanceName;
62         this.jmxServiceURL = jmxServiceURL;
63         this.brokerType = brokerType;
64         this.jmxConnectorEnv = jmxConnectorEnv;
65         if (_logger.isLoggable(Level.FINE)) {
66             _logger.log(Level.FINE, "MQJMXConnectorInfo : brokerInstanceName " +
67                             brokerInstanceName + " ASInstanceName " + asInstanceName +
68                             " jmxServiceURL " + jmxServiceURL + " BrokerType " + brokerType
69                             + " jmxConnectorEnv " + jmxConnectorEnv);
70         }
71     }
72
73     public String JavaDoc getBrokerInstanceName(){
74         return this.brokerInstanceName;
75     }
76
77     public String JavaDoc getBrokerType(){
78         return this.brokerType;
79     }
80
81     public String JavaDoc getASInstanceName(){
82         return this.asInstanceName;
83     }
84
85     public String JavaDoc getJMXServiceURL(){
86         _logger.log(Level.FINE,"MQJMXConnectorInfo :: JMXServiceURL is " + this.jmxServiceURL);
87         return this.jmxServiceURL;
88     }
89
90     public Map JavaDoc<String JavaDoc, ?> getJMXConnectorEnv(){
91         return this.jmxConnectorEnv;
92     }
93     
94     /**
95      * Returns an <code>MBeanServerConnection</code> representing the MQ broker instance's MBean
96      * server.
97      * @return
98      * @throws ConnectorRuntimeException
99      */

100     //XXX:Enhance to support SSL (once MQ team delivers support in the next drop)
101
//XXX: Discuss how <code>ConnectionNotificationListeners</code> could
102
//be shared with the consumer of this API
103
public MBeanServerConnection JavaDoc getMQMBeanServerConnection() throws ConnectorRuntimeException {
104         try {
105             if (_logger.isLoggable(Level.FINE)) {
106                 _logger.log(Level.FINE,
107                 "creating MBeanServerConnection to MQ JMXServer with "+getJMXServiceURL());
108             }
109             JMXServiceURL JavaDoc jmxServiceURL = new JMXServiceURL JavaDoc(getJMXServiceURL());
110             connector = JMXConnectorFactory.connect(jmxServiceURL, this.jmxConnectorEnv);
111             //XXX: Do we need to pass in a Subject?
112
MBeanServerConnection JavaDoc mbsc = connector.getMBeanServerConnection();
113             return mbsc;
114         } catch (Exception JavaDoc e) {
115             e.printStackTrace();
116             ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
117             cre.initCause(e);
118             throw cre;
119         }
120     }
121
122     public void closeMQMBeanServerConnection() throws ConnectorRuntimeException {
123         try {
124            if (connector != null) {
125                  connector.close();
126            }
127         } catch (IOException JavaDoc e) {
128             ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
129             cre.initCause(e);
130             throw cre;
131         }
132     }
133  }
134
Popular Tags