1 /*
2 * Copyright (c) 2011, 2014, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.management;
27
28 import com.sun.management.GarbageCollectionNotificationInfo;
29 import com.sun.management.GcInfo;
30 import java.lang.reflect.Method;
31 import javax.management.openmbean.CompositeData;
32 import javax.management.openmbean.CompositeType;
33 import javax.management.openmbean.CompositeDataSupport;
34 import javax.management.openmbean.OpenDataException;
35 import javax.management.openmbean.OpenType;
36 import javax.management.openmbean.SimpleType;
37 import java.security.AccessController;
38 import java.security.PrivilegedAction;
39 import java.lang.reflect.Field;
40 import java.util.HashMap;
41
42 /**
43 * A CompositeData for GarbageCollectionNotificationInfo for the local management support.
44 * This class avoids the performance penalty paid to the
45 * construction of a CompositeData use in the local case.
46 */
47 public class GarbageCollectionNotifInfoCompositeData extends LazyCompositeData {
48 private final GarbageCollectionNotificationInfo gcNotifInfo;
49
50 public GarbageCollectionNotifInfoCompositeData(GarbageCollectionNotificationInfo info) {
51 this.gcNotifInfo = info;
52 }
53
54 public GarbageCollectionNotificationInfo getGarbageCollectionNotifInfo() {
55 return gcNotifInfo;
56 }
57
58 public static CompositeData toCompositeData(GarbageCollectionNotificationInfo info) {
59 GarbageCollectionNotifInfoCompositeData gcnicd =
60 new GarbageCollectionNotifInfoCompositeData(info);
78 synchronized(compositeTypeByBuilder) {
79 gict = compositeTypeByBuilder.get(builder);
80 if(gict == null) {
81 OpenType<?>[] gcNotifInfoItemTypes = new OpenType<?>[] {
82 SimpleType.STRING,
83 SimpleType.STRING,
84 SimpleType.STRING,
85 builder.getGcInfoCompositeType(),
86 };
87 try {
88 final String typeName =
89 "sun.management.GarbageCollectionNotifInfoCompositeType";
90 gict = new CompositeType(typeName,
91 "CompositeType for GC notification info",
92 gcNotifInfoItemNames,
93 gcNotifInfoItemNames,
94 gcNotifInfoItemTypes);
95 compositeTypeByBuilder.put(builder,gict);
96 } catch (OpenDataException e) {
97 // shouldn't reach here
98 throw Util.newException(e);
99 }
100 }
101 }
102 return gict;
103 }
104
105 protected CompositeData getCompositeData() {
106 // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
107 // gcNotifInfoItemNames!
108 final Object[] gcNotifInfoItemValues;
109 gcNotifInfoItemValues = new Object[] {
110 gcNotifInfo.getGcName(),
111 gcNotifInfo.getGcAction(),
112 gcNotifInfo.getGcCause(),
113 GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
114 };
115
116 CompositeType gict = getCompositeTypeByBuilder();
117
118 try {
188
189 // This is only used for validation.
190 private static CompositeType baseGcNotifInfoCompositeType = null;
191 private static synchronized CompositeType getBaseGcNotifInfoCompositeType() {
192 if (baseGcNotifInfoCompositeType == null) {
193 try {
194 OpenType<?>[] baseGcNotifInfoItemTypes = new OpenType<?>[] {
195 SimpleType.STRING,
196 SimpleType.STRING,
197 SimpleType.STRING,
198 GcInfoCompositeData.getBaseGcInfoCompositeType()
199 };
200 baseGcNotifInfoCompositeType =
201 new CompositeType("sun.management.BaseGarbageCollectionNotifInfoCompositeType",
202 "CompositeType for Base GarbageCollectionNotificationInfo",
203 gcNotifInfoItemNames,
204 gcNotifInfoItemNames,
205 baseGcNotifInfoItemTypes);
206 } catch (OpenDataException e) {
207 // shouldn't reach here
208 throw Util.newException(e);
209 }
210 }
211 return baseGcNotifInfoCompositeType;
212 }
213
214 private static final long serialVersionUID = -1805123446483771292L;
215 }
|
1 /*
2 * Copyright (c) 2011, 2015, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.management.internal;
27
28 import com.sun.management.GarbageCollectionNotificationInfo;
29 import com.sun.management.GcInfo;
30 import javax.management.openmbean.CompositeData;
31 import javax.management.openmbean.CompositeType;
32 import javax.management.openmbean.CompositeDataSupport;
33 import javax.management.openmbean.OpenDataException;
34 import javax.management.openmbean.OpenType;
35 import javax.management.openmbean.SimpleType;
36 import java.security.AccessController;
37 import java.security.PrivilegedAction;
38 import java.lang.reflect.Field;
39 import java.util.HashMap;
40 import sun.management.LazyCompositeData;
41 import static sun.management.LazyCompositeData.getString;
42 import sun.management.Util;
43
44 /**
45 * A CompositeData for GarbageCollectionNotificationInfo for the local management support.
46 * This class avoids the performance penalty paid to the
47 * construction of a CompositeData use in the local case.
48 */
49 public class GarbageCollectionNotifInfoCompositeData extends LazyCompositeData {
50 private final GarbageCollectionNotificationInfo gcNotifInfo;
51
52 public GarbageCollectionNotifInfoCompositeData(GarbageCollectionNotificationInfo info) {
53 this.gcNotifInfo = info;
54 }
55
56 public GarbageCollectionNotificationInfo getGarbageCollectionNotifInfo() {
57 return gcNotifInfo;
58 }
59
60 public static CompositeData toCompositeData(GarbageCollectionNotificationInfo info) {
61 GarbageCollectionNotifInfoCompositeData gcnicd =
62 new GarbageCollectionNotifInfoCompositeData(info);
80 synchronized(compositeTypeByBuilder) {
81 gict = compositeTypeByBuilder.get(builder);
82 if(gict == null) {
83 OpenType<?>[] gcNotifInfoItemTypes = new OpenType<?>[] {
84 SimpleType.STRING,
85 SimpleType.STRING,
86 SimpleType.STRING,
87 builder.getGcInfoCompositeType(),
88 };
89 try {
90 final String typeName =
91 "sun.management.GarbageCollectionNotifInfoCompositeType";
92 gict = new CompositeType(typeName,
93 "CompositeType for GC notification info",
94 gcNotifInfoItemNames,
95 gcNotifInfoItemNames,
96 gcNotifInfoItemTypes);
97 compositeTypeByBuilder.put(builder,gict);
98 } catch (OpenDataException e) {
99 // shouldn't reach here
100 throw new RuntimeException(e);
101 }
102 }
103 }
104 return gict;
105 }
106
107 protected CompositeData getCompositeData() {
108 // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
109 // gcNotifInfoItemNames!
110 final Object[] gcNotifInfoItemValues;
111 gcNotifInfoItemValues = new Object[] {
112 gcNotifInfo.getGcName(),
113 gcNotifInfo.getGcAction(),
114 gcNotifInfo.getGcCause(),
115 GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
116 };
117
118 CompositeType gict = getCompositeTypeByBuilder();
119
120 try {
190
191 // This is only used for validation.
192 private static CompositeType baseGcNotifInfoCompositeType = null;
193 private static synchronized CompositeType getBaseGcNotifInfoCompositeType() {
194 if (baseGcNotifInfoCompositeType == null) {
195 try {
196 OpenType<?>[] baseGcNotifInfoItemTypes = new OpenType<?>[] {
197 SimpleType.STRING,
198 SimpleType.STRING,
199 SimpleType.STRING,
200 GcInfoCompositeData.getBaseGcInfoCompositeType()
201 };
202 baseGcNotifInfoCompositeType =
203 new CompositeType("sun.management.BaseGarbageCollectionNotifInfoCompositeType",
204 "CompositeType for Base GarbageCollectionNotificationInfo",
205 gcNotifInfoItemNames,
206 gcNotifInfoItemNames,
207 baseGcNotifInfoItemTypes);
208 } catch (OpenDataException e) {
209 // shouldn't reach here
210 throw new RuntimeException(e);
211 }
212 }
213 return baseGcNotifInfoCompositeType;
214 }
215
216 private static final long serialVersionUID = -1805123446483771292L;
217 }
|