org.rhq.core.system
Class NativeSystemInfo

java.lang.Object
  extended by org.rhq.core.system.NativeSystemInfo
All Implemented Interfaces:
SystemInfo
Direct Known Subclasses:
WindowsNativeSystemInfo

public class NativeSystemInfo
extends Object
implements SystemInfo

The superclass for all the native SystemInfo implementations. You are free to subclass this implementation if there are additional platform-specific methods that need to be exposed. Most functionality, however, can be exposed via this native superclass implementation.

This implementation uses SIGAR. To enable debug logging in SIGAR, set the system property "sigar.nativeLogging" or call Sigar.enableLogging(boolean).


Constructor Summary
NativeSystemInfo()
          Constructor for NativeSystemInfo with package scope so only the SystemInfoFactory can instantiate this object.
 
Method Summary
 ProcessExecutionResults executeProcess(ProcessExecution processExecution)
          Executes a process.
 List<NetworkAdapterInfo> getAllNetworkAdapters()
          Returns the information on all installed network adapters.
 List<ProcessInfo> getAllProcesses()
          Returns the information on all processes found in the process table.
 List<ServiceInfo> getAllServices()
          Returns the information on all installed services found in the services manager.
 CpuInformation getCpu(int cpuIndex)
          Returns information about a specified CPU installed on the hardware where the JVM is running.
 FileSystemInfo getFileSystem(String path)
          Returns information on the mounted file system that hosts the given file or directory.
 List<FileSystemInfo> getFileSystems()
          Returns information on all mounted file systems.
 String getHostname()
          Returns the hostname that the system is known as.
 org.hyperic.sigar.Mem getMemoryInfo()
          Returns information about memory installed on the platform.
 NetworkAdapterStats getNetworkAdapterStats(String interfaceName)
           
 NetworkStats getNetworkStats(String addressName, int port)
           
 int getNumberOfCpus()
          Returns the number of CPUs on the hardware platform.
 String getOperatingSystemName()
          Returns the name of the operating system.
 OperatingSystemType getOperatingSystemType()
          Returns the operating system type, if known; otherwise, OperatingSystemType.JAVA is returned (in which case, the caller can examine the Java system property "os.name" to try to detect the type).
 String getOperatingSystemVersion()
          Returns the version string of the operating system, as reported by the operating system.
 List<ProcessInfo> getProcesses(String piq)
          Returns ProcessInfo objects for all processes that match the provided PIQL query string
 org.hyperic.sigar.Swap getSwapInfo()
          Returns information about the virtual, swap memory installed on the platform.
 String getSystemArchitecture()
          Returns the architecture of the underlying hardware
 ProcessInfo getThisProcess()
          Returns the process information for the Java VM process this object is running in.
 boolean isNative()
          Always returns true to indicate that the native library is available.
 String readLineFromConsole(boolean noEcho)
          Reads a line of input from the console and returns that line as a string.
 void writeLineToConsole(String line)
          Writes a line of output to the console.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NativeSystemInfo

public NativeSystemInfo()
Constructor for NativeSystemInfo with package scope so only the SystemInfoFactory can instantiate this object.

Method Detail

isNative

public boolean isNative()
Always returns true to indicate that the native library is available.

Specified by:
isNative in interface SystemInfo
Returns:
true if there is a low-level native API available for the JVM's platform
See Also:
SystemInfo.isNative()

getOperatingSystemType

public OperatingSystemType getOperatingSystemType()
Description copied from interface: SystemInfo
Returns the operating system type, if known; otherwise, OperatingSystemType.JAVA is returned (in which case, the caller can examine the Java system property "os.name" to try to detect the type).

Specified by:
getOperatingSystemType in interface SystemInfo
Returns:
the type of operating system, as detected by the native layer

getOperatingSystemName

public String getOperatingSystemName()
Description copied from interface: SystemInfo
Returns the name of the operating system.

Specified by:
getOperatingSystemName in interface SystemInfo
Returns:
OS name

getOperatingSystemVersion

public String getOperatingSystemVersion()
Description copied from interface: SystemInfo
Returns the version string of the operating system, as reported by the operating system.

Specified by:
getOperatingSystemVersion in interface SystemInfo
Returns:
what the operating system says is its version

getHostname

public String getHostname()
                   throws SystemInfoException
Description copied from interface: SystemInfo
Returns the hostname that the system is known as.

Specified by:
getHostname in interface SystemInfo
Returns:
machine host name
Throws:
SystemInfoException

getAllNetworkAdapters

public List<NetworkAdapterInfo> getAllNetworkAdapters()
                                               throws SystemInfoException
Description copied from interface: SystemInfo
Returns the information on all installed network adapters.

Specified by:
getAllNetworkAdapters in interface SystemInfo
Returns:
list containing information on all network adapters
Throws:
SystemInfoException

getNetworkAdapterStats

public NetworkAdapterStats getNetworkAdapterStats(String interfaceName)
Specified by:
getNetworkAdapterStats in interface SystemInfo

getNetworkStats

public NetworkStats getNetworkStats(String addressName,
                                    int port)
Specified by:
getNetworkStats in interface SystemInfo

getAllServices

public List<ServiceInfo> getAllServices()
                                 throws SystemInfoException
Description copied from interface: SystemInfo
Returns the information on all installed services found in the services manager.

Specified by:
getAllServices in interface SystemInfo
Returns:
list container information on all services currently installed
Throws:
SystemInfoException

getAllProcesses

public List<ProcessInfo> getAllProcesses()
Description copied from interface: SystemInfo
Returns the information on all processes found in the process table. This means that all processes currently running and are visible to the user running the VM are returned.

Specified by:
getAllProcesses in interface SystemInfo
Returns:
list containing information on all processes currently running at the time the method was called

getProcesses

public List<ProcessInfo> getProcesses(String piq)
Description copied from interface: SystemInfo
Returns ProcessInfo objects for all processes that match the provided PIQL query string

Specified by:
getProcesses in interface SystemInfo
Parameters:
piq - the PIQL query string
Returns:
list containing process information

getThisProcess

public ProcessInfo getThisProcess()
Description copied from interface: SystemInfo
Returns the process information for the Java VM process this object is running in.

Specified by:
getThisProcess in interface SystemInfo
Returns:
this VM process's information

executeProcess

public ProcessExecutionResults executeProcess(ProcessExecution processExecution)
Description copied from interface: SystemInfo
Executes a process. The caller specifies the actual executable to run, the optional arguments to pass to the executable, the optional name=value set of environment variables the new process will have, the optional new working directory for the new process, the time (in milliseconds) to wait for the process to exit and the flag to indicate if the process's output should be captured and passed back in the returned results.

Specified by:
executeProcess in interface SystemInfo
Parameters:
processExecution - the settings on how to execute the process
Returns:
the results of the execution

getNumberOfCpus

public int getNumberOfCpus()
Description copied from interface: SystemInfo
Returns the number of CPUs on the hardware platform.

Specified by:
getNumberOfCpus in interface SystemInfo
Returns:
CPU count

getMemoryInfo

public org.hyperic.sigar.Mem getMemoryInfo()
Description copied from interface: SystemInfo
Returns information about memory installed on the platform.

Specified by:
getMemoryInfo in interface SystemInfo
Returns:
memory information

getSwapInfo

public org.hyperic.sigar.Swap getSwapInfo()
Description copied from interface: SystemInfo
Returns information about the virtual, swap memory installed on the platform.

Specified by:
getSwapInfo in interface SystemInfo
Returns:
swap information

readLineFromConsole

public String readLineFromConsole(boolean noEcho)
                           throws IOException
Description copied from interface: SystemInfo
Reads a line of input from the console and returns that line as a string. You can ask the implementation to not echo what the user typed into the console by passing true as the value to noEcho. noEcho is a hint and not guaranteed to work since some implementations (like the Java-only fallback implementation) will not be able to stop the console from echoing input.

Specified by:
readLineFromConsole in interface SystemInfo
Parameters:
noEcho - if true, the implementation should try to not echo the input to the console
Returns:
the line read from the console input
Throws:
IOException - if failed to read console input

writeLineToConsole

public void writeLineToConsole(String line)
                        throws IOException
Description copied from interface: SystemInfo
Writes a line of output to the console. This method does not output any newline characters - if you wish to end the output with a newline character, you must append it to the end of line.

Specified by:
writeLineToConsole in interface SystemInfo
Throws:
IOException

getCpu

public CpuInformation getCpu(int cpuIndex)
Description copied from interface: SystemInfo
Returns information about a specified CPU installed on the hardware where the JVM is running.

Specified by:
getCpu in interface SystemInfo
Parameters:
cpuIndex - identifies the CPU whose information is to be returned; on a single-CPU system, the index must be 0.
Returns:
information on the CPU

getFileSystems

public List<FileSystemInfo> getFileSystems()
Description copied from interface: SystemInfo
Returns information on all mounted file systems.

Specified by:
getFileSystems in interface SystemInfo
Returns:
list of all file systems on the platform

getFileSystem

public FileSystemInfo getFileSystem(String path)
Description copied from interface: SystemInfo
Returns information on the mounted file system that hosts the given file or directory.

Specified by:
getFileSystem in interface SystemInfo
Parameters:
path - the file or directory whose mounted file system should be returned
Returns:
the file system where the given file or directory is hosted

getSystemArchitecture

public String getSystemArchitecture()
Description copied from interface: SystemInfo
Returns the architecture of the underlying hardware

Specified by:
getSystemArchitecture in interface SystemInfo
Returns:


Copyright © 2008-2009 RHQ Project Advisory Board (Red Hat, Inc.). All Rights Reserved.