001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.monitoring.client;
006:
007: import com.ibm.websphere.management.AdminClient;
008: import com.ibm.websphere.management.exception.ConnectorException;
009: import com.sun.portal.log.common.PortalLogger;
010:
011: import javax.management.*;
012: import java.io.IOException;
013: import java.util.List;
014: import java.util.Set;
015: import java.util.ArrayList;
016: import java.util.logging.Logger;
017: import java.util.logging.Level;
018: import java.util.logging.LogRecord;
019: import java.lang.reflect.Method;
020:
021: public class IbmClientImpl extends ClientImpl {
022: private static final Logger logger = PortalLogger
023: .getLogger(IbmClientImpl.class);
024:
025: private static LogRecord getLogRecord(Level level, String message,
026: Object[] parameters, Throwable t) {
027: LogRecord result = new LogRecord(level, message);
028: result.setLoggerName(logger.getName());
029: result.setParameters(parameters);
030: result.setThrown(t);
031: return result;
032: }
033:
034: public IbmClientImpl(String defaultDomain,
035: List immortalMBeanObjectNames, AdminClient adminClient) {
036: setDefaultDomain(defaultDomain);
037: setImmortalMBeanObjectNames(immortalMBeanObjectNames);
038: this .adminClient = adminClient;
039: }
040:
041: public void addNotificationListener(ObjectName on,
042: NotificationListener listener, NotificationFilter filter,
043: Object handback) throws InstanceNotFoundException,
044: IOException {
045: if (adminClient != null) {
046: try {
047: adminClient.addNotificationListener(on, listener,
048: filter, handback);
049: } catch (ConnectorException e) {
050: if (logger.isLoggable(Level.SEVERE)) {
051: logger.log(getLogRecord(Level.SEVERE,
052: "PSMN_CSPM0001", new Object[] { e
053: .getLocalizedMessage() }, null));
054: }
055: throw new IOException(e.getLocalizedMessage());
056: }
057: }
058: }
059:
060: public Object getAttribute(ObjectName on, String attrName)
061: throws ReflectionException, InstanceNotFoundException,
062: MBeanException, AttributeNotFoundException, IOException {
063: if (adminClient != null) {
064: try {
065: return adminClient.getAttribute(on, attrName);
066: } catch (ConnectorException e) {
067: if (logger.isLoggable(Level.SEVERE)) {
068: logger.log(getLogRecord(Level.SEVERE,
069: "PSMN_CSPM0001", new Object[] { e
070: .getLocalizedMessage() }, null));
071: }
072: throw new IOException(e.getLocalizedMessage());
073: }
074: }
075:
076: return null;
077: }
078:
079: public AttributeList getAttributes(ObjectName on, String[] attrNames)
080: throws ReflectionException, InstanceNotFoundException,
081: IOException {
082: if (adminClient != null) {
083: try {
084: return adminClient.getAttributes(on, attrNames);
085: } catch (ConnectorException e) {
086: if (logger.isLoggable(Level.SEVERE)) {
087: logger.log(getLogRecord(Level.SEVERE,
088: "PSMN_CSPM0001", new Object[] { e
089: .getLocalizedMessage() }, null));
090: }
091: throw new IOException(e.getLocalizedMessage());
092: }
093: }
094:
095: return null;
096: }
097:
098: public Integer getMBeanCount() throws IOException {
099: if (adminClient != null) {
100: try {
101: return adminClient.getMBeanCount();
102: } catch (ConnectorException e) {
103: if (logger.isLoggable(Level.SEVERE)) {
104: logger.log(getLogRecord(Level.SEVERE,
105: "PSMN_CSPM0001", new Object[] { e
106: .getLocalizedMessage() }, null));
107: }
108: throw new IOException(e.getLocalizedMessage());
109: }
110: }
111:
112: return new Integer(0);
113: }
114:
115: public MBeanInfo getMBeanInfo(ObjectName on)
116: throws ReflectionException, InstanceNotFoundException,
117: IOException, IntrospectionException {
118: if (adminClient != null) {
119: try {
120: return adminClient.getMBeanInfo(on);
121: } catch (ConnectorException e) {
122: if (logger.isLoggable(Level.SEVERE)) {
123: logger.log(getLogRecord(Level.SEVERE,
124: "PSMN_CSPM0001", new Object[] { e
125: .getLocalizedMessage() }, null));
126: }
127: throw new IOException(e.getLocalizedMessage());
128: }
129: }
130:
131: return null;
132: }
133:
134: public Object invoke(ObjectName on, String operationName,
135: Object[] params, String[] signature)
136: throws ReflectionException, InstanceNotFoundException,
137: MBeanException, IOException {
138: if (adminClient != null) {
139: try {
140: return adminClient.invoke(on, operationName, params,
141: signature);
142: } catch (ConnectorException e) {
143: if (logger.isLoggable(Level.SEVERE)) {
144: logger.log(getLogRecord(Level.SEVERE,
145: "PSMN_CSPM0001", new Object[] { e
146: .getLocalizedMessage() }, null));
147: }
148: throw new IOException(e.getLocalizedMessage());
149: }
150: }
151:
152: return null;
153: }
154:
155: public Boolean isInstanceOf(ObjectName on, String className)
156: throws InstanceNotFoundException, IOException {
157: if (adminClient != null) {
158: try {
159: return adminClient.isInstanceOf(on, className) ? Boolean.TRUE
160: : Boolean.FALSE;
161: } catch (ConnectorException e) {
162: if (logger.isLoggable(Level.SEVERE)) {
163: logger.log(getLogRecord(Level.SEVERE,
164: "PSMN_CSPM0001", new Object[] { e
165: .getLocalizedMessage() }, null));
166: }
167: throw new IOException(e.getLocalizedMessage());
168: }
169: }
170:
171: return Boolean.FALSE;
172: }
173:
174: public Boolean isRegistered(ObjectName on) throws IOException {
175: if (adminClient != null) {
176: try {
177: return adminClient.isRegistered(on) ? Boolean.TRUE
178: : Boolean.FALSE;
179: } catch (ConnectorException e) {
180: if (logger.isLoggable(Level.SEVERE)) {
181: logger.log(getLogRecord(Level.SEVERE,
182: "PSMN_CSPM0001", new Object[] { e
183: .getLocalizedMessage() }, null));
184: }
185: throw new IOException(e.getLocalizedMessage());
186: }
187: }
188:
189: return Boolean.FALSE;
190: }
191:
192: public Set queryNames(ObjectName pattern, QueryExp expr)
193: throws IOException {
194: if (adminClient != null) {
195: try {
196: return adminClient.queryNames(pattern, expr);
197: } catch (ConnectorException e) {
198: if (logger.isLoggable(Level.SEVERE)) {
199: logger.log(getLogRecord(Level.SEVERE,
200: "PSMN_CSPM0001", new Object[] { e
201: .getLocalizedMessage() }, null));
202: }
203: throw new IOException(e.getLocalizedMessage());
204: }
205: }
206:
207: return null;
208: }
209:
210: public void removeNotificationListener(ObjectName on,
211: NotificationListener listener)
212: throws InstanceNotFoundException,
213: ListenerNotFoundException, IOException {
214: if (adminClient != null) {
215: try {
216: adminClient.removeNotificationListener(on, listener);
217: } catch (ConnectorException e) {
218: if (logger.isLoggable(Level.SEVERE)) {
219: logger.log(getLogRecord(Level.SEVERE,
220: "PSMN_CSPM0001", new Object[] { e
221: .getLocalizedMessage() }, null));
222: }
223: throw new IOException(e.getLocalizedMessage());
224: }
225: }
226: }
227:
228: public void setAttribute(ObjectName on, Attribute attr)
229: throws ReflectionException, InstanceNotFoundException,
230: MBeanException, AttributeNotFoundException,
231: InvalidAttributeValueException, IOException {
232: if (adminClient != null) {
233: try {
234: adminClient.setAttribute(on, attr);
235: } catch (ConnectorException e) {
236: if (logger.isLoggable(Level.SEVERE)) {
237: logger.log(getLogRecord(Level.SEVERE,
238: "PSMN_CSPM0001", new Object[] { e
239: .getLocalizedMessage() }, null));
240: }
241: throw new IOException(e.getLocalizedMessage());
242: }
243: }
244: }
245:
246: public AttributeList setAttributes(ObjectName on,
247: AttributeList attrs) throws ReflectionException,
248: InstanceNotFoundException, IOException {
249: if (adminClient != null) {
250: try {
251: return adminClient.setAttributes(on, attrs);
252: } catch (ConnectorException e) {
253: if (logger.isLoggable(Level.SEVERE)) {
254: logger.log(getLogRecord(Level.SEVERE,
255: "PSMN_CSPM0001", new Object[] { e
256: .getLocalizedMessage() }, null));
257: }
258: throw new IOException(e.getLocalizedMessage());
259: }
260: }
261:
262: return null;
263: }
264:
265: public void unregisterMBean(ObjectName on) {
266: if (adminClient != null) {
267: // WebSphere AdminClient doesn't support unregisterMBean!
268: // return adminClient.unregisterMBean(on);
269:
270: // TODO: Most likely we'll be using JMX 1.2 Common Component by putting
271: // it in our WebApp lib.
272: }
273: }
274:
275: public void disconnect() {
276: adminClient = null;
277: }
278:
279: private AdminClient adminClient;
280:
281: public IbmClientImpl() {
282: }
283:
284: public void setAdminClient(AdminClient adminClient) {
285: this .adminClient = adminClient;
286: }
287:
288: public Object invoke(Object proxy, Method method, Object[] params)
289: throws Throwable {
290: List signature = new ArrayList();
291: Class[] paramTypeClasses = method.getParameterTypes();
292: if (paramTypeClasses != null) {
293: } else if (paramTypeClasses.length != 0) {
294: for (int i = 0; i < paramTypeClasses.length; i++) {
295: signature.add(paramTypeClasses[i].getName());
296: }
297: }
298: String[] paramTypes = (signature.size() == 0) ? null
299: : ((String[]) signature.toArray(new String[signature
300: .size()]));
301: return adminClient.invoke(objectNameProxy, method.getName(),
302: params, paramTypes);
303: }
304: }
|