1 /*
2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 package nsk.monitoring.share.direct;
25 
26 import java.lang.management.*;
27 import javax.management.*;
28 import nsk.monitoring.share.*;
29 import java.util.List;
30 import java.lang.reflect.Method;
31 
32 /**
33  * This is MonitoringFactory implementation, which obtains
34  * MXBeans directly from ManagementFactory.
35  *
36  * @see nsk.monitoring.share.MonitoringFactory
37  */
38 public class DirectMonitoringFactory implements MonitoringFactory {
getClassLoadingMXBean()39         public ClassLoadingMXBean getClassLoadingMXBean() {
40                 return ManagementFactory.getClassLoadingMXBean();
41         }
42 
hasCompilationMXBean()43         public boolean hasCompilationMXBean() {
44                 return ManagementFactory.getCompilationMXBean() != null;
45         }
46 
getCompilationMXBean()47         public CompilationMXBean getCompilationMXBean() {
48                 return ManagementFactory.getCompilationMXBean();
49         }
50 
getGarbageCollectorMXBeans()51         public List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
52                 return ManagementFactory.getGarbageCollectorMXBeans();
53         }
54 
getRuntimeMXBean()55         public RuntimeMXBean getRuntimeMXBean() {
56                 return ManagementFactory.getRuntimeMXBean();
57         }
58 
getMemoryMXBean()59         public MemoryMXBean getMemoryMXBean() {
60                 return ManagementFactory.getMemoryMXBean();
61         }
62 
getMemoryMXBeanNotificationEmitter()63         public NotificationEmitter getMemoryMXBeanNotificationEmitter() {
64                 return (NotificationEmitter) ManagementFactory.getMemoryMXBean();
65         }
66 
getMemoryPoolMXBeans()67         public List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
68                 return ManagementFactory.getMemoryPoolMXBeans();
69         }
70 
getThreadMXBean()71         public ThreadMXBean getThreadMXBean() {
72                 return ManagementFactory.getThreadMXBean();
73         }
74 
hasThreadMXBeanNew()75         public boolean hasThreadMXBeanNew() {
76             boolean supported = false;
77             Class cl = ManagementFactory.getThreadMXBean().getClass();
78             Method[] methods = cl.getDeclaredMethods();
79             for (int i = 0; i < methods.length; i++ ) {
80                 if (methods[i].getName().equals("isThreadAllocatedMemorySupported")) {
81                     supported = true;
82                     break;
83                 }
84             }
85             return supported;
86         }
87 
getThreadMXBeanNew()88         public ThreadMXBean getThreadMXBeanNew() {
89             return getThreadMXBean();
90         }
91         /*
92         public OperatingSystemMXBean getOperatingSystemMXBean() {
93                 return ManagementFactory.getOperatingSystemMXBean();
94         }
95 
96         */
97 }
98