Skip to content

Commit

Permalink
Issue #16 - added comments to main api
Browse files Browse the repository at this point in the history
  • Loading branch information
profesorfalken committed Sep 3, 2016
1 parent b0fe6a6 commit 5f5ebc7
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target/
/nbactions.xml
/nbactions.xml
/.classpath
/.project
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jprocesses</groupId>
<artifactId>jProcesses</artifactId>
<version>1.6.1</version>
<version>1.6.2</version>
<packaging>jar</packaging>

<name>jProcesses</name>
Expand Down
128 changes: 127 additions & 1 deletion src/main/java/org/jutils/jprocesses/JProcesses.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
import org.jutils.jprocesses.info.ProcessesService;
import org.jutils.jprocesses.model.JProcessesResponse;
import org.jutils.jprocesses.model.ProcessInfo;
import org.jutils.jprocesses.model.WindowsPriority;

import java.util.List;

/**
* Static class that gives access to Processes details.
* Class that gives access to Processes details.<p>
*
* JProcesses allows to interact with system processes. It is possible to
* list all alive processes, kill them or change the priority.
*
* @author Javier Garcia Alonso
*/
Expand All @@ -35,48 +39,170 @@ public class JProcesses {
private JProcesses() {
}

/**
* Gets the JProcesses instance.<br>
* This method creates a new instance each time.
*
* @return JProcesses instance
*/
public static JProcesses get() {
return new JProcesses();
}

/**
* Enables the fast mode. <br>In this mode JProcesses does not try to retrieve
* time consuming data as the use percentage or the owner of the process in Windows implementation.<br>
* <b>This flag has no effect in Linux implementation as it is fast enough</b>.
*
* @return JProcesses instance
*/
public JProcesses fastMode() {
this.fastMode = true;
return this;
}

/**
* Enables/disables the fast mode. <br>In this mode JProcesses does not try to retrieve
* time consuming data as the use percentage or the owner of the process in Windows implementation.<br>
* <b>This flag has no effect in Linux implementation as it is fast enough</b>.
*
* @param enabled boolean true or false
* @return JProcesses instance
*/
public JProcesses fastMode(boolean enabled) {
this.fastMode = enabled;
return this;
}

/**
* Return the list of processes running in the system.<br>
* For each process some information is retrieved:
* <li>PID</li>
* <li>Name</li>
* <li>Used memory</li>
* <li>Date/time</li>
* <li>Priority</li>
* [...]<p>
*
* For further details see {@link ProcessInfo}
*
* @return List of processes
*/
public List<ProcessInfo> listProcesses() {
return getService().getList(fastMode);
}

/**
* Return the list of processes that match with the provided name.<br>
* For each process some information is retrieved:
* <li>PID</li>
* <li>Name</li>
* <li>Used memory</li>
* <li>Date/time</li>
* <li>Priority</li>
* [...]<p>
*
* For further details see {@link ProcessInfo}
*
* @param name The name of the searched process
* @return List of found processes
*/
public List<ProcessInfo> listProcesses(String name) {
return getService().getList(name, fastMode);
}

/**
* Convenience static method that returns the list of processes
* that match with the provided name.<br>
* For each process some information is retrieved:
* <li>PID</li>
* <li>Name</li>
* <li>Used memory</li>
* <li>Date/time</li>
* <li>Priority</li>
* [...]<p>
*
* For further details see {@link ProcessInfo}
*
* @return List of found processes
*/
public static List<ProcessInfo> getProcessList() {
return getService().getList();
}

/**
* Convenience static method that returns the list of processes
* that match with the provided name.<br>
* For each process some information is retrieved:
* <li>PID</li>
* <li>Name</li>
* <li>Used memory</li>
* <li>Date/time</li>
* <li>Priority</li>
* [...]<p>
*
* For further details see {@link ProcessInfo}
*
* @param name The name of the searched process
* @return List of found processes
*/
public static List<ProcessInfo> getProcessList(String name) {
return getService().getList(name);
}

/**
* Static method that returns the information of a process<br>
* Some information is retrieved:
* <li>PID</li>
* <li>Name</li>
* <li>Used memory</li>
* <li>Date/time</li>
* <li>Priority</li>
* [...]<p>
*
* For further details see {@link ProcessInfo}
*
* @param name The pid of the searched process
* @return {@link JProcesses} object with the information of the process
*/
public static ProcessInfo getProcess(int pid) {
return getService().getProcess(pid);
}

/**
* Static method that kills a process abruptly (forced mode)<br>
*
* For further details see {@link ProcessInfo}
*
* @param pid The PID of the process to kill
* @return {@link JProcessesResponse} response object that contains information about the result of the operation
*/
public static JProcessesResponse killProcess(int pid) {
return getService().killProcess(pid);
}

/**
* Static method that kills a process, letting it the necessary time to finish<br>
* If the process does not finish with this method, try with the stronger killProcess()<p>
*
* For further details see {@link ProcessInfo}
*
* @param pid The PID of the process to kill
* @return {@link JProcessesResponse} response object that contains information about the result of the operation
*/
public static JProcessesResponse killProcessGracefully(int pid) {
return getService().killProcessGracefully(pid);
}

/**
* Static method that changes the priority of a process<br>
* If the process does not finish with this method, try with the stronger killProcess()<p>
*
* For further details see {@link ProcessInfo}
*
* @param newPriority integer with the new version. For windows you can use the helper constants at {@link WindowsPriority}
* @return {@link JProcessesResponse} response object that contains information about the result of the operation
*/
public static JProcessesResponse changePriority(int pid, int newPriority) {
return getService().changePriority(pid, newPriority);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,18 @@ abstract class AbstractProcessesService implements ProcessesService {

protected boolean fastMode = false;

@Override
public List<ProcessInfo> getList() {
return getList(null);
}

@Override
public List<ProcessInfo> getList(boolean fastMode) {
return getList(null, fastMode);
}

@Override
public List<ProcessInfo> getList(String name) {
return getList(name, false);
}

@Override
public List<ProcessInfo> getList(String name, boolean fastMode) {
this.fastMode = fastMode;
String rawData = getProcessesData(name);
Expand All @@ -56,12 +52,10 @@ public List<ProcessInfo> getList(String name, boolean fastMode) {
return buildInfoFromMap(mapList);
}

@Override
public JProcessesResponse killProcess(int pid) {
return kill(pid);
}

@Override
public JProcessesResponse killProcessGracefully(int pid) {
return killGracefully(pid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
*/
package org.jutils.jprocesses.info;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.jutils.jprocesses.model.JProcessesResponse;
import org.jutils.jprocesses.model.ProcessInfo;
Expand Down Expand Up @@ -121,7 +120,6 @@ protected JProcessesResponse killGracefully(int pid) {
return response;
}

@Override
public JProcessesResponse changePriority(int pid, int priority) {
JProcessesResponse response = new JProcessesResponse();
if (ProcessesUtils.executeCommandAndGetCode("renice", String.valueOf(priority),
Expand All @@ -131,12 +129,10 @@ public JProcessesResponse changePriority(int pid, int priority) {
return response;
}

@Override
public ProcessInfo getProcess(int pid) {
return getProcess (pid, false);
}

@Override
public ProcessInfo getProcess(int pid, boolean fastMode) {
this.fastMode = fastMode;
List<Map<String, String>> processList
Expand Down

0 comments on commit 5f5ebc7

Please sign in to comment.