This commit is contained in:
Abhijit Saha 2009-10-30 07:58:03 -07:00
commit 0456a42631
35 changed files with 936 additions and 144 deletions

View File

@ -99,7 +99,7 @@ public class ObjectStreamClass implements Serializable {
}
/** class associated with this descriptor (if any) */
private Class cl;
private Class<?> cl;
/** name of class represented by this descriptor */
private String name;
/** serialVersionUID of represented class (null if not computed yet) */
@ -276,7 +276,7 @@ public class ObjectStreamClass implements Serializable {
* @param all if true, return descriptors for all classes; if false, only
* return descriptors for serializable classes
*/
static ObjectStreamClass lookup(Class cl, boolean all) {
static ObjectStreamClass lookup(Class<?> cl, boolean all) {
if (!(all || Serializable.class.isAssignableFrom(cl))) {
return null;
}
@ -414,7 +414,7 @@ public class ObjectStreamClass implements Serializable {
/**
* Creates local class descriptor representing given class.
*/
private ObjectStreamClass(final Class cl) {
private ObjectStreamClass(final Class<?> cl) {
this.cl = cl;
name = cl.getName();
isProxy = Proxy.isProxyClass(cl);
@ -422,7 +422,7 @@ public class ObjectStreamClass implements Serializable {
serializable = Serializable.class.isAssignableFrom(cl);
externalizable = Externalizable.class.isAssignableFrom(cl);
Class superCl = cl.getSuperclass();
Class<?> superCl = cl.getSuperclass();
superDesc = (superCl != null) ? lookup(superCl, false) : null;
localDesc = this;
@ -453,10 +453,10 @@ public class ObjectStreamClass implements Serializable {
} else {
cons = getSerializableConstructor(cl);
writeObjectMethod = getPrivateMethod(cl, "writeObject",
new Class[] { ObjectOutputStream.class },
new Class<?>[] { ObjectOutputStream.class },
Void.TYPE);
readObjectMethod = getPrivateMethod(cl, "readObject",
new Class[] { ObjectInputStream.class },
new Class<?>[] { ObjectInputStream.class },
Void.TYPE);
readObjectNoDataMethod = getPrivateMethod(
cl, "readObjectNoData", null, Void.TYPE);
@ -507,7 +507,7 @@ public class ObjectStreamClass implements Serializable {
/**
* Initializes class descriptor representing a proxy class.
*/
void initProxy(Class cl,
void initProxy(Class<?> cl,
ClassNotFoundException resolveEx,
ObjectStreamClass superDesc)
throws InvalidClassException
@ -540,7 +540,7 @@ public class ObjectStreamClass implements Serializable {
* Initializes class descriptor representing a non-proxy class.
*/
void initNonProxy(ObjectStreamClass model,
Class cl,
Class<?> cl,
ClassNotFoundException resolveEx,
ObjectStreamClass superDesc)
throws InvalidClassException
@ -1131,7 +1131,7 @@ public class ObjectStreamClass implements Serializable {
throws InvalidClassException
{
ArrayList<ClassDataSlot> slots = new ArrayList<ClassDataSlot>();
Class start = cl, end = cl;
Class<?> start = cl, end = cl;
// locate closest non-serializable superclass
while (end != null && Serializable.class.isAssignableFrom(end)) {
@ -1142,8 +1142,8 @@ public class ObjectStreamClass implements Serializable {
// search up inheritance hierarchy for class with matching name
String searchName = (d.cl != null) ? d.cl.getName() : d.name;
Class match = null;
for (Class c = start; c != end; c = c.getSuperclass()) {
Class<?> match = null;
for (Class<?> c = start; c != end; c = c.getSuperclass()) {
if (searchName.equals(c.getName())) {
match = c;
break;
@ -1152,7 +1152,7 @@ public class ObjectStreamClass implements Serializable {
// add "no data" slot for each unmatched class below match
if (match != null) {
for (Class c = start; c != match; c = c.getSuperclass()) {
for (Class<?> c = start; c != match; c = c.getSuperclass()) {
slots.add(new ClassDataSlot(
ObjectStreamClass.lookup(c, true), false));
}
@ -1164,7 +1164,7 @@ public class ObjectStreamClass implements Serializable {
}
// add "no data" slot for any leftover unmatched classes
for (Class c = start; c != end; c = c.getSuperclass()) {
for (Class<?> c = start; c != end; c = c.getSuperclass()) {
slots.add(new ClassDataSlot(
ObjectStreamClass.lookup(c, true), false));
}
@ -1288,7 +1288,7 @@ public class ObjectStreamClass implements Serializable {
* descriptor, returns reference to this class descriptor. Otherwise,
* returns variant of this class descriptor bound to given class.
*/
private ObjectStreamClass getVariantFor(Class cl)
private ObjectStreamClass getVariantFor(Class<?> cl)
throws InvalidClassException
{
if (this.cl == cl) {
@ -1355,8 +1355,8 @@ public class ObjectStreamClass implements Serializable {
* method (if any).
*/
private static Method getInheritableMethod(Class<?> cl, String name,
Class[] argTypes,
Class returnType)
Class<?>[] argTypes,
Class<?> returnType)
{
Method meth = null;
Class<?> defCl = cl;
@ -1410,7 +1410,7 @@ public class ObjectStreamClass implements Serializable {
* Returns true if classes are defined in the same runtime package, false
* otherwise.
*/
private static boolean packageEquals(Class cl1, Class cl2) {
private static boolean packageEquals(Class<?> cl1, Class<?> cl2) {
return (cl1.getClassLoader() == cl2.getClassLoader() &&
getPackageName(cl1).equals(getPackageName(cl2)));
}
@ -1418,7 +1418,7 @@ public class ObjectStreamClass implements Serializable {
/**
* Returns package name of given class.
*/
private static String getPackageName(Class cl) {
private static String getPackageName(Class<?> cl) {
String s = cl.getName();
int i = s.lastIndexOf('[');
if (i >= 0) {
@ -1441,7 +1441,7 @@ public class ObjectStreamClass implements Serializable {
/**
* Returns JVM type signature for given class.
*/
static String getClassSignature(Class cl) {
private static String getClassSignature(Class<?> cl) {
StringBuilder sbuf = new StringBuilder();
while (cl.isArray()) {
sbuf.append('[');
@ -1478,8 +1478,8 @@ public class ObjectStreamClass implements Serializable {
/**
* Returns JVM type signature for given list of parameters and return type.
*/
private static String getMethodSignature(Class[] paramTypes,
Class retType)
private static String getMethodSignature(Class<?>[] paramTypes,
Class<?> retType)
{
StringBuilder sbuf = new StringBuilder();
sbuf.append('(');
@ -1515,7 +1515,7 @@ public class ObjectStreamClass implements Serializable {
* Field objects. Throws InvalidClassException if the (explicitly
* declared) serializable fields are invalid.
*/
private static ObjectStreamField[] getSerialFields(Class cl)
private static ObjectStreamField[] getSerialFields(Class<?> cl)
throws InvalidClassException
{
ObjectStreamField[] fields;
@ -1545,7 +1545,7 @@ public class ObjectStreamClass implements Serializable {
* InvalidClassException if the declared serializable fields are
* invalid--e.g., if multiple fields share the same name.
*/
private static ObjectStreamField[] getDeclaredSerialFields(Class cl)
private static ObjectStreamField[] getDeclaredSerialFields(Class<?> cl)
throws InvalidClassException
{
ObjectStreamField[] serialPersistentFields = null;
@ -1602,7 +1602,7 @@ public class ObjectStreamClass implements Serializable {
* contains a Field object for the field it represents. If no default
* serializable fields exist, NO_FIELDS is returned.
*/
private static ObjectStreamField[] getDefaultSerialFields(Class cl) {
private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) {
Field[] clFields = cl.getDeclaredFields();
ArrayList<ObjectStreamField> list = new ArrayList<ObjectStreamField>();
int mask = Modifier.STATIC | Modifier.TRANSIENT;
@ -1621,7 +1621,7 @@ public class ObjectStreamClass implements Serializable {
* Returns explicit serial version UID value declared by given class, or
* null if none.
*/
private static Long getDeclaredSUID(Class cl) {
private static Long getDeclaredSUID(Class<?> cl) {
try {
Field f = cl.getDeclaredField("serialVersionUID");
int mask = Modifier.STATIC | Modifier.FINAL;
@ -1637,7 +1637,7 @@ public class ObjectStreamClass implements Serializable {
/**
* Computes the default serial version UID value for the given class.
*/
private static long computeDefaultSUID(Class cl) {
private static long computeDefaultSUID(Class<?> cl) {
if (!Serializable.class.isAssignableFrom(cl) || Proxy.isProxyClass(cl))
{
return 0L;
@ -1671,7 +1671,7 @@ public class ObjectStreamClass implements Serializable {
* Class.getInterfaces() was modified to return Cloneable and
* Serializable for array classes.
*/
Class[] interfaces = cl.getInterfaces();
Class<?>[] interfaces = cl.getInterfaces();
String[] ifaceNames = new String[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
ifaceNames[i] = interfaces[i].getName();
@ -1784,7 +1784,7 @@ public class ObjectStreamClass implements Serializable {
* Returns true if the given class defines a static initializer method,
* false otherwise.
*/
private native static boolean hasStaticInitializer(Class cl);
private native static boolean hasStaticInitializer(Class<?> cl);
/**
* Class for computing and caching field/constructor/method signatures
@ -1837,7 +1837,7 @@ public class ObjectStreamClass implements Serializable {
/** field type codes */
private final char[] typeCodes;
/** field types */
private final Class[] types;
private final Class<?>[] types;
/**
* Constructs FieldReflector capable of setting/getting values from the
@ -2071,7 +2071,7 @@ public class ObjectStreamClass implements Serializable {
throws InvalidClassException
{
// class irrelevant if no fields
Class cl = (localDesc != null && fields.length > 0) ?
Class<?> cl = (localDesc != null && fields.length > 0) ?
localDesc.cl : null;
processQueue(Caches.reflectorsQueue, Caches.reflectors);
FieldReflectorKey key = new FieldReflectorKey(cl, fields,
@ -2136,7 +2136,7 @@ public class ObjectStreamClass implements Serializable {
private final int hash;
private final boolean nullClass;
FieldReflectorKey(Class cl, ObjectStreamField[] fields,
FieldReflectorKey(Class<?> cl, ObjectStreamField[] fields,
ReferenceQueue<Class<?>> queue)
{
super(cl, queue);

View File

@ -45,7 +45,7 @@ public class ObjectStreamField
/** canonical JVM signature of field type */
private final String signature;
/** field type (Object.class if unknown non-primitive type) */
private final Class type;
private final Class<?> type;
/** whether or not to (de)serialize field values as unshared */
private final boolean unshared;
/** corresponding reflective field object, if any */
@ -88,7 +88,7 @@ public class ObjectStreamField
this.name = name;
this.type = type;
this.unshared = unshared;
signature = ObjectStreamClass.getClassSignature(type).intern();
signature = getClassSignature(type).intern();
field = null;
}
@ -132,9 +132,9 @@ public class ObjectStreamField
this.field = field;
this.unshared = unshared;
name = field.getName();
Class ftype = field.getType();
Class<?> ftype = field.getType();
type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
signature = ObjectStreamClass.getClassSignature(ftype).intern();
signature = getClassSignature(ftype).intern();
}
/**
@ -274,4 +274,41 @@ public class ObjectStreamField
String getSignature() {
return signature;
}
/**
* Returns JVM type signature for given class.
*/
private static String getClassSignature(Class<?> cl) {
StringBuilder sbuf = new StringBuilder();
while (cl.isArray()) {
sbuf.append('[');
cl = cl.getComponentType();
}
if (cl.isPrimitive()) {
if (cl == Integer.TYPE) {
sbuf.append('I');
} else if (cl == Byte.TYPE) {
sbuf.append('B');
} else if (cl == Long.TYPE) {
sbuf.append('J');
} else if (cl == Float.TYPE) {
sbuf.append('F');
} else if (cl == Double.TYPE) {
sbuf.append('D');
} else if (cl == Short.TYPE) {
sbuf.append('S');
} else if (cl == Character.TYPE) {
sbuf.append('C');
} else if (cl == Boolean.TYPE) {
sbuf.append('Z');
} else if (cl == Void.TYPE) {
sbuf.append('V');
} else {
throw new InternalError();
}
} else {
sbuf.append('L' + cl.getName().replace('.', '/') + ';');
}
return sbuf.toString();
}
}

View File

@ -30,8 +30,7 @@ import java.util.Collections;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.LoggingMXBean;
import java.util.logging.LogManager;
import java.util.logging.PlatformLoggingMXBean;
import java.nio.BufferPoolMXBean;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
@ -181,15 +180,14 @@ enum PlatformComponent {
* Logging facility.
*/
LOGGING(
"java.util.logging.LoggingMXBean",
"java.util.logging.PlatformLoggingMXBean",
"java.util.logging", "Logging", defaultKeyProperties(),
new MXBeanFetcher<LoggingMXBean>() {
public List<LoggingMXBean> getMXBeans() {
return Collections.singletonList(LogManager.getLoggingMXBean());
new MXBeanFetcher<PlatformLoggingMXBean>() {
public List<PlatformLoggingMXBean> getMXBeans() {
return ManagementFactoryHelper.getLoggingMXBean();
}
}),
/**
* Buffer pools.
*/

View File

@ -1039,12 +1039,16 @@ public class LogManager {
/**
* Returns <tt>LoggingMXBean</tt> for managing loggers.
* The <tt>LoggingMXBean</tt> can also obtained from the
* {@link java.lang.management.ManagementFactory#getPlatformMBeanServer
* platform <tt>MBeanServer</tt>} method.
* An alternative way to manage loggers is using
* the {@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
* ManagementFactory.getPlatformMXBeans} method as follows:
* <pre>
* List&lt{@link PlatformLoggingMXBean}&gt result = ManagementFactory.getPlatformMXBeans(PlatformLoggingMXBean.class);
* </pre>
*
* @return a {@link LoggingMXBean} object.
*
* @see PlatformLoggingMXBean
* @see java.lang.management.ManagementFactory
* @since 1.5
*/

View File

@ -29,9 +29,6 @@ import java.util.Enumeration;
import java.util.List;
import java.util.ArrayList;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
/**
* Logging is the implementation class of LoggingMXBean.
*
@ -117,12 +114,4 @@ class Logging implements LoggingMXBean {
return p.getName();
}
}
public ObjectName getObjectName() {
try {
return ObjectName.getInstance(LogManager.LOGGING_MXBEAN_NAME);
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException(e);
}
}
}

View File

@ -25,7 +25,6 @@
package java.util.logging;
import java.lang.management.PlatformManagedObject;
/**
* The management interface for the logging facility.
@ -35,27 +34,26 @@ import java.lang.management.PlatformManagedObject;
* <a href="../../lang/management/ManagementFactory.html#MXBean">MXBean</a>
* can be obtained by calling
* the {@link LogManager#getLoggingMXBean} method or from the
* {@link java.lang.management.ManagementFactory#getPlatformMBeanServer
* platform <tt>MBeanServer</tt>} method.
* {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
* platform <tt>MBeanServer</tt>}.
*
* <p>The {@link javax.management.ObjectName ObjectName} for uniquely
* The {@link javax.management.ObjectName ObjectName} for uniquely
* identifying the <tt>LoggingMXBean</tt> within an MBeanServer is:
* <blockquote>
* {@link LogManager#LOGGING_MXBEAN_NAME
* <tt>java.util.logging:type=Logging</tt>}
* </blockquote>
*
* It can be obtained by calling the
* {@link PlatformManagedObject#getObjectName} method.
*
* @see java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
* The instance registered in the platform <tt>MBeanServer</tt> with
* this {@code ObjectName} is also a {@link PlatformLoggingMXBean}.
*
* @author Ron Mann
* @author Mandy Chung
* @since 1.5
*
* @see PlatformLoggingMXBean
*/
public interface LoggingMXBean extends PlatformManagedObject {
public interface LoggingMXBean {
/**
* Returns the list of currently registered loggers. This method

View File

@ -0,0 +1,102 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.util.logging;
import sun.util.logging.LoggingProxy;
/**
* Implementation of LoggingProxy when java.util.logging classes exist.
*/
class LoggingProxyImpl implements LoggingProxy {
static final LoggingProxy INSTANCE = new LoggingProxyImpl();
private LoggingProxyImpl() { }
@Override
public Object getLogger(String name) {
return Logger.getLogger(name);
}
@Override
public Object getLevel(Object logger) {
return ((Logger) logger).getLevel();
}
@Override
public void setLevel(Object logger, Object newLevel) {
((Logger) logger).setLevel((Level) newLevel);
}
@Override
public boolean isLoggable(Object logger, Object level) {
return ((Logger) logger).isLoggable((Level) level);
}
@Override
public void log(Object logger, Object level, String msg) {
((Logger) logger).log((Level) level, msg);
}
@Override
public void log(Object logger, Object level, String msg, Throwable t) {
((Logger) logger).log((Level) level, msg, t);
}
@Override
public void log(Object logger, Object level, String msg, Object... params) {
((Logger) logger).log((Level) level, msg, params);
}
@Override
public java.util.List<String> getLoggerNames() {
return LogManager.getLoggingMXBean().getLoggerNames();
}
@Override
public String getLoggerLevel(String loggerName) {
return LogManager.getLoggingMXBean().getLoggerLevel(loggerName);
}
@Override
public void setLoggerLevel(String loggerName, String levelName) {
LogManager.getLoggingMXBean().setLoggerLevel(loggerName, levelName);
}
@Override
public String getParentLoggerName(String loggerName) {
return LogManager.getLoggingMXBean().getParentLoggerName(loggerName);
}
@Override
public Object parseLevel(String levelName) {
return Level.parse(levelName);
}
@Override
public String getLevelName(Object level) {
return ((Level) level).getName();
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.util.logging;
import java.lang.management.PlatformManagedObject;
/**
* The {@linkplain PlatformManagedObject platform managed object} for the
* logging facility. This interface simply unifies {@link LoggingMXBean}
* {@link PlatformManagedObject};
* and it does not specify any new operations.
*
* <p>The {@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
* ManagementFactory.getPlatformMXBeans} method can be used to obtain
* the {@code PlatformLoggingMXBean} object as follows:
* <pre>
* ManagementFactory.getPlatformMXBeans(PlatformLoggingMXBean.class);
* </pre>
* or from the {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
* platform <tt>MBeanServer</tt>}.
*
* The {@link javax.management.ObjectName ObjectName} for uniquely
* identifying the <tt>LoggingMXBean</tt> within an MBeanServer is:
* <blockquote>
* <tt>java.util.logging:type=Logging</tt>
* </blockquote>
*
* The {@link PlatformManagedObject#getObjectName} method
* can be used to obtain its {@code ObjectName}.
*
* @See java.lang.management.PlatformManagedObject
*
* @author Mandy Chung
* @since 1.7
*/
public interface PlatformLoggingMXBean extends LoggingMXBean, PlatformManagedObject {
}

View File

@ -146,4 +146,6 @@ public class AgentConfigurationError extends Error {
public String[] getParams() {
return params;
}
private static final long serialVersionUID = 1211605593516195475L;
}

View File

@ -248,4 +248,5 @@ public class GcInfoCompositeData extends LazyCompositeData {
return baseGcInfoCompositeType;
}
private static final long serialVersionUID = -5716428894085882742L;
}

View File

@ -192,4 +192,6 @@ public abstract class LazyCompositeData
return isTypeMatched(type1.getRowType(), type2.getRowType());
}
private static final long serialVersionUID = -2190411934472666714L;
}

View File

@ -40,7 +40,11 @@ import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import sun.security.action.LoadLibraryAction;
import java.util.logging.PlatformLoggingMXBean;
import sun.util.logging.LoggingSupport;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.sun.management.OSMBeanFactory;
import com.sun.management.HotSpotDiagnosticMXBean;
@ -135,6 +139,54 @@ public class ManagementFactoryHelper {
return result;
}
public static List<PlatformLoggingMXBean> getLoggingMXBean() {
if (LoggingSupport.isAvailable()) {
return Collections.singletonList(createPlatformLoggingMXBean());
} else {
return Collections.emptyList();
}
}
private final static String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging";
private static PlatformLoggingMXBean createPlatformLoggingMXBean() {
return new PlatformLoggingMXBean() {
private volatile ObjectName objname; // created lazily
@Override
public ObjectName getObjectName() {
ObjectName result = objname;
if (result == null) {
synchronized (this) {
if (objname == null) {
result = Util.newObjectName(LOGGING_MXBEAN_NAME);
objname = result;
}
}
}
return result;
}
@Override
public java.util.List<String> getLoggerNames() {
return LoggingSupport.getLoggerNames();
}
@Override
public String getLoggerLevel(String loggerName) {
return LoggingSupport.getLoggerLevel(loggerName);
}
@Override
public void setLoggerLevel(String loggerName, String levelName) {
LoggingSupport.setLoggerLevel(loggerName, levelName);
}
@Override
public String getParentLoggerName(String loggerName) {
return LoggingSupport.getParentLoggerName(loggerName);
}
};
}
public static List<BufferPoolMXBean> getBufferPoolMXBeans() {
List<BufferPoolMXBean> pools = new ArrayList<BufferPoolMXBean>(2);
pools.add(createBufferPoolMXBean(sun.misc.SharedSecrets.getJavaNioAccess()

View File

@ -777,6 +777,7 @@ public abstract class MappedMXBeanType {
public boolean isValue(Object o) {
return false;
}
private static final long serialVersionUID = -3413063475064374490L;
}
private static final OpenType inProgress;
static {

View File

@ -127,4 +127,5 @@ public class MemoryNotifInfoCompositeData extends LazyCompositeData {
}
}
private static final long serialVersionUID = -1805123446483771291L;
}

View File

@ -126,4 +126,6 @@ public class MemoryUsageCompositeData extends LazyCompositeData {
"Unexpected composite type for MemoryUsage");
}
}
private static final long serialVersionUID = -8504291541083874143L;
}

View File

@ -143,4 +143,6 @@ public class MonitorInfoCompositeData extends LazyCompositeData {
"Unexpected composite type for MonitorInfo");
}
}
private static final long serialVersionUID = -5825215591822908529L;
}

View File

@ -120,4 +120,6 @@ public class StackTraceElementCompositeData extends LazyCompositeData {
"Unexpected composite type for StackTraceElement");
}
}
private static final long serialVersionUID = -2704607706598396827L;
}

View File

@ -410,4 +410,6 @@ public class ThreadInfoCompositeData extends LazyCompositeData {
}
}
private static final long serialVersionUID = 2464378539119753175L;
}

View File

@ -128,4 +128,6 @@ public class VMOptionCompositeData extends LazyCompositeData {
"Unexpected composite type for VMOption");
}
}
private static final long serialVersionUID = -2395573975093578470L;
}

View File

@ -53,4 +53,6 @@ class ByteArrayCounterSnapshot extends AbstractCounter
public byte byteAt(int index) {
return value[index];
}
private static final long serialVersionUID = 1444793459838438979L;
}

View File

@ -42,4 +42,6 @@ public class InstrumentationException extends RuntimeException {
public InstrumentationException(String message) {
super(message);
}
private static final long serialVersionUID = 8060117844393922797L;
}

View File

@ -53,4 +53,6 @@ class LongArrayCounterSnapshot extends AbstractCounter
public long longAt(int index) {
return value[index];
}
private static final long serialVersionUID = 3585870271405924292L;
}

View File

@ -52,4 +52,6 @@ class LongCounterSnapshot extends AbstractCounter
public long longValue() {
return value;
}
private static final long serialVersionUID = 2054263861474565758L;
}

View File

@ -88,4 +88,6 @@ public class PerfByteArrayCounter extends AbstractCounter
getVectorLength(),
byteArrayValue());
}
private static final long serialVersionUID = 2545474036937279921L;
}

View File

@ -80,4 +80,6 @@ public class PerfLongArrayCounter extends AbstractCounter
getVectorLength(),
longArrayValue());
}
private static final long serialVersionUID = -2733617913045487126L;
}

View File

@ -62,4 +62,6 @@ public class PerfLongCounter extends AbstractCounter
getFlags(),
longValue());
}
private static final long serialVersionUID = 857711729279242948L;
}

View File

@ -86,4 +86,5 @@ public class PerfStringCounter extends PerfByteArrayCounter
stringValue());
}
private static final long serialVersionUID = 6802913433363692452L;
}

View File

@ -49,4 +49,6 @@ class StringCounterSnapshot extends AbstractCounter
public String stringValue() {
return value;
}
private static final long serialVersionUID = 1132921539085572034L;
}

View File

@ -86,4 +86,6 @@ public class SingleEntryRegistry extends RegistryImpl {
private final String name;
private final Remote object;
private static final long serialVersionUID = -4897238949499730950L;
}

View File

@ -63,13 +63,13 @@ package sun.security.provider;
* @author Gadi Guy
*/
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.security.*;
import java.io.*;
import java.util.Properties;
import java.util.Enumeration;
import java.net.*;
import java.nio.file.DirectoryStream;
import java.nio.file.Path;
import java.util.Random;
import sun.security.util.Debug;
@ -183,26 +183,38 @@ abstract class SeedGenerator {
// The temporary dir
File f = new File(p.getProperty("java.io.tmpdir"));
int count = 0;
DirectoryStream<Path> ds
= f.toPath().newDirectoryStream();
try {
// Go thru files in the tmp dir using NIO's
// DirectoryStream. Fallback to File.list()
// if NIO is not available.
if (NIODirectoryStream.isAvailable()) {
int count = 0;
Iterable<?> stream =
NIODirectoryStream.newDirectoryStream(f);
// We use a Random object to choose what file names
// should be used. Otherwise on a machine with too
// many files, the same first 1024 files always get
// used. Any, We make sure the first 512 files are
// always used.
Random r = new Random();
for (Path path: ds) {
if (count < 512 || r.nextBoolean()) {
md.update(path.getName().toString().getBytes());
}
if (count++ > 1024) {
break;
try {
for (Object entry: stream) {
if (count < 512 || r.nextBoolean()) {
md.update(NIODirectoryStream.getName(
entry).getBytes());
}
if (count++ > 1024) {
break;
}
}
} finally {
((Closeable)stream).close();
}
} else {
String[] sa = f.list();
for(int i = 0; i < sa.length; i++) {
md.update(sa[i].getBytes());
}
} finally {
ds.close();
}
} catch (Exception ex) {
md.update((byte)ex.hashCode());
@ -505,4 +517,76 @@ abstract class SeedGenerator {
}
/**
* A wrapper of NIO DirectoryStream using reflection.
*/
private static class NIODirectoryStream {
private static final Class<?> pathClass =
getClass("java.nio.file.Path");
private static final Method toPathMethod =
(pathClass == null) ? null : getMethod(File.class, "toPath");
private static final Method getNameMethod =
getMethod(pathClass, "getName");
private static final Method newDirectoryStreamMethod =
getMethod(pathClass, "newDirectoryStream");
private static Class<?> getClass(String name) {
try {
return Class.forName(name, true, null);
} catch (ClassNotFoundException e) {
return null;
}
}
private static Method getMethod(Class<?> clazz,
String name,
Class<?>... paramTypes) {
if (clazz != null) {
try {
return clazz.getMethod(name, paramTypes);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
} else {
return null;
}
}
static boolean isAvailable() {
return pathClass != null;
}
static Iterable<?> newDirectoryStream(File dir) throws IOException {
assert pathClass != null;
try {
Object path = toPathMethod.invoke(dir);
return (Iterable<?>)newDirectoryStreamMethod.invoke(path);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException)
throw (IOException)cause;
if (cause instanceof RuntimeException)
throw (RuntimeException)cause;
if (cause instanceof Error)
throw (Error)cause;
throw new AssertionError(e);
} catch (IllegalAccessException iae) {
throw new AssertionError(iae);
}
}
static String getName(Object path) {
assert pathClass != null;
try {
Object name = getNameMethod.invoke(path);
return name.toString();
} catch (InvocationTargetException e) {
throw new AssertionError(e);
} catch (IllegalAccessException iae) {
throw new AssertionError(iae);
}
}
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.util.logging;
/**
* A proxy interface for the java.util.logging support.
*
* @see sun.util.logging.LoggingSupport
*/
public interface LoggingProxy {
// Methods to bridge java.util.logging.Logger methods
public Object getLogger(String name);
public Object getLevel(Object logger);
public void setLevel(Object logger, Object newLevel);
public boolean isLoggable(Object logger, Object level);
public void log(Object logger, Object level, String msg);
public void log(Object logger, Object level, String msg, Throwable t);
public void log(Object logger, Object level, String msg, Object... params);
// Methods to bridge java.util.logging.LoggingMXBean methods
public java.util.List<String> getLoggerNames();
public String getLoggerLevel(String loggerName);
public void setLoggerLevel(String loggerName, String levelName);
public String getParentLoggerName(String loggerName);
// Methods to bridge Level.parse() and Level.getName() method
public Object parseLevel(String levelName);
public String getLevelName(Object level);
}

View File

@ -0,0 +1,141 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.util.logging;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* Internal API to support JRE implementation to detect if the java.util.logging
* support is available but with no dependency on the java.util.logging
* classes. This LoggingSupport class provides several static methods to
* access the java.util.logging functionality that requires the caller
* to ensure that the logging support is {@linkplain #isAvailable available}
* before invoking it.
*
* @see sun.util.logging.PlatformLogger if you want to log messages even
* if the logging support is not available
*/
public class LoggingSupport {
private LoggingSupport() { }
private static final LoggingProxy proxy =
AccessController.doPrivileged(new PrivilegedAction<LoggingProxy>() {
public LoggingProxy run() {
try {
// create a LoggingProxyImpl instance when
// java.util.logging classes exist
Class<?> c = Class.forName("java.util.logging.LoggingProxyImpl", true, null);
Field f = c.getDeclaredField("INSTANCE");
f.setAccessible(true);
return (LoggingProxy) f.get(null);
} catch (ClassNotFoundException cnf) {
return null;
} catch (NoSuchFieldException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
}
}});
/**
* Returns true if java.util.logging support is available.
*/
public static boolean isAvailable() {
return proxy != null;
}
private static void ensureAvailable() {
if (proxy == null)
throw new AssertionError("Should not here");
}
public static java.util.List<String> getLoggerNames() {
ensureAvailable();
return proxy.getLoggerNames();
}
public static String getLoggerLevel(String loggerName) {
ensureAvailable();
return proxy.getLoggerLevel(loggerName);
}
public static void setLoggerLevel(String loggerName, String levelName) {
ensureAvailable();
proxy.setLoggerLevel(loggerName, levelName);
}
public static String getParentLoggerName(String loggerName) {
ensureAvailable();
return proxy.getParentLoggerName(loggerName);
}
public static Object getLogger(String name) {
ensureAvailable();
return proxy.getLogger(name);
}
public static Object getLevel(Object logger) {
ensureAvailable();
return proxy.getLevel(logger);
}
public static void setLevel(Object logger, Object newLevel) {
ensureAvailable();
proxy.setLevel(logger, newLevel);
}
public static boolean isLoggable(Object logger, Object level) {
ensureAvailable();
return proxy.isLoggable(logger,level);
}
public static void log(Object logger, Object level, String msg) {
ensureAvailable();
proxy.log(logger, level, msg);
}
public static void log(Object logger, Object level, String msg, Throwable t) {
ensureAvailable();
proxy.log(logger, level, msg, t);
}
public static void log(Object logger, Object level, String msg, Object... params) {
ensureAvailable();
proxy.log(logger, level, msg, params);
}
public static Object parseLevel(String levelName) {
ensureAvailable();
return proxy.parseLevel(levelName);
}
public static String getLevelName(Object level) {
ensureAvailable();
return proxy.getLevelName(level);
}
}

View File

@ -136,7 +136,7 @@ public class PlatformLogger {
* This method is called from LogManager.readPrimordialConfiguration().
*/
public static synchronized void redirectPlatformLoggers() {
if (loggingEnabled || !JavaLogger.supported) return;
if (loggingEnabled || !LoggingSupport.isAvailable()) return;
loggingEnabled = true;
for (Map.Entry<String, WeakReference<PlatformLogger>> entry : loggers.entrySet()) {
@ -487,73 +487,22 @@ public class PlatformLogger {
* java.util.logging.Logger object.
*/
static class JavaLogger extends LoggerProxy {
private static final boolean supported;
private static final Class<?> loggerClass;
private static final Class<?> levelClass;
private static final Method getLoggerMethod;
private static final Method setLevelMethod;
private static final Method getLevelMethod;
private static final Method isLoggableMethod;
private static final Method logMethod;
private static final Method logThrowMethod;
private static final Method logParamsMethod;
private static final Map<Integer, Object> levelObjects =
new HashMap<Integer, Object>();
static {
loggerClass = getClass("java.util.logging.Logger");
levelClass = getClass("java.util.logging.Level");
getLoggerMethod = getMethod(loggerClass, "getLogger", String.class);
setLevelMethod = getMethod(loggerClass, "setLevel", levelClass);
getLevelMethod = getMethod(loggerClass, "getLevel");
isLoggableMethod = getMethod(loggerClass, "isLoggable", levelClass);
logMethod = getMethod(loggerClass, "log", levelClass, String.class);
logThrowMethod = getMethod(loggerClass, "log", levelClass, String.class, Throwable.class);
logParamsMethod = getMethod(loggerClass, "log", levelClass, String.class, Object[].class);
supported = (loggerClass != null && levelClass != null && getLoggerMethod != null &&
getLevelMethod != null && setLevelMethod != null &&
logMethod != null && logThrowMethod != null && logParamsMethod != null);
if (supported) {
if (LoggingSupport.isAvailable()) {
// initialize the map to Level objects
getLevelObjects();
}
}
private static Class<?> getClass(String name) {
try {
return Class.forName(name, true, null);
} catch (ClassNotFoundException e) {
return null;
}
}
private static Method getMethod(Class<?> cls, String name, Class<?>... parameterTypes) {
if (cls == null) return null;
try {
return cls.getMethod(name, parameterTypes);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}
private static Object invoke(Method m, Object obj, Object... params) {
try {
return m.invoke(obj, params);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
private static void getLevelObjects() {
// get all java.util.logging.Level objects
Method parseLevelMethod = getMethod(levelClass, "parse", String.class);
int[] levelArray = new int[] {OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL};
for (int l : levelArray) {
Object o = invoke(parseLevelMethod, null, getLevelName(l));
levelObjects.put(l, o);
Object level = LoggingSupport.parseLevel(getLevelName(l));
levelObjects.put(l, level);
}
}
@ -564,10 +513,10 @@ public class PlatformLogger {
JavaLogger(String name, int level) {
super(name, level);
this.javaLogger = invoke(getLoggerMethod, null, name);
this.javaLogger = LoggingSupport.getLogger(name);
if (level != 0) {
// level has been updated and so set the Logger's level
invoke(setLevelMethod, javaLogger, levelObjects.get(level));
LoggingSupport.setLevel(javaLogger, levelObjects.get(level));
}
}
@ -578,24 +527,24 @@ public class PlatformLogger {
* not be updated.
*/
void doLog(int level, String msg) {
invoke(logMethod, javaLogger, levelObjects.get(level), msg);
LoggingSupport.log(javaLogger, levelObjects.get(level), msg);
}
void doLog(int level, String msg, Throwable t) {
invoke(logThrowMethod, javaLogger, levelObjects.get(level), msg, t);
LoggingSupport.log(javaLogger, levelObjects.get(level), msg, t);
}
void doLog(int level, String msg, Object... params) {
invoke(logParamsMethod, javaLogger, levelObjects.get(level), msg, params);
LoggingSupport.log(javaLogger, levelObjects.get(level), msg, params);
}
boolean isEnabled() {
Object level = invoke(getLevelMethod, javaLogger);
Object level = LoggingSupport.getLevel(javaLogger);
return level == null || level.equals(levelObjects.get(OFF)) == false;
}
int getLevel() {
Object level = invoke(getLevelMethod, javaLogger);
Object level = LoggingSupport.getLevel(javaLogger);
if (level != null) {
for (Map.Entry<Integer, Object> l : levelObjects.entrySet()) {
if (level == l.getValue()) {
@ -608,15 +557,14 @@ public class PlatformLogger {
void setLevel(int newLevel) {
levelValue = newLevel;
invoke(setLevelMethod, javaLogger, levelObjects.get(newLevel));
LoggingSupport.setLevel(javaLogger, levelObjects.get(newLevel));
}
public boolean isLoggable(int level) {
return (Boolean) invoke(isLoggableMethod, javaLogger, levelObjects.get(level));
return LoggingSupport.isLoggable(javaLogger, levelObjects.get(level));
}
}
private static String getLevelName(int level) {
switch (level) {
case OFF : return "OFF";

View File

@ -0,0 +1,279 @@
/*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6876135
*
* @summary Test PlatformLoggingMXBean
* This test performs similar testing as LoggingMXBeanTest.
*
* @build PlatformLoggingMXBeanTest
* @run main PlatformLoggingMXBeanTest
*/
import javax.management.*;
import java.lang.management.ManagementFactory;
import java.util.logging.*;
import java.util.List;
public class PlatformLoggingMXBeanTest
{
ObjectName objectName = null;
static String LOGGER_NAME_1 = "com.sun.management.Logger1";
static String LOGGER_NAME_2 = "com.sun.management.Logger2";
public PlatformLoggingMXBeanTest() throws Exception {
}
private void runTest(PlatformLoggingMXBean mBean) throws Exception {
/*
* Create the MBeanServeri, register the PlatformLoggingMXBean
*/
System.out.println( "***************************************************" );
System.out.println( "********** PlatformLoggingMXBean Unit Test **********" );
System.out.println( "***************************************************" );
System.out.println( "" );
System.out.println( "*******************************" );
System.out.println( "*********** Phase 1 ***********" );
System.out.println( "*******************************" );
System.out.println( " Creating MBeanServer " );
System.out.print( " Register PlatformLoggingMXBean: " );
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
String[] list = new String[0];
try {
objectName = new ObjectName(LogManager.LOGGING_MXBEAN_NAME);
mbs.registerMBean( mBean, objectName );
}
catch ( Exception e ) {
System.out.println( "FAILED" );
throw e;
}
System.out.println( "PASSED" );
System.out.println("");
/*
* Access our MBean to get the current list of Loggers
*/
System.out.println( "*******************************" );
System.out.println( "*********** Phase 2 ***********" );
System.out.println( "*******************************" );
System.out.println( " Test Logger Name retrieval (getLoggerNames) " );
// check that Level object are returned properly
try {
list = (String[]) mbs.getAttribute( objectName, "LoggerNames" );
}
catch ( Exception e ) {
System.out.println(" : FAILED" );
throw e;
}
/*
* Dump the list of Loggers already present, if any
*/
Object[] params = new Object[1];
String[] signature = new String[1];
Level l;
if ( list == null ) {
System.out.println(" : PASSED. No Standard Loggers Present" );
System.out.println("");
}
else {
System.out.println(" : PASSED. There are " + list.length + " Loggers Present" );
System.out.println("");
System.out.println( "*******************************" );
System.out.println( "*********** Phase 2B **********" );
System.out.println( "*******************************" );
System.out.println( " Examine Existing Loggers" );
for ( int i = 0; i < list.length; i++ ) {
try {
params[0] = list[i];
signature[0] = "java.lang.String";
String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
System.out.println(" : Logger #" + i + " = " + list[i] );
System.out.println(" : Level = " + levelName );
}
catch ( Exception e ) {
System.out.println(" : FAILED" );
throw e;
}
}
System.out.println(" : PASSED" );
}
/*
* Create two new loggers to the list of Loggers already present
*/
System.out.println("");
System.out.println( "*******************************" );
System.out.println( "*********** Phase 3 ***********" );
System.out.println( "*******************************" );
System.out.println( " Create and test new Loggers" );
Logger logger1 = Logger.getLogger( LOGGER_NAME_1 );
Logger logger2 = Logger.getLogger( LOGGER_NAME_2 );
// check that Level object are returned properly
try {
list = (String[]) mbs.getAttribute( objectName, "LoggerNames" );
}
catch ( Exception e ) {
System.out.println(" : FAILED" );
throw e;
}
/*
* Check for the existence of our new Loggers
*/
boolean log1 = false, log2 = false;
if ( list == null || list.length < 2 ) {
System.out.println(" : FAILED. Could not Detect the presense of the new Loggers" );
throw new RuntimeException(
"Could not Detect the presense of the new Loggers");
}
else {
for ( int i = 0; i < list.length; i++ ) {
if ( list[i].equals( LOGGER_NAME_1 ) ) {
log1 = true;
System.out.println( " : Found new Logger : " + list[i] );
}
if ( list[i].equals( LOGGER_NAME_2 ) ) {
log2 = true;
System.out.println( " : Found new Logger : " + list[i] );
}
}
if ( log1 && log2 )
System.out.println( " : PASSED." );
else {
System.out.println( " : FAILED. Could not Detect the new Loggers." );
throw new RuntimeException(
"Could not Detect the presense of the new Loggers");
}
}
/*
* Set a new Logging levels and check that it succeeded
*/
System.out.println("");
System.out.println( "*******************************" );
System.out.println( "*********** Phase 4 ***********" );
System.out.println( "*******************************" );
System.out.println( " Set and Check the Logger Level" );
log1 = false;
log2 = false;
try {
// Set the level of logger1 to ALL
params = new Object[2];
signature = new String[2];
params[0] = LOGGER_NAME_1;
params[1] = Level.ALL.getName();
signature[0] = "java.lang.String";
signature[1] = "java.lang.String";
mbs.invoke( objectName, "setLoggerLevel", params, signature );
// Set the level of logger2 to FINER
params[0] = LOGGER_NAME_2;
params[1] = Level.FINER.getName();
mbs.invoke( objectName, "setLoggerLevel", params, signature );
// Okay read back the Level from Logger1. Should be ALL
params = new Object[1];
signature = new String[1];
params[0] = LOGGER_NAME_1;
signature[0] = "java.lang.String";
String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
l = Level.parse(levelName);
System.out.print(" Logger1: " );
if ( l.equals( l.ALL ) ) {
System.out.println("Level Set to ALL: PASSED" );
log1 = true;
}
else {
System.out.println("Level Set to ALL: FAILED" );
throw new RuntimeException(
"Level Set to ALL but returned " + l.toString());
}
// Okay read back the Level from Logger2. Should be FINER
params = new Object[1];
signature = new String[1];
params[0] = LOGGER_NAME_2;
signature[0] = "java.lang.String";
levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
l = Level.parse(levelName);
System.out.print(" Logger2: " );
if ( l.equals( l.FINER ) ) {
System.out.println("Level Set to FINER: PASSED" );
log2 = true;
}
else {
System.out.println("Level Set to FINER: FAILED" );
throw new RuntimeException(
"Level Set to FINER but returned " + l.toString());
}
}
catch ( Exception e ) {
throw e;
}
System.out.println( "" );
System.out.println( "***************************************************" );
System.out.println( "***************** All Tests Passed ****************" );
System.out.println( "***************************************************" );
}
public static void main(String[] argv) throws Exception {
List<PlatformLoggingMXBean> result =
ManagementFactory.getPlatformMXBeans(PlatformLoggingMXBean.class);
if (result.size() != 1) {
throw new RuntimeException("Unexpected number of PlatformLoggingMXBean instances: " +
result.size());
}
PlatformLoggingMXBean mbean = result.get(0);
ObjectName objname = mbean.getObjectName();
if (!objname.equals(new ObjectName(LogManager.LOGGING_MXBEAN_NAME))) {
throw new RuntimeException("Invalid ObjectName " + objname);
}
// check if the PlatformLoggingMXBean is registered in the platform MBeanServer
MBeanServer platformMBS = ManagementFactory.getPlatformMBeanServer();
ObjectName objName = new ObjectName(LogManager.LOGGING_MXBEAN_NAME);
// We could call mbs.isRegistered(objName) here.
// Calling getMBeanInfo will throw exception if not found.
platformMBS.getMBeanInfo(objName);
if (!platformMBS.isInstanceOf(objName, "java.util.logging.PlatformLoggingMXBean") ||
!platformMBS.isInstanceOf(objName, "java.util.logging.LoggingMXBean")) {
throw new RuntimeException(objName + " is of unexpected type");
}
// test if PlatformLoggingMXBean works properly in a MBeanServer
PlatformLoggingMXBeanTest test = new PlatformLoggingMXBeanTest();
test.runTest(mbean);
}
}

View File

@ -23,6 +23,7 @@
/* @test
* @bug 4811913
* @ignore until 6896424 is resolved
* @summary Test bounds checking in zip package
*/