HBASE-6945 Compilation errors when using non-Sun JDKs to build HBase-0.94

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1409115 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-11-14 08:42:52 +00:00
parent 839a0944b3
commit 98bdd5df13
2 changed files with 41 additions and 57 deletions

View File

@ -34,17 +34,20 @@ import java.lang.reflect.Method;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.util.Shell;
/**
* This class is a wrapper for the implementation of
* com.sun.management.UnixOperatingSystemMXBean
* It will decide to use Oracle Java api or its own implementation
* It will decide to use the sun api or its own implementation
* depending on the runtime (vendor) used.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class OSMXBean {
static final Logger LOG = LoggerFactory.getLogger(OSMXBean.class);
public class JVM
{
static final Logger LOG = LoggerFactory.getLogger(JVM.class);
private OperatingSystemMXBean osMbean;
@ -58,7 +61,7 @@ public class OSMXBean {
/**
* Constructor. Get the running Operating System instance
*/
public OSMXBean () {
public JVM () {
this.osMbean = ManagementFactory.getOperatingSystemMXBean();
}
@ -80,8 +83,8 @@ public class OSMXBean {
* @param mBeanMethodName : method to run from the interface UnixOperatingSystemMXBean
* @return the method result
*/
private Long runUnixMXBeanMethod (String mBeanMethodName)
{
private Long runUnixMXBeanMethod (String mBeanMethodName) {
Object unixos;
Class<?> classRef;
Method mBeanMethod;
@ -107,8 +110,8 @@ public class OSMXBean {
* Otherwise, this methods implements it (linux only).
* @return number of open file descriptors for the jvm
*/
public long getOpenFileDescriptorCount()
{
public long getOpenFileDescriptorCount() {
Long ofdc;
if (!ibmvendor) {
@ -130,9 +133,8 @@ public class OSMXBean {
new InputStreamReader(in));
String openFileDesCount;
if ((openFileDesCount = output.readLine()) != null) {
if ((openFileDesCount = output.readLine()) != null)
return Long.parseLong(openFileDesCount);
}
} catch (IOException ie) {
LOG.warn("Not able to get the number of open file descriptors", ie);
}
@ -145,8 +147,8 @@ public class OSMXBean {
* Otherwise, this methods implements it (linux only).
* @return max number of file descriptors the operating system can use.
*/
public long getMaxFileDescriptorCount()
{
public long getMaxFileDescriptorCount() {
Long mfdc;
if (!ibmvendor) {
@ -164,9 +166,8 @@ public class OSMXBean {
new InputStreamReader(in));
String maxFileDesCount;
if ((maxFileDesCount = output.readLine()) != null) {
if ((maxFileDesCount = output.readLine()) != null)
return Long.parseLong(maxFileDesCount);
}
} catch (IOException ie) {
LOG.warn("Not able to get the max number of file descriptors", ie);
}

View File

@ -32,7 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.hadoop.hbase.ResourceChecker.Phase;
import org.junit.runner.notification.RunListener;
import com.sun.management.UnixOperatingSystemMXBean;
import org.apache.hadoop.hbase.util.JVM;
/**
* Listen to the test progress and check the usage of:
@ -85,32 +85,15 @@ public class ResourceCheckerJUnitListener extends RunListener {
}
}
/**
* On unix, we know how to get the number of open file descriptor. This class allow to share
* the MXBeans code.
*/
abstract static class OSResourceAnalyzer extends ResourceChecker.ResourceAnalyzer {
protected static final OperatingSystemMXBean osStats;
protected static final UnixOperatingSystemMXBean unixOsStats;
static {
osStats = ManagementFactory.getOperatingSystemMXBean();
if (osStats instanceof UnixOperatingSystemMXBean) {
unixOsStats = (UnixOperatingSystemMXBean) osStats;
} else {
unixOsStats = null;
}
}
}
static class OpenFileDescriptorResourceAnalyzer extends OSResourceAnalyzer {
static class OpenFileDescriptorResourceAnalyzer extends ResourceChecker.ResourceAnalyzer {
@Override
public int getVal(Phase phase) {
if (unixOsStats == null) {
JVM jvm = new JVM();
if (jvm != null && jvm.isUnix() == true)
return (int)jvm.getOpenFileDescriptorCount();
else
return 0;
} else {
return (int) unixOsStats.getOpenFileDescriptorCount();
}
}
@Override
@ -119,14 +102,14 @@ public class ResourceCheckerJUnitListener extends RunListener {
}
}
static class MaxFileDescriptorResourceAnalyzer extends OSResourceAnalyzer {
static class MaxFileDescriptorResourceAnalyzer extends ResourceChecker.ResourceAnalyzer {
@Override
public int getVal(Phase phase) {
if (unixOsStats == null) {
JVM jvm = new JVM();
if (jvm != null && jvm.isUnix() == true)
return (int)jvm.getMaxFileDescriptorCount();
else
return 0;
} else {
return (int) unixOsStats.getMaxFileDescriptorCount();
}
}
}