You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ay...@apache.org on 2007/01/31 13:48:06 UTC
svn commit: r501829 - in
/harmony/enhanced/classlib/trunk/modules/logging/src/main/java:
java/util/logging/LogManager.java
org/apache/harmony/logging/internal/nls/messages.properties
Author: ayza
Date: Wed Jan 31 04:48:05 2007
New Revision: 501829
URL: http://svn.apache.org/viewvc?view=rev&rev=501829
Log:
Implementation of LogManager.getLoggingMXBean() was added - HARMONY-3075 ([classlib][logging] implementation of getLoggingMXBean)
Modified:
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java?view=diff&rev=501829&r1=501828&r2=501829
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java Wed Jan 31 04:48:05 2007
@@ -29,8 +29,16 @@
import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Properties;
+import java.util.Set;
import java.util.StringTokenizer;
+import java.lang.management.ManagementFactory;
+import java.lang.reflect.Method;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.ObjectInstance;
+import javax.management.MalformedObjectNameException;
import org.apache.harmony.logging.internal.nls.Messages;
@@ -140,7 +148,8 @@
// The line separator of the underlying OS
// Use privileged code to read the line.separator system property
- private static final String lineSeparator = getPrivilegedSystemProperty("line.separator"); //$NON-NLS-1$
+ private static final String lineSeparator =
+ getPrivilegedSystemProperty("line.separator"); //$NON-NLS-1$
// The shared logging permission
private static final LoggingPermission perm = new LoggingPermission(
@@ -152,12 +161,45 @@
/**
* <p>The String value of the {@link LoggingMXBean}'s ObjectName.</p>
*/
- public static final String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; //$NON-NLS-1$
+ public static final String LOGGING_MXBEAN_NAME =
+ "java.util.logging:type=Logging"; //$NON-NLS-1$
+ /**
+ * Get the <code>LoggingMXBean</code> instance
+ *
+ * @return the <code>LoggingMXBean</code> instance
+ */
public static LoggingMXBean getLoggingMXBean() {
- // logging.0=This method is not currently implemented.
- throw new AssertionError(Messages.getString("logging.0")); //$NON-NLS-1$
+ try {
+ ObjectName loggingMXBeanName = new ObjectName(LOGGING_MXBEAN_NAME);
+ MBeanServer platformBeanServer =
+ ManagementFactory.getPlatformMBeanServer();
+ Set loggingMXBeanSet = platformBeanServer.queryMBeans(
+ loggingMXBeanName, null);
+
+ if (loggingMXBeanSet.size() != 1) {
+ // logging.21=There Can Be Only One logging MX bean.
+ throw new AssertionError(Messages.getString("logging.21"));
+ }
+
+ Iterator i = loggingMXBeanSet.iterator();
+ ObjectInstance loggingMXBeanOI = (ObjectInstance) i.next();
+ String lmxbcn = loggingMXBeanOI.getClassName();
+ Class lmxbc = Class.forName(lmxbcn);
+ Method giMethod = lmxbc.getDeclaredMethod("getInstance");
+ giMethod.setAccessible(true);
+ LoggingMXBean lmxb = (LoggingMXBean)
+ giMethod.invoke(null, new Object[] {});
+
+ return lmxb;
+ } catch (Exception e) {
+ //TODO
+ //e.printStackTrace();
+ }
+ // logging.22=Exception occurred while getting the logging MX bean.
+ throw new AssertionError(Messages.getString("logging.22")); //$NON-NLS-1$
}
+
/*
* -------------------------------------------------------------------
* Instance variables
@@ -182,7 +224,8 @@
// init LogManager singleton instance
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
- String className = System.getProperty("java.util.logging.manager"); //$NON-NLS-1$
+ String className = System.getProperty(
+ "java.util.logging.manager"); //$NON-NLS-1$
if (null != className) {
manager = (LogManager) getInstanceByClass(className);
@@ -306,7 +349,8 @@
if (parent != null) {
logger.internalSetParent(parent);
break;
- }else if(getProperty(parentName+".level") != null || getProperty(parentName+".handlers") != null){//$NON-NLS-1$ //$NON-NLS-2$
+ } else if (getProperty(parentName+".level") != null || //$NON-NLS-1$
+ getProperty(parentName+".handlers") != null) { //$NON-NLS-1$
parent = Logger.getLogger(parentName);
logger.internalSetParent(parent);
break;
@@ -389,23 +433,27 @@
public void readConfiguration() throws IOException {
checkAccess();
// check config class
- String configClassName = System.getProperty("java.util.logging.config.class"); //$NON-NLS-1$
+ String configClassName = System.getProperty(
+ "java.util.logging.config.class"); //$NON-NLS-1$
if (null == configClassName || null == getInstanceByClass(configClassName)) {
// if config class failed, check config file
- String configFile = System.getProperty("java.util.logging.config.file"); //$NON-NLS-1$
+ String configFile = System.getProperty(
+ "java.util.logging.config.file"); //$NON-NLS-1$
+
if (null == configFile) {
// if cannot find configFile, use default logging.properties
configFile = new StringBuilder().append(
System.getProperty("java.home")).append(File.separator) //$NON-NLS-1$
.append("lib").append(File.separator).append( //$NON-NLS-1$
- "logging.properties").toString(); //$NON-NLS-1$
+ "logging.properties").toString(); //$NON-NLS-1$
}
+
InputStream input = null;
try {
input = new BufferedInputStream(new FileInputStream(configFile));
readConfigurationImpl(input);
} finally {
- if(input != null){
+ if (input != null) {
try {
input.close();
} catch (Exception e) {// ignore
@@ -432,12 +480,13 @@
return clazz.newInstance();
} catch (Exception e) {
try {
- Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(
- className);
+ Class<?> clazz = Thread.currentThread()
+ .getContextClassLoader().loadClass(className);
return clazz.newInstance();
} catch (Exception innerE) {
//logging.20=Loading class "{0}" failed
- System.err.println(Messages.getString("logging.20", className)); //$NON-NLS-1$
+ System.err.println(Messages.getString(
+ "logging.20", className)); //$NON-NLS-1$
System.err.println(innerE);
return null;
}
@@ -464,7 +513,8 @@
// set levels for logger
Collection<Logger> allLoggers = loggers.values();
for(Logger logger : allLoggers){
- String property = props.getProperty(logger.getName()+".level"); //$NON-NLS-1$
+ String property = props.getProperty(
+ logger.getName()+".level"); //$NON-NLS-1$
if(null != property){
logger.setLevel(Level.parse(property));
}
Modified: harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties?view=diff&rev=501829&r1=501828&r2=501829
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties Wed Jan 31 04:48:05 2007
@@ -35,6 +35,8 @@
logging.1F=Exception - {0}
logging.2=The OutputStream parameter is null
logging.20=Loading class "{0}" failed
+logging.21=There Can Be Only One logging MX bean.
+logging.22=Exception occurred while getting the logging MX bean.
logging.3=The Formatter parameter is null.
logging.4=The 'level' parameter is null.
logging.5=Different version - {0}.{1}