Class SystemManagerWin32

java.lang.Object
  extended by SystemManager
      extended by SystemManagerWin32

public class SystemManagerWin32
extends SystemManager

Windows (32-bit) implementation of SystemManager.

Noone should now about this class unless one intends to port it to another operating system.

Use SystemManager.getSystemManager to get OS-specific implementation.

It is important to note here that 32-bit Windows API is used to poll the status information, hence may return unpredictable information on 64-bit systems. This limitation is only due to MinGW32 compiler dependency (which happened not to have 64-bit Windows API headers), otherwise it should be easy to adjust the library implementation for 64-bit API calls.

See Also:
SystemManager

Constructor Summary
SystemManagerWin32()
           
 
Method Summary
 void closeProcessHandle(int hProcess)
          Closes a process handle (which was opened by openProcessHandle).
 int fetchProcessIDs(int[] pids)
          Fills the integer array with PIDs (process identifiers) of currently running processes.
 boolean fetchProcessStatus(int hProcess, ProcessStatus ps)
          Fills the ps structure with process status information.
 boolean fetchSystemMemoryStatus(SystemMemoryStatus sms)
          Fills the sms structure with system memory status information.
 String getProcessName(int hProcess)
          Retrieves the name of executable referenced by process handle.
static void main(String[] args)
          This is a sample test of this class.
 int openProcessHandle(int processID)
          Opens a handle to a process with given identifier.
 
Methods inherited from class SystemManager
getProcessStatus, getSystemManager, getSystemMemoryStatus, loadTmpLibrary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SystemManagerWin32

public SystemManagerWin32()
Method Detail

fetchSystemMemoryStatus

public boolean fetchSystemMemoryStatus(SystemMemoryStatus sms)
Description copied from class: SystemManager
Fills the sms structure with system memory status information. The method call may fail due to sms being null, or for technical implementation reasons. sms structure will not reflect the system status if the call fails.

Specified by:
fetchSystemMemoryStatus in class SystemManager
Parameters:
sms - the SystemMemoryStatus object, should not be null.
Returns:
true if successfull, otherwise false.
See Also:
SystemMemoryStatus

fetchProcessStatus

public boolean fetchProcessStatus(int hProcess,
                                  ProcessStatus ps)
Description copied from class: SystemManager
Fills the ps structure with process status information. After the succesfull call, ps structure reflects the status information about given process. The call may fail due to bad handle, ps being null or other technical implementation reasons (e.g. security).

Specified by:
fetchProcessStatus in class SystemManager
Parameters:
hProcess - (OS specific) handle to a process, created from openProcessHandle.
ps - ProcessStatus object, should not be null.
Returns:
true if successfull, otherwise false.
See Also:
SystemManager.openProcessHandle(int), ProcessStatus

openProcessHandle

public int openProcessHandle(int processID)
Description copied from class: SystemManager
Opens a handle to a process with given identifier. Some OSs (e.g. Windows) provide access to process information through handles, which is a nice feature since it keeps the status information available even if the process has terminated. The handle should be closed with closeProcessHandle when it's no longer needed.

Specified by:
openProcessHandle in class SystemManager
Parameters:
processID - (host OS specific) process identifier.
Returns:
integer representing process handle upon success, 0 otherwise.
See Also:
SystemManager.closeProcessHandle(int)

closeProcessHandle

public void closeProcessHandle(int hProcess)
Description copied from class: SystemManager
Closes a process handle (which was opened by openProcessHandle).

Specified by:
closeProcessHandle in class SystemManager
Parameters:
hProcess - the open process handle.
See Also:
SystemManager.openProcessHandle(int)

fetchProcessIDs

public int fetchProcessIDs(int[] pids)
Description copied from class: SystemManager
Fills the integer array with PIDs (process identifiers) of currently running processes. The array should not be null but initialized with a length of estimated maximum number of processes. It is difficult to predict exact number of running processes (this is the official position of Windows API) so the array should be large enough to incorporate them all. The excess PIDs will be trimmed, so if the return value is the same as the length of the array, then consider enlarging the array and calling again.

Specified by:
fetchProcessIDs in class SystemManager
Parameters:
pids - non-null array of integers to be filled with PIDs.
Returns:
the number of PIDs put into arrray.

getProcessName

public String getProcessName(int hProcess)
Description copied from class: SystemManager
Retrieves the name of executable referenced by process handle. The call may fail if invalid handle is given or there are technical problems (e.g. security obstacles) while retrieving the information.

Specified by:
getProcessName in class SystemManager
Parameters:
hProcess - is a handle to a process created by openProcessHandle.
Returns:
the name of a process executable upon success, null otherwise.

main

public static void main(String[] args)
This is a sample test of this class.



© 2007 Marius Mikucionis