001: /**
002: * $Id: ListDesktopStatisticsBean.java,v 1.8 2006/03/24 08:36:16 pa157442 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console.monitoring.desktopStatistics;
014:
015: import java.util.LinkedList;
016: import java.util.Set;
017: import java.util.Iterator;
018: import java.util.ArrayList;
019: import java.util.logging.Level;
020: import java.util.List;
021:
022: import java.io.IOException;
023:
024: import javax.management.AttributeNotFoundException;
025: import javax.management.MBeanException;
026: import javax.management.InstanceNotFoundException;
027: import javax.management.ReflectionException;
028: import javax.management.MalformedObjectNameException;
029: import javax.management.MBeanServerConnection;
030: import javax.management.ObjectName;
031: import javax.management.AttributeList;
032: import javax.management.Attribute;
033: import javax.management.QueryExp;
034:
035: import com.sun.portal.admin.common.util.AdminUtil;
036: import com.sun.portal.admin.common.util.AdminClientUtil;
037: import com.sun.portal.admin.console.common.PSBaseBean;
038:
039: import com.sun.data.provider.DataProvider;
040: import com.sun.data.provider.impl.ObjectListDataProvider;
041:
042: import com.sun.portal.admin.console.common.PortalBaseBean;
043: import com.sun.portal.admin.console.common.PSBaseBean;
044:
045: /**
046: *
047: * @author pa157442
048: */
049: public class ListDesktopStatisticsBean extends PSBaseBean {
050:
051: public static final String MONITORING = "Monitoring";
052: public static final String DESKTOPREQUESTSTATISTIC = "DesktopRequestStatistic";
053: public static final String EXCEPTION = "Exception";
054: public static final String RESPONSE = "Response";
055: public static final String REQUESTS = "Requests";
056:
057: private ObjectName objectName;
058: private MBeanServerConnection mbsc;
059: private String defaultDomain;
060: private Set mbeanNames;
061: private String portalId;
062: private ObjectListDataProvider desktopStatistics;
063: private int count = 0;
064: private boolean refresh = false;
065:
066: private String[] attributeList = { "Count", "MinTime", "MaxTime",
067: "TotalTime", "RollingAvgTime", "Name" };
068:
069: private ObjectListDataProvider getNewObjectListDataProvider() {
070: // Has to be initialized as Lockhart does not like it to be null.
071: List list = new LinkedList();
072: ObjectListDataProvider dataProvider = new ObjectListDataProvider(
073: list);
074: dataProvider.setObjectType(DesktopStatisticsBean.class);
075: return dataProvider;
076: }
077:
078: /** Creates a new instance of ListDesktopStatisticsBean */
079: public ListDesktopStatisticsBean() {
080: portalId = (String) getSessionAttribute(ATTR_SELECTED_PORTAL);
081: }
082:
083: private void populateDesktopStatisticsTable() {
084: if (count < 1 || refresh) {
085: count++;
086: refresh = false;
087: desktopStatistics = getNewObjectListDataProvider();
088:
089: ObjectName pattern = null;
090: Set instanceNames = null;
091:
092: PortalBaseBean portalBean = new PortalBaseBean();
093: try {
094: instanceNames = portalBean
095: .getInstanceObjectNames(portalId);
096: } catch (IOException ie) {
097: log(
098: Level.SEVERE,
099: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
100: ie);
101: } catch (Exception e) {
102: log(
103: Level.SEVERE,
104: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
105: e);
106: }
107:
108: PSBaseBean psBean = new PSBaseBean();
109:
110: LinkedList statisticsList = new LinkedList();
111:
112: for (Iterator counter = instanceNames.iterator(); counter
113: .hasNext();) {
114: ObjectName instanceName = (ObjectName) counter.next();
115: String instanceId = (String) psBean.getAttribute(
116: (ObjectName) instanceName, "ID");
117: //MBean path of Monitoring
118: LinkedList path = new LinkedList();
119: path.addFirst(getDomain());
120: path.addFirst(portalId);
121: path.addFirst(instanceId);
122: path.addFirst(MONITORING);
123:
124: try {
125: //Object Name of Monitoring
126: objectName = AdminClientUtil
127: .getResourceMBeanObjectName(
128: AdminUtil.MONITORING_MBEAN_TYPE,
129: path);
130: } catch (MalformedObjectNameException mone) {
131: log(
132: Level.SEVERE,
133: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
134: mone);
135: }
136:
137: mbsc = getMBeanServerConnection();
138:
139: Boolean connected = Boolean.FALSE;
140: boolean instanceDown = false;
141:
142: try {
143:
144: try {
145: mbsc.invoke(objectName, "connect", null, null);
146: connected = Boolean.TRUE;
147: } catch (ReflectionException re) {
148: log(
149: Level.SEVERE,
150: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
151: re);
152: } catch (IOException ie) {
153: log(
154: Level.SEVERE,
155: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
156: ie);
157: } catch (InstanceNotFoundException infe) {
158: log(
159: Level.SEVERE,
160: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
161: infe);
162: } catch (MBeanException mbe) {
163: log(
164: Level.SEVERE,
165: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
166: mbe);
167: boolean io = mbe.getCause() instanceof IOException;
168: if (io) {
169: instanceDown = true;
170: }
171: }
172:
173: if (!instanceDown) {
174: try {
175: defaultDomain = (String) mbsc.getAttribute(
176: objectName, "DefaultDomain");
177: } catch (MBeanException mbe) {
178: log(
179: Level.SEVERE,
180: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
181: mbe);
182: } catch (AttributeNotFoundException anfe) {
183: log(
184: Level.SEVERE,
185: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
186: anfe);
187: } catch (InstanceNotFoundException infe) {
188: log(
189: Level.SEVERE,
190: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
191: infe);
192: } catch (ReflectionException re) {
193: log(
194: Level.SEVERE,
195: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
196: re);
197: } catch (IOException ie) {
198: log(
199: Level.SEVERE,
200: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
201: ie);
202: }
203:
204: try {
205: pattern = new ObjectName(defaultDomain
206: + ":type="
207: + DESKTOPREQUESTSTATISTIC + ",*");
208: } catch (MalformedObjectNameException mone) {
209: log(
210: Level.SEVERE,
211: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
212: mone);
213: }
214:
215: try {
216: mbeanNames = (Set) mbsc.invoke(objectName,
217: "queryNames", new Object[] {
218: pattern, null },
219: new String[] {
220: ObjectName.class.getName(),
221: QueryExp.class.getName() });
222: } catch (IOException ie) {
223: log(
224: Level.SEVERE,
225: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
226: ie);
227: } catch (InstanceNotFoundException infe) {
228: log(
229: Level.SEVERE,
230: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
231: infe);
232: } catch (ReflectionException re) {
233: log(
234: Level.SEVERE,
235: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
236: re);
237: } catch (MBeanException mbe) {
238: log(
239: Level.SEVERE,
240: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
241: mbe);
242: }
243:
244: if (mbeanNames != null && mbeanNames.size() > 0) {
245: for (Iterator iterator = mbeanNames
246: .iterator(); iterator.hasNext();) {
247: ObjectName mBeanName = (ObjectName) iterator
248: .next();
249: AttributeList values = null;
250: try {
251: //values = mbsc.getAttributes(objectName, attributeList);
252: values = (AttributeList) mbsc
253: .invoke(
254: objectName,
255: "getAttributes",
256: new Object[] {
257: mBeanName,
258: attributeList },
259: new String[] {
260: ObjectName.class
261: .getName(),
262: String[].class
263: .getName() });
264: } catch (InstanceNotFoundException infe) {
265: log(
266: Level.SEVERE,
267: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
268: infe);
269: } catch (ReflectionException re) {
270: log(
271: Level.SEVERE,
272: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
273: re);
274: } catch (IOException ie) {
275: log(
276: Level.SEVERE,
277: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
278: ie);
279: } catch (MBeanException mbe) {
280: log(
281: Level.SEVERE,
282: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
283: mbe);
284: }
285:
286: Attribute attrCount = (Attribute) values
287: .get(0);
288: Attribute attrMinTime = (Attribute) values
289: .get(1);
290: Attribute attrMaxTime = (Attribute) values
291: .get(2);
292: Attribute attrTotalTime = (Attribute) values
293: .get(3);
294: Attribute attrRollingAvgTime = (Attribute) values
295: .get(4);
296: Attribute attrName = (Attribute) values
297: .get(5);
298:
299: String name = (String) attrName
300: .getValue();
301:
302: if (name.substring(31)
303: .equals(EXCEPTION)) {
304: name = name.substring(31) + " "
305: + RESPONSE;
306: } else {
307: name = name.substring(31) + " "
308: + REQUESTS;
309: }
310:
311: Long count = (Long) attrCount
312: .getValue();
313: Long minTime = (Long) attrMinTime
314: .getValue();
315: Long maxTime = (Long) attrMaxTime
316: .getValue();
317: Long totalTime = (Long) attrTotalTime
318: .getValue();
319: Long rollingAvgTime = (Long) attrRollingAvgTime
320: .getValue();
321:
322: statisticsList
323: .add(new DesktopStatisticsBean(
324: name, count, minTime,
325: maxTime, totalTime,
326: rollingAvgTime,
327: instanceId, false));
328:
329: }
330: }
331: } else {
332: statisticsList.add(new DesktopStatisticsBean(
333: null, null, null, null, null, null,
334: instanceId, true));
335: }
336: desktopStatistics = new ObjectListDataProvider(
337: statisticsList);
338: desktopStatistics
339: .setObjectType(DesktopStatisticsBean.class);
340:
341: } finally {
342: if (connected.booleanValue()) {
343: try {
344: mbsc.invoke(objectName, "disconnect", null,
345: null);
346: } catch (ReflectionException re) {
347: log(
348: Level.SEVERE,
349: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
350: re);
351: } catch (InstanceNotFoundException infe) {
352: log(
353: Level.SEVERE,
354: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
355: infe);
356: } catch (IOException ie) {
357: log(
358: Level.SEVERE,
359: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
360: ie);
361: } catch (MBeanException me) {
362: log(
363: Level.SEVERE,
364: "ListDesktopStatisticsBean.ListDesktopStatisticsBean()",
365: me);
366: }
367: }
368:
369: }
370: }
371:
372: }
373: }
374:
375: public DataProvider getDesktopStatistics() {
376: populateDesktopStatisticsTable();
377: return desktopStatistics;
378: }
379:
380: public void setDesktopStatistics(
381: ObjectListDataProvider desktopStatistics) {
382: this .desktopStatistics = desktopStatistics;
383: }
384:
385: public String refresh() {
386: refresh = true;
387: return "success";
388: }
389:
390: }
|