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) {
@ -123,18 +126,17 @@ public class OSMXBean {
//using linux bash commands to retrieve info
Process p = Runtime.getRuntime().exec(
new String[] { "bash", "-c",
new String[] { "bash", "-c",
"ls /proc/" + pidhost[0] + "/fdinfo | wc -l" });
InputStream in = p.getInputStream();
BufferedReader output = new BufferedReader(
new InputStreamReader(in));
new InputStreamReader(in));
String openFileDesCount;
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);
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);
}
return -1;
}
@ -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) {
@ -157,19 +159,18 @@ public class OSMXBean {
//using linux bash commands to retrieve info
Process p = Runtime.getRuntime().exec(
new String[] { "bash", "-c",
"ulimit -n" });
new String[] { "bash", "-c",
"ulimit -n" });
InputStream in = p.getInputStream();
BufferedReader output = new BufferedReader(
new InputStreamReader(in));
String maxFileDesCount;
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);
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);
}
return -1;
}
}
}

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) {
return 0;
} else {
return (int) unixOsStats.getOpenFileDescriptorCount();
}
JVM jvm = new JVM();
if (jvm != null && jvm.isUnix() == true)
return (int)jvm.getOpenFileDescriptorCount();
else
return 0;
}
@Override
@ -119,16 +102,16 @@ 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) {
return 0;
} else {
return (int) unixOsStats.getMaxFileDescriptorCount();
}
}
}
JVM jvm = new JVM();
if (jvm != null && jvm.isUnix() == true)
return (int)jvm.getMaxFileDescriptorCount();
else
return 0;
}
}
/**