Reconstruct the codes.

This commit is contained in:
huanghongxun
2015-07-01 21:27:08 +08:00
parent dace6ab223
commit 67056f4849
84 changed files with 217 additions and 429 deletions

View File

@@ -10,7 +10,7 @@ import java.awt.Font;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.swing.UIManager;
import org.jackhuang.hellominecraft.utils.functions.DoneListener0;
import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.views.LogWindow;
import org.jackhuang.hellominecraft.svrmgr.settings.SettingsManager;
@@ -41,7 +41,7 @@ public class Main {
} catch (Throwable ex) {
HMCLog.warn("Failed to set look and feel", ex);
}
new UpdateChecker(new VersionNumber(firstVer, secondVer, thirdVer), "hmcsm", SettingsManager.settings.checkUpdate, new DoneListener0() {
new UpdateChecker(new VersionNumber(firstVer, secondVer, thirdVer), "hmcsm", SettingsManager.settings.checkUpdate, new NonConsumer() {
@Override
public void onDone() {

View File

@@ -25,10 +25,10 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.swing.JOptionPane;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.DigestUtils;
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
import org.jackhuang.hellominecraft.utils.FileUtils;
import org.jackhuang.hellominecraft.utils.IOUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.tasks.TaskWindow;

View File

@@ -24,7 +24,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.IOUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
import org.jackhuang.hellominecraft.utils.Pair;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.svrmgr.settings.Schedule;

View File

@@ -10,7 +10,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.Compressor;
import org.jackhuang.hellominecraft.utils.system.Compressor;
import org.jackhuang.hellominecraft.svrmgr.settings.SettingsManager;
import org.jackhuang.hellominecraft.svrmgr.utils.Utilities;

View File

@@ -5,7 +5,7 @@
package org.jackhuang.hellominecraft.svrmgr.utils;
import java.io.File;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
/**
*

View File

@@ -11,7 +11,7 @@ import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.StringTokenizer;
import com.sun.management.OperatingSystemMXBean;
import org.jackhuang.hellominecraft.utils.Bytes;
import org.jackhuang.hellominecraft.utils.StrUtils;
/**
*
@@ -33,6 +33,7 @@ public class MonitorServiceImpl implements IMonitorService {
* @throws Exception
* @author GuoHuang
*/
@Override
public MonitorInfoBean getMonitorInfoBean() throws Exception {
int kb = 1024;
// 可使用内存
@@ -78,7 +79,7 @@ public class MonitorServiceImpl implements IMonitorService {
InputStream is = null;
InputStreamReader isr = null;
BufferedReader brStat = null;
StringTokenizer tokenStat = null;
StringTokenizer tokenStat;
try {
System.out.println("Getting usage rate of CPU , linux version: " + linuxVersion);
Process process = Runtime.getRuntime().exec("top -b -n 1");
@@ -102,9 +103,9 @@ public class MonitorServiceImpl implements IMonitorService {
user = user.substring(0, user.indexOf("%"));
system = system.substring(0, system.indexOf("%"));
nice = nice.substring(0, nice.indexOf("%"));
float userUsage = new Float(user).floatValue();
float systemUsage = new Float(system).floatValue();
float niceUsage = new Float(nice).floatValue();
float userUsage = new Float(user);
float systemUsage = new Float(system);
float niceUsage = new Float(nice);
return (userUsage + systemUsage + niceUsage) / 100;
} else {
brStat.readLine();
@@ -120,7 +121,7 @@ public class MonitorServiceImpl implements IMonitorService {
String cpuUsage = tokenStat.nextToken();
System.out.println("CPU idle : " + cpuUsage);
Float usage = new Float(cpuUsage.substring(0, cpuUsage.indexOf("%")));
return (1 - usage.floatValue() / 100);
return (1 - usage / 100);
}
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
@@ -164,11 +165,11 @@ public class MonitorServiceImpl implements IMonitorService {
if (c0 != null && c1 != null) {
long idletime = c1[0] - c0[0];
long busytime = c1[1] - c0[1];
return Double.valueOf(PERCENT * (busytime) / (busytime + idletime)).doubleValue();
return (double) PERCENT * (busytime) / (busytime + idletime);
} else {
return 0.0;
}
} catch (Exception ex) {
} catch (IOException | InterruptedException ex) {
ex.printStackTrace();
return 0.0;
}
@@ -206,13 +207,13 @@ public class MonitorServiceImpl implements IMonitorService {
}
// 字段出现顺序Caption,CommandLine,KernelModeTime,ReadOperationCount,
// ThreadCount,UserModeTime,WriteOperation
String caption = Bytes.substring(line, capidx, cmdidx - 1).trim();
String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim();
if (cmd.indexOf("wmic.exe") >= 0) {
String caption = StrUtils.substring(line, capidx, cmdidx - 1).trim();
String cmd = StrUtils.substring(line, cmdidx, kmtidx - 1).trim();
if (cmd.contains("wmic.exe")) {
continue;
}
String s1 = Bytes.substring(line, kmtidx, rocidx - 1).trim();
String s2 = Bytes.substring(line, umtidx, wocidx - 1).trim();
String s1 = StrUtils.substring(line, kmtidx, rocidx - 1).trim();
String s2 = StrUtils.substring(line, umtidx, wocidx - 1).trim();
if (caption.equals("System Idle Process") || caption.equals("System")) {
if (s1.length() > 0) {
idletime += Long.parseLong(s1);
@@ -232,7 +233,7 @@ public class MonitorServiceImpl implements IMonitorService {
retn[0] = idletime;
retn[1] = kneltime + usertime;
return retn;
} catch (Exception ex) {
} catch (IOException | NumberFormatException ex) {
ex.printStackTrace();
} finally {
try {

View File

@@ -42,7 +42,7 @@ import org.jackhuang.hellominecraft.tasks.download.HTTPGetTask;
import org.jackhuang.hellominecraft.utils.FileUtils;
import org.jackhuang.hellominecraft.svrmgr.utils.IMonitorService;
import org.jackhuang.hellominecraft.utils.IOUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
import org.jackhuang.hellominecraft.svrmgr.utils.ModType;
import org.jackhuang.hellominecraft.svrmgr.utils.MonitorInfoBean;
import org.jackhuang.hellominecraft.svrmgr.utils.MonitorServiceImpl;