Source Code Cross Referenced for MRCConnector.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » monitoring » console » 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 » EJB Server geronimo » plugins » org.apache.geronimo.monitoring.console 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.monitoring.console;
017:
018:        import java.sql.Connection;
019:        import java.sql.Statement;
020:        import java.text.Format;
021:        import java.text.SimpleDateFormat;
022:        import java.util.ArrayList;
023:        import java.util.Date;
024:        import java.util.HashMap;
025:        import java.util.Hashtable;
026:        import java.util.Iterator;
027:        import java.util.Properties;
028:        import java.util.Set;
029:        import java.util.TreeMap;
030:        import java.util.TreeSet;
031:
032:        import javax.management.MBeanServerConnection;
033:        import javax.management.ObjectName;
034:        import javax.management.remote.JMXConnector;
035:        import javax.management.remote.JMXConnectorFactory;
036:        import javax.management.remote.JMXServiceURL;
037:
038:        import javax.naming.Context;
039:        import javax.naming.InitialContext;
040:
041:        import org.apache.geronimo.monitoring.MasterRemoteControlRemote;
042:        import org.apache.geronimo.monitoring.console.util.DBManager;
043:
044:        import org.apache.geronimo.crypto.EncryptionManager;
045:
046:        public class MRCConnector {
047:
048:            private static final String PATH = "geronimo:ServiceModule=org.apache.geronimo.plugins.monitoring/agent-car-jmx/2.2-SNAPSHOT/car,J2EEServer=geronimo,name=MasterRemoteControlJMX,j2eeType=GBean";
049:            private static MBeanServerConnection mbServerConn;
050:            private MasterRemoteControlRemote mrc = null;
051:            private int Protocol = 0;
052:
053:            MRCConnector() {
054:
055:            }
056:
057:            /**
058:             * @param ip -
059:             *            IP address of mrc-server to connect to
060:             * @param userName -
061:             *            Username for JMX connection to the host
062:             * @param password -
063:             *            Password for JMX connection to the host
064:             * @throws Exception -
065:             *             If the connection to mrc-server fails
066:             */
067:            public MRCConnector(String ip, String userName, String password,
068:                    int port, int protocol) throws Exception {
069:                // decrypt the password
070:                password = (String) EncryptionManager.decrypt(password);
071:                Protocol = protocol;
072:
073:                if (Protocol == 1) {
074:
075:                    try {
076:                        Properties props = new Properties();
077:                        props
078:                                .setProperty(Context.INITIAL_CONTEXT_FACTORY,
079:                                        "org.apache.openejb.client.RemoteInitialContextFactory");
080:                        props.setProperty(Context.PROVIDER_URL, "ejbd://" + ip
081:                                + ":" + port);
082:                        props.setProperty(Context.SECURITY_PRINCIPAL, userName);
083:                        props.setProperty(Context.SECURITY_CREDENTIALS,
084:                                password);
085:                        props.setProperty("openejb.authentication.realmName",
086:                                "geronimo-admin");
087:                        Context ic = new InitialContext(props);
088:                        mrc = (MasterRemoteControlRemote) ic
089:                                .lookup("ejb/mgmt/MRCRemote");
090:                        mrc.setUpMEJB(userName, password);
091:                    } catch (Exception e) {
092:                        throw e;
093:                    }
094:
095:                } else {
096:                    try {
097:                        JMXServiceURL serviceURL = new JMXServiceURL(
098:                                "service:jmx:rmi:///jndi/rmi://" + ip + ":"
099:                                        + port + "/JMXConnector");
100:                        Hashtable<String, Object> env = new Hashtable<String, Object>();
101:                        String[] credentials = new String[2];
102:                        credentials[0] = userName;
103:                        credentials[1] = password;
104:                        env.put(JMXConnector.CREDENTIALS, credentials);
105:                        JMXConnector connector = JMXConnectorFactory.connect(
106:                                serviceURL, env);
107:                        mbServerConn = connector.getMBeanServerConnection();
108:                    } catch (Exception e) {
109:                        throw e;
110:                    }
111:
112:                }
113:                // when the code has reach this point, a connection was successfully
114:                // established
115:                // so we need to update the last_seen attribute for the server
116:                Format formatter = null;
117:                formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
118:                Date date = new Date(System.currentTimeMillis());
119:                String currentTime = formatter.format(date);
120:
121:                Connection conn = DBManager.createConnection();
122:                try {
123:                    Statement stmt = conn.createStatement();
124:                    stmt.executeUpdate("UPDATE SERVERS SET LAST_SEEN = '"
125:                            + currentTime + "' WHERE IP='" + ip + "'");
126:                } catch (Exception e) {
127:                    throw e;
128:                } finally {
129:                    try {
130:                        if (conn != null) {
131:                            conn.close();
132:                        }
133:                    } catch (Exception e) {
134:
135:                    }
136:                }
137:            }
138:
139:            /**
140:             * @return - Returns an Long representing the current snapshot duration set
141:             *         on the server side
142:             * @throws Exception -
143:             *             If the connection to the MRC-Server fails
144:             */
145:            public Long getSnapshotDuration() throws Exception {
146:                if (Protocol == 1) {
147:
148:                    return mrc.getSnapshotDuration();
149:
150:                } else {
151:
152:                    return (Long) mbServerConn.invoke(new ObjectName(PATH),
153:                            "getSnapshotDuration", new Object[] {},
154:                            new String[] {});
155:                }
156:            }
157:
158:            /**
159:             * @return - Returns an ArrayList of String objects containing a listing of
160:             *         all statistics values being collected
161:             * @throws Exception -
162:             *             If the connection to the MRC-Server fails
163:             */
164:            @SuppressWarnings("unchecked")
165:            public HashMap<String, ArrayList<String>> getDataNameList()
166:                    throws Exception {
167:
168:                HashMap<String, ArrayList<String>> DataNameList = new HashMap<String, ArrayList<String>>();
169:
170:                if (Protocol == 1) {
171:
172:                    try {
173:                        DataNameList = mrc.getAllSnapshotStatAttributes();
174:                    } catch (Exception e) {
175:                        e.printStackTrace();
176:                    }
177:
178:                } else {
179:                    try {
180:                        DataNameList = (HashMap<String, ArrayList<String>>) mbServerConn
181:                                .invoke(new ObjectName(PATH),
182:                                        "getAllSnapshotStatAttributes",
183:                                        new Object[] {}, new String[] {});
184:                    } catch (Exception e) {
185:                        e.printStackTrace();
186:                    }
187:                }
188:                // Strip out snapshot_date and snapshot_time, we know these exist
189:                for (Iterator<String> it = DataNameList.keySet().iterator(); it
190:                        .hasNext();) {
191:                    String mbeanName = it.next();
192:                    DataNameList.get(mbeanName).remove("snapshot_date");
193:                    DataNameList.get(mbeanName).remove("snapshot_time");
194:                }
195:                return DataNameList;
196:            }
197:
198:            /**
199:             * @param snapCount -
200:             *            Number of snapshots to request from the server
201:             * @param skipCount -
202:             *            Every nth snapshot. A value of 1 will be every 1. A value of 2
203:             *            will be every other.
204:             * @return - Returns an ArrayList of Map objects.
205:             * @throws Exception -
206:             *             If the connection to the MRC-Server fails
207:             */
208:            @SuppressWarnings("unchecked")
209:            public ArrayList<HashMap<String, HashMap<String, Object>>> getSnapshots(
210:                    int snapCount, int skipCount) throws Exception {
211:                ArrayList<HashMap<String, HashMap<String, Object>>> snapshotList = null;
212:                if (Protocol == 1) {
213:
214:                    snapshotList = mrc.fetchSnapshotData(snapCount, skipCount);
215:
216:                } else {
217:                    snapshotList = (ArrayList<HashMap<String, HashMap<String, Object>>>) mbServerConn
218:                            .invoke(new ObjectName(PATH), "fetchSnapshotData",
219:                                    new Object[] { snapCount, skipCount },
220:                                    new String[] { "java.lang.Integer",
221:                                            "java.lang.Integer" });
222:                }
223:                // Check if snapshotList is empty
224:                if (snapshotList.size() == 0) {
225:                    return snapshotList;
226:                }
227:                /*
228:                 * If there are not enough snapshots available to fill the requested
229:                 * number, insert some with values of 0 and the proper times.
230:                 */
231:                while (snapshotList.size() < snapCount) {
232:                    // Temporary, always is first element (oldest)
233:                    HashMap<String, HashMap<String, Object>> mapTimeFix = snapshotList
234:                            .get(0);
235:
236:                    // Temporary map, used to generate blank data to be added to
237:                    // the
238:                    // list at position 0
239:                    HashMap<String, HashMap<String, Object>> tempMap = new HashMap<String, HashMap<String, Object>>();
240:
241:                    // Temporary submap, used to store 0 elements to be added to
242:                    // the
243:                    // tempmap
244:                    HashMap<String, Object> subMap = new HashMap<String, Object>();
245:
246:                    // Calculate appropriate time, add it to the submap, then
247:                    // add
248:                    // that to the tempMap
249:                    subMap
250:                            .put(
251:                                    "snapshot_time",
252:                                    ((Long) mapTimeFix.get("times").get(
253:                                            "snapshot_time") - (getSnapshotDuration() * skipCount)));
254:                    Format formatter = null;
255:                    formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
256:                    Date date = new Date((Long) subMap.get("snapshot_time"));
257:                    subMap.put("snapshot_date", formatter.format(date));
258:
259:                    // Add the submap back to the tempmap
260:                    tempMap.put("times", new HashMap<String, Object>(subMap));
261:
262:                    // Clear out the subMap for use again
263:                    subMap.clear();
264:
265:                    // Run through the mbeans
266:
267:                    // Run through the mbeans
268:                    for (Iterator<String> it = mapTimeFix.keySet().iterator(); it
269:                            .hasNext();) {
270:                        // get the mbean name
271:                        String mbeanName = it.next();
272:                        HashMap<String, Object> stats = null;
273:                        // Verify that it's not times
274:
275:                        if (mbeanName.equals(new String("times"))) {
276:
277:                        } else {
278:                            stats = mapTimeFix.get(mbeanName);
279:                            // Run through the stats elements for the particular
280:                            // mbean
281:                            for (Iterator<String> itt = stats.keySet()
282:                                    .iterator(); itt.hasNext();) {
283:                                String key = itt.next();
284:                                // Place faux data into the submap
285:                                subMap.put(key, new Long(0));
286:                            }
287:                            // Add the submap to the tempmap, and clear it
288:                            tempMap.put(mbeanName, new HashMap<String, Object>(
289:                                    subMap));
290:                        }
291:                    }
292:                    snapshotList.add(0,
293:                            new HashMap<String, HashMap<String, Object>>(
294:                                    tempMap));
295:                }
296:
297:                /*
298:                 * This is where we will be inserting data to fill 'gaps' in the
299:                 * snapshots The initial for-loop will travel from the most recent
300:                 * snapshot to the oldest, checking that the snapshot_time along the way
301:                 * all align with what they should be
302:                 */
303:                for (int i = snapshotList.size() - 1; i > 0; i--) {
304:                    if (i > 0) {
305:                        HashMap<String, HashMap<String, Object>> mapTimeFix = snapshotList
306:                                .get(i);
307:                        HashMap<String, HashMap<String, Object>> mapTimeFix2 = snapshotList
308:                                .get(i - 1);
309:                        // here is where we will in missing data
310:                        while (((((Long) mapTimeFix.get("times").get(
311:                                "snapshot_time") / 1000) / 60)
312:                                - (((Long) mapTimeFix2.get("times").get(
313:                                        "snapshot_time") / 1000) / 60) > (((getSnapshotDuration() / 1000) / 60) * skipCount))) {
314:                            HashMap<String, HashMap<String, Object>> tempMap = new HashMap<String, HashMap<String, Object>>();
315:                            HashMap<String, Object> subMap = new HashMap<String, Object>();
316:
317:                            for (Iterator<String> it = mapTimeFix.keySet()
318:                                    .iterator(); it.hasNext();) {
319:                                // get the mbean name
320:                                String mbeanName = it.next();
321:                                HashMap<String, Object> stats = null;
322:                                // Verify that it's not times
323:                                if (!mbeanName.equals("times")) {
324:                                    stats = mapTimeFix.get(mbeanName);
325:                                    // Run through the stats elements for the
326:                                    // particular
327:                                    // mbean
328:                                    for (Iterator<String> itt = stats.keySet()
329:                                            .iterator(); itt.hasNext();) {
330:                                        String key = itt.next();
331:                                        // Place faux data into the submap
332:                                        subMap.put(key, new Long(0));
333:                                    }
334:                                    // Add the submap to the tempmap, and clear it
335:                                    tempMap
336:                                            .put(
337:                                                    mbeanName,
338:                                                    new HashMap<String, Object>(
339:                                                            subMap));
340:                                    subMap.clear();
341:                                }
342:                            }
343:
344:                            subMap
345:                                    .put(
346:                                            "snapshot_time",
347:                                            new Long(
348:                                                    (Long) mapTimeFix.get(
349:                                                            "times").get(
350:                                                            "snapshot_time")
351:                                                            - (getSnapshotDuration() * skipCount)));
352:                            Format formatter = null;
353:                            formatter = new SimpleDateFormat(
354:                                    "yyyy-MM-dd HH:mm:ss");
355:                            Date date = new Date((Long) subMap
356:                                    .get("snapshot_time"));
357:                            subMap.put("snapshot_date", formatter.format(date));
358:                            tempMap.put("times", new HashMap<String, Object>(
359:                                    subMap));
360:                            subMap.clear();
361:                            snapshotList
362:                                    .add(
363:                                            i,
364:                                            new HashMap<String, HashMap<String, Object>>(
365:                                                    tempMap));
366:                            snapshotList.remove(0);
367:                            mapTimeFix = tempMap;
368:                            mapTimeFix2 = snapshotList.get(i - 1);
369:                        }
370:                    }
371:                }
372:                return snapshotList;
373:            }
374:
375:            @SuppressWarnings("unchecked")
376:            public TreeMap<Long, Long> getSpecificStatistics(String mbeanName,
377:                    String statsName, int snapCount, int skipCount,
378:                    boolean showArchive) throws Exception {
379:                TreeMap<Long, Long> snapshotList = null;
380:                if (Protocol == 1) {
381:
382:                    snapshotList = mrc.getSpecificStatistics(mbeanName,
383:                            statsName, snapCount, skipCount, showArchive);
384:
385:                } else {
386:                    snapshotList = (TreeMap<Long, Long>) mbServerConn.invoke(
387:                            new ObjectName(PATH), "getSpecificStatistics",
388:                            new Object[] { mbeanName, statsName, snapCount,
389:                                    skipCount, showArchive }, new String[] {
390:                                    "java.lang.String", "java.lang.String",
391:                                    "java.lang.Integer", "java.lang.Integer",
392:                                    "java.lang.Boolean" });
393:
394:                }
395:                // Check if snapshotList is empty
396:                if (snapshotList.size() == 0) {
397:                    return snapshotList;
398:                }
399:                /*
400:                 * If there are not enough snapshots available to fill the requested
401:                 * number, insert some with values of 0 and the proper times.
402:                 */
403:                while (snapshotList.size() < snapCount) {
404:                    // Temporary, always is first element (oldest)
405:                    Long timeFix = snapshotList.firstKey();
406:
407:                    // Calculate appropriate time, add it to the submap, then
408:                    // add
409:                    // that to the tempMap
410:                    snapshotList.put(
411:                            (timeFix - (getSnapshotDuration() * skipCount)),
412:                            new Long(0));
413:                }
414:
415:                /*
416:                 * This is where we will be inserting data to fill 'gaps' in the
417:                 * snapshots The initial for-loop will travel from the most recent
418:                 * snapshot to the oldest, checking that the snapshot_time along the way
419:                 * all align with what they should be
420:                 */
421:                Set tempSet = snapshotList.keySet();
422:                ArrayList<Long> tempArray = new ArrayList(tempSet);
423:
424:                for (int i = tempArray.size() - 1; i > 0; i--) {
425:                    Long tempLong1 = tempArray.get(i);
426:                    Long tempLong2 = tempArray.get(i - 1);
427:                    // here is where we will in missing data
428:                    while ((((tempLong1 / 1000) / 60)
429:                            - ((tempLong2 / 1000) / 60) > (((getSnapshotDuration() / 1000) / 60) * skipCount))
430:                            && i > 0) {
431:                        tempLong1 = tempLong1
432:                                - (getSnapshotDuration() * skipCount);
433:                        snapshotList.remove(tempArray.get(0));
434:                        snapshotList.put(tempLong1, new Long(0));
435:                        tempArray.remove(0);
436:                        i--;
437:                    }
438:                }
439:                return snapshotList;
440:            }
441:
442:            @SuppressWarnings("unchecked")
443:            public HashMap<String, HashMap<String, Object>> getLatestSnapshots()
444:                    throws Exception {
445:                int snapCount = 1;
446:                int skipCount = 1;
447:                ArrayList<HashMap<String, HashMap<String, Object>>> snapshotList = null;
448:                if (Protocol == 1) {
449:
450:                    snapshotList = mrc.fetchSnapshotData(snapCount, skipCount);
451:
452:                } else {
453:                    snapshotList = (ArrayList<HashMap<String, HashMap<String, Object>>>) mbServerConn
454:                            .invoke(new ObjectName(PATH), "fetchSnapshotData",
455:                                    new Object[] { snapCount, skipCount },
456:                                    new String[] { "java.lang.Integer",
457:                                            "java.lang.Integer" });
458:                }
459:                // Check if snapshotList is empty
460:                if (snapshotList.size() == 0) {
461:                    return null;
462:                } else
463:                    return snapshotList.get(0);
464:            }
465:
466:            /**
467:             * @return - Returns a boolean indicating successful stop
468:             * @throws Exception -
469:             *             If the connection to the MRC-Server fails
470:             */
471:            public boolean stopSnapshotThread() throws Exception {
472:                if (Protocol == 1) {
473:
474:                    return mrc.stopSnapshot();
475:
476:                } else {
477:                    return (Boolean) mbServerConn.invoke(new ObjectName(PATH),
478:                            "stopSnapshot", new Object[] {}, new String[] {});
479:                }
480:            }
481:
482:            /**
483:             * @return - Returns a boolean indicating successful stop
484:             * @throws Exception -
485:             *             If the connection to the MRC-Server fails
486:             */
487:            public boolean startSnapshotThread(long time) throws Exception {
488:                if (Protocol == 1) {
489:
490:                    return mrc.startSnapshot(time);
491:
492:                } else {
493:                    return (Boolean) mbServerConn.invoke(new ObjectName(PATH),
494:                            "startSnapshot", new Object[] { time },
495:                            new String[] { "java.lang.Long" });
496:                }
497:            }
498:
499:            public int isSnapshotRunning() {
500:                Integer running = 0;
501:                if (Protocol == 1) {
502:
503:                    try {
504:                        if (mrc.isSnapshotRunning())
505:                            running = 1;
506:                    } catch (Exception e) {
507:                        return 0;
508:                    }
509:
510:                } else {
511:                    try {
512:                        running = (Integer) mbServerConn.invoke(new ObjectName(
513:                                PATH), "SnapshotStatus", new Object[] {},
514:                                new String[] {});
515:                    } catch (Exception e) {
516:                        e.printStackTrace();
517:                        return 0;
518:                    }
519:                }
520:                return running;
521:            }
522:
523:            @SuppressWarnings("unchecked")
524:            public Set<String> getAllMbeanNames() throws Exception {
525:                if (Protocol == 1) {
526:
527:                    return mrc.getAllMBeanNames();
528:
529:                } else {
530:                    return (Set<String>) mbServerConn.invoke(new ObjectName(
531:                            PATH), "getAllMBeanNames", new Object[] {},
532:                            new String[] {});
533:                }
534:            }
535:
536:            @SuppressWarnings("unchecked")
537:            public Set<String> getStatisticsProviderBeanNames()
538:                    throws Exception {
539:                if (Protocol == 1) {
540:
541:                    return mrc.getStatisticsProviderMBeanNames();
542:
543:                } else {
544:                    return (Set<String>) mbServerConn.invoke(new ObjectName(
545:                            PATH), "getStatisticsProviderMBeanNames",
546:                            new Object[] {}, new String[] {});
547:                }
548:            }
549:
550:            @SuppressWarnings("unchecked")
551:            public HashMap<String, ArrayList<String>> getAllSnapshotStatAttributes()
552:                    throws Exception {
553:                if (Protocol == 1) {
554:
555:                    return mrc.getAllSnapshotStatAttributes();
556:
557:                } else {
558:                    return (HashMap<String, ArrayList<String>>) mbServerConn
559:                            .invoke(new ObjectName(PATH),
560:                                    "getAllSnapshotStatAttributes",
561:                                    new Object[] {}, new String[] {});
562:                }
563:            }
564:
565:            @SuppressWarnings("unchecked")
566:            public Set<String> getTrackedBeans() throws Exception {
567:                if (Protocol == 1) {
568:
569:                    return mrc.getTrackedMBeans();
570:
571:                } else {
572:                    return (Set<String>) mbServerConn.invoke(new ObjectName(
573:                            PATH), "getTrackedMBeans", new Object[] {},
574:                            new String[] {});
575:                }
576:            }
577:
578:            @SuppressWarnings("unchecked")
579:            public Set<String> getStatAttributesOnMBean(String mBean)
580:                    throws Exception {
581:                HashMap<String, ArrayList<String>> allStatAttributes = getAllSnapshotStatAttributes();
582:                ArrayList<String> tempArrayList = allStatAttributes.get(mBean);
583:                Set<String> tempSet = new TreeSet<String>();
584:                Iterator it = tempArrayList.iterator();
585:                while (it.hasNext()) {
586:                    tempSet.add(it.next().toString());
587:                }
588:                return tempSet;
589:            }
590:
591:            @SuppressWarnings("unchecked")
592:            public Set<String> getTrackedBeansPretty() throws Exception {
593:                Set trackedBeans = getTrackedBeans();
594:                Set prettybeans = new TreeSet();
595:                Iterator it = trackedBeans.iterator();
596:                while (it.hasNext()) {
597:                    String[] temparray1 = it.next().toString().split("name=");
598:                    String[] temparray2 = temparray1[1].split(",");
599:                    String[] temparray3 = temparray2[0].split("/");
600:                    String mbeanName = null;
601:                    if (temparray3.length > 1)
602:                        mbeanName = temparray3[1];
603:                    else
604:                        mbeanName = temparray2[0];
605:                    prettybeans.add(mbeanName);
606:                }
607:                return prettybeans;
608:            }
609:
610:            @SuppressWarnings("unchecked")
611:            public TreeMap<String, String> getTrackedBeansMap()
612:                    throws Exception {
613:                Set trackedBeans = getTrackedBeans();
614:                TreeMap<String, String> beanMap = new TreeMap<String, String>();
615:                Iterator it = trackedBeans.iterator();
616:                while (it.hasNext()) {
617:                    String mbeanName = it.next().toString();
618:                    String[] temparray1 = mbeanName.split("name=");
619:                    String[] temparray2 = temparray1[1].split(",");
620:                    String[] temparray3 = temparray2[0].split("/");
621:                    String mbeanNamePretty = null;
622:                    if (temparray3.length > 1)
623:                        mbeanNamePretty = temparray3[1];
624:                    else
625:                        mbeanNamePretty = temparray2[0];
626:                    beanMap.put(mbeanNamePretty, mbeanName);
627:                }
628:                return beanMap;
629:            }
630:
631:            @SuppressWarnings("unchecked")
632:            public Set<String> getStatisticsProviderBeanNamesPretty()
633:                    throws Exception {
634:                Set availableBeans = getStatisticsProviderBeanNames();
635:                Set prettybeans = new TreeSet();
636:                Iterator it = availableBeans.iterator();
637:                while (it.hasNext()) {
638:                    String[] temparray1 = it.next().toString().split("name=");
639:                    String[] temparray2 = temparray1[1].split(",");
640:                    String[] temparray3 = temparray2[0].split("/");
641:                    String mbeanName = null;
642:                    if (temparray3.length > 1)
643:                        mbeanName = temparray3[1];
644:                    else
645:                        mbeanName = temparray2[0];
646:                    prettybeans.add(mbeanName);
647:                }
648:                return prettybeans;
649:            }
650:
651:            @SuppressWarnings("unchecked")
652:            public TreeMap<String, String> getStatisticsProviderBeanNamesMap()
653:                    throws Exception {
654:                Set availableBeans = getStatisticsProviderBeanNames();
655:                TreeMap<String, String> beanMap = new TreeMap<String, String>();
656:                Iterator it = availableBeans.iterator();
657:                while (it.hasNext()) {
658:                    String mbeanName = it.next().toString();
659:                    String[] temparray1 = mbeanName.split("name=");
660:                    String[] temparray2 = temparray1[1].split(",");
661:                    String[] temparray3 = temparray2[0].split("/");
662:                    String mbeanNamePretty = null;
663:                    if (temparray3.length > 1)
664:                        mbeanNamePretty = temparray3[1];
665:                    else
666:                        mbeanNamePretty = temparray2[0];
667:                    beanMap.put(mbeanNamePretty, mbeanName);
668:                }
669:                return beanMap;
670:            }
671:
672:            @SuppressWarnings("unchecked")
673:            public Set<String> getFreeStatisticsProviderBeanNamesPretty()
674:                    throws Exception {
675:                Set<String> availableBeans = getStatisticsProviderBeanNamesPretty();
676:                Set<String> usedBeans = getTrackedBeansPretty();
677:                Set freeBeans = new TreeSet();
678:                Iterator it = availableBeans.iterator();
679:                while (it.hasNext()) {
680:                    String mbeanName = it.next().toString();
681:                    if (!usedBeans.contains(mbeanName))
682:                        freeBeans.add(mbeanName);
683:                }
684:                return freeBeans;
685:            }
686:
687:            @SuppressWarnings("unchecked")
688:            public Set<String> getFreeStatisticsProviderBeanNames()
689:                    throws Exception {
690:                Set<String> availableBeans = getStatisticsProviderBeanNames();
691:                Set<String> usedBeans = getTrackedBeansPretty();
692:                Set freeBeans = new TreeSet();
693:                Iterator it = availableBeans.iterator();
694:                while (it.hasNext()) {
695:                    String mbeanName = it.next().toString();
696:                    String[] temparray1 = mbeanName.split("name=");
697:                    String[] temparray2 = temparray1[1].split(",");
698:                    String[] temparray3 = temparray2[0].split("/");
699:                    String mbeanNamePretty = null;
700:                    if (temparray3.length > 1)
701:                        mbeanNamePretty = temparray3[1];
702:                    else
703:                        mbeanNamePretty = temparray2[0];
704:                    if (!usedBeans.contains(mbeanNamePretty))
705:                        freeBeans.add(mbeanName);
706:                }
707:                return freeBeans;
708:            }
709:
710:            @SuppressWarnings("unchecked")
711:            public TreeMap<String, String> getFreeStatisticsProviderBeanNamesMap()
712:                    throws Exception {
713:                Set<String> availableBeans = getStatisticsProviderBeanNames();
714:                Set<String> usedBeans = getTrackedBeansPretty();
715:                TreeMap<String, String> beanMap = new TreeMap<String, String>();
716:                Iterator it = availableBeans.iterator();
717:                while (it.hasNext()) {
718:                    String mbeanName = it.next().toString();
719:                    String[] temparray1 = mbeanName.split("name=");
720:                    String[] temparray2 = temparray1[1].split(",");
721:                    String[] temparray3 = temparray2[0].split("/");
722:                    String mbeanNamePretty = null;
723:                    if (temparray3.length > 1)
724:                        mbeanNamePretty = temparray3[1];
725:                    else
726:                        mbeanNamePretty = temparray2[0];
727:                    if (!usedBeans.contains(mbeanNamePretty))
728:                        beanMap.put(mbeanNamePretty, mbeanName);
729:                }
730:                return beanMap;
731:            }
732:
733:            @SuppressWarnings("unchecked")
734:            public boolean stopTrackingMbean(String MBean) throws Exception {
735:                if (Protocol == 1) {
736:
737:                    mrc.removeMBeanForSnapshot(MBean);
738:
739:                } else {
740:                    mbServerConn.invoke(new ObjectName(PATH),
741:                            "removeMBeanForSnapshot", new Object[] { MBean },
742:                            new String[] { "java.lang.String" });
743:
744:                }
745:                return true;
746:            }
747:
748:            @SuppressWarnings("unchecked")
749:            public boolean startTrackingMbean(String MBean) throws Exception {
750:                if (Protocol == 1) {
751:
752:                    mrc.addMBeanForSnapshot(MBean);
753:
754:                } else {
755:                    mbServerConn.invoke(new ObjectName(PATH),
756:                            "addMBeanForSnapshot", new Object[] { MBean },
757:                            new String[] { "java.lang.String" });
758:                }
759:                return true;
760:            }
761:
762:            @SuppressWarnings("unchecked")
763:            public HashMap<String, Long> getStats(String MBean)
764:                    throws Exception {
765:                if (Protocol == 1) {
766:
767:                    return mrc.getStats(MBean);
768:
769:                } else {
770:                    return (HashMap<String, Long>) mbServerConn.invoke(
771:                            new ObjectName(PATH), "getStats",
772:                            new Object[] { MBean },
773:                            new String[] { "java.lang.String" });
774:                }
775:            }
776:
777:            public void setSnapshotDuration(long duration) {
778:                if (Protocol == 1) {
779:
780:                    mrc.setSnapshotDuration(new Long(duration));
781:
782:                } else {
783:                    try {
784:
785:                        mbServerConn.invoke(new ObjectName(PATH),
786:                                "setSnapshotDuration", new Object[] { new Long(
787:                                        duration) },
788:                                new String[] { "java.lang.Long" });
789:                    } catch (Exception e) {
790:                        e.printStackTrace();
791:                    }
792:                }
793:            }
794:
795:            public int getSnapshotRetention() {
796:                if (Protocol == 1) {
797:
798:                    return Integer.parseInt(mrc.getSnapshotRetention());
799:
800:                } else {
801:                    try {
802:                        return (Integer) mbServerConn.invoke(new ObjectName(
803:                                PATH), "getSnapshotRetention", new Object[] {},
804:                                new String[] {});
805:                    } catch (Exception e) {
806:                        e.printStackTrace();
807:                    }
808:                }
809:                return 0;
810:            }
811:
812:            public void setSnapshotRetention(int duration) {
813:                if (Protocol == 1) {
814:
815:                    mrc.setSnapshotRetention(duration);
816:
817:                } else {
818:                    try {
819:                        mbServerConn.invoke(new ObjectName(PATH),
820:                                "setSnapshotRetention",
821:                                new Object[] { duration },
822:                                new String[] { "java.lang.Integer" });
823:                    } catch (Exception e) {
824:                        e.printStackTrace();
825:                    }
826:                }
827:            }
828:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.