Source Code Cross Referenced for ListChannelStatisticsBean.java in  » Portal » Open-Portal » com » sun » portal » admin » console » monitoring » channelStatistics » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.admin.console.monitoring.channelStatistics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: ListChannelStatisticsBean.java,v 1.12 2006/06/08 11:08:59 kk155903 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.channelStatistics;
014:
015:        import java.util.logging.Level;
016:        import java.util.List;
017:        import java.util.LinkedList;
018:        import java.util.Set;
019:        import java.util.ArrayList;
020:        import java.util.Iterator;
021:        import java.util.StringTokenizer;
022:
023:        import java.io.IOException;
024:
025:        import javax.management.AttributeNotFoundException;
026:        import javax.management.MBeanException;
027:        import javax.management.InstanceNotFoundException;
028:        import javax.management.ReflectionException;
029:        import javax.management.MalformedObjectNameException;
030:        import javax.management.MBeanServerConnection;
031:        import com.sun.portal.admin.common.PSMBeanException;
032:        import javax.management.ObjectName;
033:        import javax.management.AttributeList;
034:        import javax.management.Attribute;
035:        import javax.management.QueryExp;
036:
037:        import com.sun.portal.admin.common.util.AdminUtil;
038:        import com.sun.portal.admin.common.util.AdminClientUtil;
039:        import com.sun.portal.admin.console.common.PSBaseBean;
040:        import com.sun.portal.admin.console.monitoring.preferences.Preferences;
041:        import com.sun.portal.admin.console.fabric.ListInstancesBean;
042:
043:        import javax.faces.context.FacesContext;
044:        import javax.servlet.http.HttpServletRequest;
045:
046:        import com.sun.data.provider.DataProvider;
047:        import com.sun.data.provider.impl.ObjectListDataProvider;
048:
049:        import com.sun.web.ui.component.Hyperlink;
050:        import javax.faces.component.UIComponent;
051:        import javax.faces.component.UIParameter;
052:
053:        public class ListChannelStatisticsBean extends PSBaseBean {
054:
055:            private ObjectName objectName;
056:            private MBeanServerConnection mbsc;
057:            private String defaultDomain;
058:            private Set mbeanNames;
059:            private String channelName;
060:            private String portalId;
061:            private Preferences prefs = null;
062:            private ObjectListDataProvider channelStatistics;
063:            private LinkedList statisticsList;
064:            private String previousInstanceId;
065:            private Object previousDN;
066:            private Set channelAndContainerNames = null;
067:            private boolean refresh = false;
068:            private boolean dnChanged = false;
069:
070:            private String[] attributeList = { "Count", "MinTime", "MaxTime",
071:                    "TotalTime", "RollingAvgTime", "Name" };
072:
073:            public static final String ATTR_CHANNEL = "attr_channel";
074:            public static final String MONITORING = "Monitoring";
075:            public static final String CHANNELACTIONSTATISTIC = "ChannelActionStatistic";
076:            public static final String CHANNELCACHEHITSSTATISTIC = "ChannelCacheHitsStatistic";
077:            public static final String ATTR_SELECTED_CHANNEL_NAME = "selected.channel.name";
078:            public static final char NAME_SEPARATOR_CHAR = '/';
079:
080:            private ObjectListDataProvider getNewObjectListDataProvider() {
081:                // Has to be initialized as Lockhart does not like it to be null.
082:                List list = new LinkedList();
083:                ObjectListDataProvider dataProvider = new ObjectListDataProvider(
084:                        list);
085:                dataProvider.setObjectType(ChannelStatisticsBean.class);
086:                return dataProvider;
087:            }
088:
089:            /** Creates a new instance of ChannelStatisticsBean */
090:            public ListChannelStatisticsBean() {
091:                portalId = (String) getSessionAttribute(ATTR_SELECTED_PORTAL);
092:                prefs = new Preferences();
093:            }
094:
095:            private void populateChannelStatisticsTable() {
096:
097:                Set channelNames = getChannels();
098:                //LinkedList statisticsList = new LinkedList();
099:                String instanceId = (String) getSessionAttribute(ATTR_SELECTED_INSTANCE);
100:                if (instanceId == null || instanceId.length() == 0) {
101:                    new ListInstancesBean();
102:                    instanceId = (String) getSessionAttribute(ATTR_SELECTED_INSTANCE);
103:                }
104:
105:                if (instanceId == null || instanceId.length() == 0) {
106:                    listChannels(channelNames);
107:                    channelStatistics = new ObjectListDataProvider(
108:                            statisticsList);
109:                    channelStatistics
110:                            .setObjectType(ChannelStatisticsBean.class);
111:                    return;
112:                }
113:
114:                if ((instanceId.equals(previousInstanceId)) && !dnChanged
115:                        && !refresh) {
116:                    refresh = false;
117:                    return;
118:                }
119:
120:                previousInstanceId = instanceId;
121:                statisticsList = new LinkedList();
122:
123:                Boolean connected = Boolean.FALSE;
124:
125:                ObjectName pattern = null;
126:                ObjectName cacheHitStatisticPattern = null;
127:
128:                //MBean path of Monitoring
129:                LinkedList path = new LinkedList();
130:                path.addFirst(getDomain());
131:                path.addFirst(portalId);
132:                path.addFirst(instanceId);
133:                path.addFirst(MONITORING);
134:
135:                try {
136:                    //Object Name of Monitoring
137:                    objectName = AdminClientUtil.getResourceMBeanObjectName(
138:                            AdminUtil.MONITORING_MBEAN_TYPE, path);
139:                } catch (MalformedObjectNameException mone) {
140:                    log(
141:                            Level.SEVERE,
142:                            "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
143:                            mone);
144:                }
145:
146:                mbsc = getMBeanServerConnection();
147:
148:                boolean instanceDown = false;
149:
150:                try {
151:
152:                    try {
153:                        mbsc.invoke(objectName, "connect", null, null);
154:                        connected = Boolean.TRUE;
155:                    } catch (ReflectionException re) {
156:                        log(
157:                                Level.SEVERE,
158:                                "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
159:                                re);
160:                    } catch (IOException ie) {
161:                        log(
162:                                Level.SEVERE,
163:                                "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
164:                                ie);
165:                    } catch (InstanceNotFoundException infe) {
166:                        log(
167:                                Level.SEVERE,
168:                                "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
169:                                infe);
170:                    } catch (MBeanException mbe) {
171:                        log(
172:                                Level.SEVERE,
173:                                "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
174:                                mbe);
175:                        boolean io = mbe.getCause() instanceof  IOException;
176:                        if (io) {
177:                            instanceDown = true;
178:                        }
179:                    }
180:
181:                    if (!instanceDown) {
182:                        try {
183:                            defaultDomain = (String) mbsc.getAttribute(
184:                                    objectName, "DefaultDomain");
185:                        } catch (MBeanException mbe) {
186:                            log(
187:                                    Level.SEVERE,
188:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
189:                                    mbe);
190:                        } catch (AttributeNotFoundException anfe) {
191:                            log(
192:                                    Level.SEVERE,
193:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
194:                                    anfe);
195:                        } catch (InstanceNotFoundException infe) {
196:                            log(
197:                                    Level.SEVERE,
198:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
199:                                    infe);
200:                        } catch (ReflectionException re) {
201:                            log(
202:                                    Level.SEVERE,
203:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
204:                                    re);
205:                        } catch (IOException ie) {
206:                            log(
207:                                    Level.SEVERE,
208:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
209:                                    ie);
210:                        }
211:
212:                        //String channel = (String) getSessionAttribute(ATTR_CHANNEL);
213:                        if (channelNames != null && channelNames.size() > 0) {
214:
215:                            for (Iterator iterate = channelNames.iterator(); iterate
216:                                    .hasNext();) {
217:                                String channelName = (String) iterate.next();
218:
219:                                try {
220:                                    pattern = new ObjectName(defaultDomain
221:                                            + ":type=" + CHANNELACTIONSTATISTIC
222:                                            + ",name=" + channelName + ",*");
223:                                    cacheHitStatisticPattern = new ObjectName(
224:                                            defaultDomain + ":type="
225:                                                    + CHANNELCACHEHITSSTATISTIC
226:                                                    + ",name=" + channelName
227:                                                    + ",*");
228:                                } catch (MalformedObjectNameException mone) {
229:                                    log(
230:                                            Level.SEVERE,
231:                                            "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
232:                                            mone);
233:                                }
234:
235:                                try {
236:                                    mbeanNames = (Set) mbsc.invoke(objectName,
237:                                            "queryNames", new Object[] {
238:                                                    pattern, null },
239:                                            new String[] {
240:                                                    ObjectName.class.getName(),
241:                                                    QueryExp.class.getName() });
242:                                    if (mbeanNames != null) {
243:                                        mbeanNames
244:                                                .addAll((Set) mbsc
245:                                                        .invoke(
246:                                                                objectName,
247:                                                                "queryNames",
248:                                                                new Object[] {
249:                                                                        cacheHitStatisticPattern,
250:                                                                        null },
251:                                                                new String[] {
252:                                                                        ObjectName.class
253:                                                                                .getName(),
254:                                                                        QueryExp.class
255:                                                                                .getName() }));
256:                                    } else {
257:                                        mbeanNames = (Set) mbsc
258:                                                .invoke(
259:                                                        objectName,
260:                                                        "queryNames",
261:                                                        new Object[] {
262:                                                                cacheHitStatisticPattern,
263:                                                                null },
264:                                                        new String[] {
265:                                                                ObjectName.class
266:                                                                        .getName(),
267:                                                                QueryExp.class
268:                                                                        .getName() });
269:                                    }
270:                                } catch (IOException ie) {
271:                                    log(
272:                                            Level.SEVERE,
273:                                            "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
274:                                            ie);
275:                                } catch (InstanceNotFoundException infe) {
276:                                    log(
277:                                            Level.SEVERE,
278:                                            "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
279:                                            infe);
280:                                } catch (ReflectionException re) {
281:                                    log(
282:                                            Level.SEVERE,
283:                                            "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
284:                                            re);
285:                                } catch (MBeanException mbe) {
286:                                    log(
287:                                            Level.SEVERE,
288:                                            "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
289:                                            mbe);
290:                                }
291:
292:                                if (mbeanNames != null && mbeanNames.size() > 0) {
293:                                    for (Iterator iterator = mbeanNames
294:                                            .iterator(); iterator.hasNext();) {
295:                                        ObjectName mBeanName = (ObjectName) iterator
296:                                                .next();
297:                                        AttributeList values = null;
298:                                        try {
299:                                            //values = mbsc.getAttributes(objectName, attributeList); 
300:                                            values = (AttributeList) mbsc
301:                                                    .invoke(
302:                                                            objectName,
303:                                                            "getAttributes",
304:                                                            new Object[] {
305:                                                                    mBeanName,
306:                                                                    attributeList },
307:                                                            new String[] {
308:                                                                    ObjectName.class
309:                                                                            .getName(),
310:                                                                    String[].class
311:                                                                            .getName() });
312:                                        } catch (InstanceNotFoundException infe) {
313:                                            log(
314:                                                    Level.SEVERE,
315:                                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
316:                                                    infe);
317:                                        } catch (ReflectionException re) {
318:                                            log(
319:                                                    Level.SEVERE,
320:                                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
321:                                                    re);
322:                                        } catch (IOException ie) {
323:                                            log(
324:                                                    Level.SEVERE,
325:                                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
326:                                                    ie);
327:                                        } catch (MBeanException mbe) {
328:                                            log(
329:                                                    Level.SEVERE,
330:                                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
331:                                                    mbe);
332:                                        }
333:
334:                                        Attribute attrCount = (Attribute) values
335:                                                .get(0);
336:                                        Attribute attrMinTime = (Attribute) values
337:                                                .get(1);
338:                                        Attribute attrMaxTime = (Attribute) values
339:                                                .get(2);
340:                                        Attribute attrTotalTime = (Attribute) values
341:                                                .get(3);
342:                                        Attribute attrRollingAvgTime = (Attribute) values
343:                                                .get(4);
344:                                        Attribute attrName = (Attribute) values
345:                                                .get(5);
346:
347:                                        String type = mBeanName
348:                                                .getKeyProperty("type");
349:                                        String name = null;
350:                                        if (type.equals(CHANNELACTIONSTATISTIC)) {
351:                                            name = mBeanName
352:                                                    .getKeyProperty("channelAction");
353:                                        } else if (type
354:                                                .equals(CHANNELCACHEHITSSTATISTIC)) {
355:                                            name = "Cached-Content";
356:                                        }
357:                                        /*  if(name.substring(31).equals(EXCEPTION)) {
358:                                              name = name.substring(31) + " " + RESPONSE;
359:                                          } else {
360:                                              name = name.substring(31) + " " + REQUESTS;
361:                                          }*/
362:
363:                                        Long count = (Long) attrCount
364:                                                .getValue();
365:                                        Long minTime = (Long) attrMinTime
366:                                                .getValue();
367:                                        Long maxTime = (Long) attrMaxTime
368:                                                .getValue();
369:                                        Long totalTime = (Long) attrTotalTime
370:                                                .getValue();
371:                                        Long rollingAvgTime = (Long) attrRollingAvgTime
372:                                                .getValue();
373:
374:                                        /* Get the fqcn from the ObjectName. Remove the type= , name= and  channelAction=       */
375:                                        String fqcn = mBeanName.toString();
376:                                        StringTokenizer st = new StringTokenizer(
377:                                                fqcn, ",");
378:                                        StringBuffer fullyQualifiedName = new StringBuffer();
379:                                        int index = 0;
380:                                        while (st.hasMoreTokens()) {
381:                                            String token = st.nextToken();
382:                                            if ((token.indexOf("type=") != -1)
383:                                                    || (token
384:                                                            .indexOf("channelAction=") != -1)
385:                                                    || (token.indexOf("name=") != -1)) {
386:                                                continue;
387:                                            }
388:                                            /* This ensures a proper comma seperated string */
389:                                            if (index > 1) {
390:                                                fullyQualifiedName.append(",");
391:                                            }
392:                                            fullyQualifiedName.append(token);
393:                                            index++;
394:                                        }
395:
396:                                        statisticsList
397:                                                .add(new ChannelStatisticsBean(
398:                                                        channelName, name,
399:                                                        count, minTime,
400:                                                        maxTime, totalTime,
401:                                                        rollingAvgTime, false,
402:                                                        fullyQualifiedName
403:                                                                .toString()));
404:
405:                                    }
406:                                } else {
407:                                    statisticsList
408:                                            .add(new ChannelStatisticsBean(
409:                                                    channelName, null, null,
410:                                                    null, null, null, null,
411:                                                    true, channelName));
412:                                }
413:
414:                            }
415:                        }
416:                    } else {
417:                        listChannels(channelNames);
418:                    }
419:                    channelStatistics = new ObjectListDataProvider(
420:                            statisticsList);
421:                    channelStatistics
422:                            .setObjectType(ChannelStatisticsBean.class);
423:
424:                } finally {
425:                    if (connected.booleanValue()) {
426:                        try {
427:                            mbsc.invoke(objectName, "disconnect", null, null);
428:                        } catch (ReflectionException re) {
429:                            log(
430:                                    Level.SEVERE,
431:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
432:                                    re);
433:                        } catch (InstanceNotFoundException infe) {
434:                            log(
435:                                    Level.SEVERE,
436:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
437:                                    infe);
438:                        } catch (IOException ie) {
439:                            log(
440:                                    Level.SEVERE,
441:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
442:                                    ie);
443:                        } catch (MBeanException me) {
444:                            log(
445:                                    Level.SEVERE,
446:                                    "Exception in ListChannelStatisticsBean.populateChannelStatisticsTable()",
447:                                    me);
448:                        }
449:                    }
450:
451:                }
452:
453:            }
454:
455:            private Set getChannels() {
456:
457:                String currentDN = (String) getCurrentDN();
458:
459:                if (currentDN.equals(previousDN)) {
460:                    dnChanged = false;
461:                    return channelAndContainerNames;
462:                }
463:
464:                dnChanged = true;
465:                previousDN = currentDN;
466:                Boolean all = Boolean.TRUE;
467:
468:                //Setting the params and signature
469:                Object[] params = { currentDN, all };
470:                String[] signature = { "java.lang.String", "java.lang.Boolean" };
471:
472:                String methodName1 = "getExistingChannels";
473:                String methodName2 = "getExistingContainers";
474:                ObjectName objName = null;
475:                Set containerNames = null;
476:
477:                try {
478:                    objName = AdminClientUtil.getDisplayProfileMBeanObjectName(
479:                            AdminClientUtil.DEFAULT_DOMAIN, portalId);
480:                } catch (MalformedObjectNameException mone) {
481:                    log(
482:                            Level.SEVERE,
483:                            "Exception in ListChannelStatisticsBean.getChannels()",
484:                            mone);
485:                }
486:
487:                try {
488:                    // Invoke the get method on the portal Desktop MBean
489:                    channelAndContainerNames = (Set) getMBeanServerConnection()
490:                            .invoke(objName, methodName1, params, signature);
491:                    containerNames = (Set) getMBeanServerConnection().invoke(
492:                            objName, methodName2, params, signature);
493:                    channelAndContainerNames.addAll(containerNames);
494:                } catch (ReflectionException re) {
495:                    log(
496:                            Level.SEVERE,
497:                            "Exception in ListChannelStatisticsBean.getChannels()",
498:                            re);
499:                } catch (InstanceNotFoundException infe) {
500:                    log(
501:                            Level.SEVERE,
502:                            "Exception in ListChannelStatisticsBean.getChannels()",
503:                            infe);
504:                } catch (IOException ie) {
505:                    log(
506:                            Level.SEVERE,
507:                            "Exception in ListChannelStatisticsBean.getChannels()",
508:                            ie);
509:                } catch (MBeanException me) {
510:                    log(
511:                            Level.SEVERE,
512:                            "Exception in ListChannelStatisticsBean.getChannels()",
513:                            me);
514:                }
515:
516:                return channelAndContainerNames;
517:
518:            }
519:
520:            private LinkedList listChannels(Set channelNames) {
521:                if (channelNames != null && channelNames.size() > 0) {
522:                    for (Iterator iterate = channelNames.iterator(); iterate
523:                            .hasNext();) {
524:                        String channelName = (String) iterate.next();
525:                        statisticsList.add(new ChannelStatisticsBean(
526:                                channelName, null, null, null, null, null,
527:                                null, true, channelName));
528:                    }
529:                }
530:                return statisticsList;
531:            }
532:
533:            public DataProvider getChannelStatistics() {
534:                // channelStatistics = getNewObjectListDataProvider();
535:                //statisticsList = new LinkedList(); 
536:                populateChannelStatisticsTable();
537:                return channelStatistics;
538:            }
539:
540:            public void setDesktopStatistics(DataProvider desktopStatistics) {
541:                this .channelStatistics = channelStatistics;
542:            }
543:
544:            public String refresh() {
545:                refresh = true;
546:                return "success";
547:            }
548:
549:            public Preferences getPreferences() {
550:                return prefs;
551:            }
552:
553:        }
ww_w_.___j__av___a__2___s___._c__o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.