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.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.util.Shell;
/** /**
* This class is a wrapper for the implementation of * This class is a wrapper for the implementation of
* com.sun.management.UnixOperatingSystemMXBean * 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. * depending on the runtime (vendor) used.
*/ */
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Evolving @InterfaceStability.Evolving
public class OSMXBean { public class JVM
static final Logger LOG = LoggerFactory.getLogger(OSMXBean.class); {
static final Logger LOG = LoggerFactory.getLogger(JVM.class);
private OperatingSystemMXBean osMbean; private OperatingSystemMXBean osMbean;
@ -58,7 +61,7 @@ public class OSMXBean {
/** /**
* Constructor. Get the running Operating System instance * Constructor. Get the running Operating System instance
*/ */
public OSMXBean () { public JVM () {
this.osMbean = ManagementFactory.getOperatingSystemMXBean(); this.osMbean = ManagementFactory.getOperatingSystemMXBean();
} }
@ -80,8 +83,8 @@ public class OSMXBean {
* @param mBeanMethodName : method to run from the interface UnixOperatingSystemMXBean * @param mBeanMethodName : method to run from the interface UnixOperatingSystemMXBean
* @return the method result * @return the method result
*/ */
private Long runUnixMXBeanMethod (String mBeanMethodName) private Long runUnixMXBeanMethod (String mBeanMethodName) {
{
Object unixos; Object unixos;
Class<?> classRef; Class<?> classRef;
Method mBeanMethod; Method mBeanMethod;
@ -107,8 +110,8 @@ public class OSMXBean {
* Otherwise, this methods implements it (linux only). * Otherwise, this methods implements it (linux only).
* @return number of open file descriptors for the jvm * @return number of open file descriptors for the jvm
*/ */
public long getOpenFileDescriptorCount() public long getOpenFileDescriptorCount() {
{
Long ofdc; Long ofdc;
if (!ibmvendor) { if (!ibmvendor) {
@ -123,18 +126,17 @@ public class OSMXBean {
//using linux bash commands to retrieve info //using linux bash commands to retrieve info
Process p = Runtime.getRuntime().exec( Process p = Runtime.getRuntime().exec(
new String[] { "bash", "-c", new String[] { "bash", "-c",
"ls /proc/" + pidhost[0] + "/fdinfo | wc -l" }); "ls /proc/" + pidhost[0] + "/fdinfo | wc -l" });
InputStream in = p.getInputStream(); InputStream in = p.getInputStream();
BufferedReader output = new BufferedReader( BufferedReader output = new BufferedReader(
new InputStreamReader(in)); new InputStreamReader(in));
String openFileDesCount; String openFileDesCount;
if ((openFileDesCount = output.readLine()) != null) { if ((openFileDesCount = output.readLine()) != null)
return Long.parseLong(openFileDesCount); return Long.parseLong(openFileDesCount);
} } catch (IOException ie) {
} catch (IOException ie) { LOG.warn("Not able to get the number of open file descriptors", ie);
LOG.warn("Not able to get the number of open file descriptors", ie);
} }
return -1; return -1;
} }
@ -145,8 +147,8 @@ public class OSMXBean {
* Otherwise, this methods implements it (linux only). * Otherwise, this methods implements it (linux only).
* @return max number of file descriptors the operating system can use. * @return max number of file descriptors the operating system can use.
*/ */
public long getMaxFileDescriptorCount() public long getMaxFileDescriptorCount() {
{
Long mfdc; Long mfdc;
if (!ibmvendor) { if (!ibmvendor) {
@ -157,19 +159,18 @@ public class OSMXBean {
//using linux bash commands to retrieve info //using linux bash commands to retrieve info
Process p = Runtime.getRuntime().exec( Process p = Runtime.getRuntime().exec(
new String[] { "bash", "-c", new String[] { "bash", "-c",
"ulimit -n" }); "ulimit -n" });
InputStream in = p.getInputStream(); InputStream in = p.getInputStream();
BufferedReader output = new BufferedReader( BufferedReader output = new BufferedReader(
new InputStreamReader(in)); new InputStreamReader(in));
String maxFileDesCount; String maxFileDesCount;
if ((maxFileDesCount = output.readLine()) != null) { if ((maxFileDesCount = output.readLine()) != null)
return Long.parseLong(maxFileDesCount); return Long.parseLong(maxFileDesCount);
} } catch (IOException ie) {
} catch (IOException ie) { LOG.warn("Not able to get the max number of file descriptors", ie);
LOG.warn("Not able to get the max number of file descriptors", ie);
} }
return -1; return -1;
} }
} }

View File

@ -32,7 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.hadoop.hbase.ResourceChecker.Phase; import org.apache.hadoop.hbase.ResourceChecker.Phase;
import org.junit.runner.notification.RunListener; 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: * 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 { static class OpenFileDescriptorResourceAnalyzer extends ResourceChecker.ResourceAnalyzer {
osStats = ManagementFactory.getOperatingSystemMXBean();
if (osStats instanceof UnixOperatingSystemMXBean) {
unixOsStats = (UnixOperatingSystemMXBean) osStats;
} else {
unixOsStats = null;
}
}
}
static class OpenFileDescriptorResourceAnalyzer extends OSResourceAnalyzer {
@Override @Override
public int getVal(Phase phase) { public int getVal(Phase phase) {
if (unixOsStats == null) { JVM jvm = new JVM();
return 0; if (jvm != null && jvm.isUnix() == true)
} else { return (int)jvm.getOpenFileDescriptorCount();
return (int) unixOsStats.getOpenFileDescriptorCount(); else
} return 0;
} }
@Override @Override
@ -119,16 +102,16 @@ public class ResourceCheckerJUnitListener extends RunListener {
} }
} }
static class MaxFileDescriptorResourceAnalyzer extends OSResourceAnalyzer { static class MaxFileDescriptorResourceAnalyzer extends ResourceChecker.ResourceAnalyzer {
@Override @Override
public int getVal(Phase phase) { public int getVal(Phase phase) {
if (unixOsStats == null) { JVM jvm = new JVM();
return 0; if (jvm != null && jvm.isUnix() == true)
} else { return (int)jvm.getMaxFileDescriptorCount();
return (int) unixOsStats.getMaxFileDescriptorCount(); else
} return 0;
} }
} }
/** /**