Zhou Rui 5 лет назад
Родитель
Сommit
4c1626794a

+ 1 - 1
o2server/start_linux.sh

@@ -1,4 +1,4 @@
-current_dir=$(cd "$(dirname "$0")"; pwd);
+current_dir=$(cd "$(dirname "$0")"; pwd);
 if [ -d ${current_dir}/local/update ]; then
 	if [ ! -d ${current_dir}/commons ]; then
 	mkdir ${current_dir}/commons

+ 85 - 19
o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/StringTools.java

@@ -13,6 +13,7 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Objects;
 import java.util.Random;
+import java.util.StringTokenizer;
 import java.util.UUID;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -336,25 +337,28 @@ public class StringTools {
 
 	public static boolean matchWildcard(String str, String pattern) {
 		return Objects.toString(str, "").matches(Objects.toString(pattern, "").replace("?", ".?").replace("*", ".*?"));
-//		if (StringUtils.isNotEmpty(str) && StringUtils.isNotEmpty(pattern) && StringUtils.contains(pattern, "*")) {
-//			if (StringUtils.equals(pattern, "*")) {
-//				return true;
-//			}
-//			if (StringUtils.startsWith(pattern, "*")) {
-//				return StringUtils.endsWith(str, StringUtils.substringAfter(pattern, "*"));
-//			}
-//			if (StringUtils.endsWith(pattern, "*")) {
-//				return StringUtils.startsWith(str, StringUtils.substringBeforeLast(pattern, "*"));
-//			}
-//			String[] parts = StringUtils.split(pattern, "*", 2);
-//			if (StringUtils.startsWith(str, parts[0]) && StringUtils.endsWith(str, parts[1])) {
-//				return true;
-//			} else {
-//				return false;
-//			}
-//		} else {
-//			return StringUtils.equals(str, pattern);
-//		}
+		// if (StringUtils.isNotEmpty(str) && StringUtils.isNotEmpty(pattern) &&
+		// StringUtils.contains(pattern, "*")) {
+		// if (StringUtils.equals(pattern, "*")) {
+		// return true;
+		// }
+		// if (StringUtils.startsWith(pattern, "*")) {
+		// return StringUtils.endsWith(str, StringUtils.substringAfter(pattern, "*"));
+		// }
+		// if (StringUtils.endsWith(pattern, "*")) {
+		// return StringUtils.startsWith(str, StringUtils.substringBeforeLast(pattern,
+		// "*"));
+		// }
+		// String[] parts = StringUtils.split(pattern, "*", 2);
+		// if (StringUtils.startsWith(str, parts[0]) && StringUtils.endsWith(str,
+		// parts[1])) {
+		// return true;
+		// } else {
+		// return false;
+		// }
+		// } else {
+		// return StringUtils.equals(str, pattern);
+		// }
 	}
 
 	public static List<String> includesExcludesWithWildcard(List<String> list, Collection<String> includes,
@@ -450,4 +454,66 @@ public class StringTools {
 		return false;
 	}
 
+	// copy from /org/apache/tools/ant/types/Commandline.java
+	public static String[] translateCommandline(String toProcess) throws Exception {
+		if (toProcess == null || toProcess.isEmpty()) {
+			// no command? no string
+			return new String[0];
+		}
+		// parse with a simple finite state machine
+
+		final int normal = 0;
+		final int inQuote = 1;
+		final int inDoubleQuote = 2;
+		int state = normal;
+		final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
+		final ArrayList<String> result = new ArrayList<>();
+		final StringBuilder current = new StringBuilder();
+		boolean lastTokenHasBeenQuoted = false;
+
+		while (tok.hasMoreTokens()) {
+			String nextTok = tok.nextToken();
+			switch (state) {
+				case inQuote:
+					if ("\'".equals(nextTok)) {
+						lastTokenHasBeenQuoted = true;
+						state = normal;
+					} else {
+						current.append(nextTok);
+					}
+					break;
+				case inDoubleQuote:
+					if ("\"".equals(nextTok)) {
+						lastTokenHasBeenQuoted = true;
+						state = normal;
+					} else {
+						current.append(nextTok);
+					}
+					break;
+				default:
+					if ("\'".equals(nextTok)) {
+						state = inQuote;
+					} else if ("\"".equals(nextTok)) {
+						state = inDoubleQuote;
+					} else if (" ".equals(nextTok)) {
+						if (lastTokenHasBeenQuoted || current.length() > 0) {
+							result.add(current.toString());
+							current.setLength(0);
+						}
+					} else {
+						current.append(nextTok);
+					}
+					lastTokenHasBeenQuoted = false;
+					break;
+			}
+		}
+		if (lastTokenHasBeenQuoted || current.length() > 0) {
+			result.add(current.toString());
+		}
+		if (state == inQuote || state == inDoubleQuote) {
+			throw new Exception("unbalanced quotes in " + toProcess);
+		}
+		return result.toArray(new String[result.size()]);
+	}
+
 }

+ 2 - 0
o2server/x_console/pom.xml

@@ -46,6 +46,7 @@
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-jar-plugin</artifactId>
+				<version>3.2.0</version>
 				<configuration>
 					<archive>
 						<manifest>
@@ -58,6 +59,7 @@
 			<plugin>
 				<groupId>com.coderplus.maven.plugins</groupId>
 				<artifactId>copy-rename-maven-plugin</artifactId>
+				<version>1.0.1</version>
 				<executions>
 					<execution>
 						<phase>verify</phase>

+ 5 - 4
o2server/x_console/src/main/java/com/x/server/console/CommandFactory.java

@@ -74,14 +74,14 @@ public class CommandFactory {
 
 	public static final Pattern show_http_thread_pattern = Pattern
 			.compile("^ {0,}show http thread ([1-9][0-9]*) ([1-9][0-9]*) {0,}$", Pattern.CASE_INSENSITIVE);
-//	public static final Pattern show_dataSource_pattern = Pattern
-//			.compile("^ {0,}show dataSource ([1-9][0-9]*) ([1-9][0-9]*) {0,}$", Pattern.CASE_INSENSITIVE);
 
 	public static final Pattern stack_pattern = Pattern.compile("^ {0,}stack ([1-9][0-9]*) ([1-9][0-9]*) (.+)$",
 			Pattern.CASE_INSENSITIVE);
 
 	public static final Pattern heapDump_pattern = Pattern.compile("^ {0,}heap dump (.+)$", Pattern.CASE_INSENSITIVE);
 
+	public static final Pattern debugDetailDisplay_pattern = Pattern.compile("^(\\s*)ddd(\\s*)", Pattern.CASE_INSENSITIVE);
+
 	public static void printStartHelp() {
 		try {
 			printStartImage();
@@ -127,8 +127,9 @@ public class CommandFactory {
 			help += " restore storage yyyyMMddHHmmss (passwd)" + "\t\t" + "restore storage to database,file.";
 			help += StringUtils.LF;
 			help += " setPassword (oldpasswd) (newpasswd)" + "\t\t\t" + "change initial manager password.";
-//			help += StringUtils.LF;
-//			help += " update (backup) (latest) (passwd)" + "\t\t\t" + "upgrade to new version.";
+			// help += StringUtils.LF;
+			// help += " update (backup) (latest) (passwd)" + "\t\t\t" + "upgrade to new
+			// version.";
 			help += StringUtils.LF;
 			help += " update file (path) (backup) (passwd)" + "\t\t\t" + "upgrade to new version from local zip file.";
 			help += StringUtils.LF;

+ 30 - 9
o2server/x_console/src/main/java/com/x/server/console/Main.java

@@ -20,14 +20,6 @@ import java.util.List;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.regex.Matcher;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang3.BooleanUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.eclipse.jetty.deploy.App;
-import org.eclipse.jetty.deploy.DeploymentManager;
-import org.quartz.Scheduler;
-
 import com.x.base.core.project.config.ApplicationServer;
 import com.x.base.core.project.config.CenterServer;
 import com.x.base.core.project.config.Config;
@@ -35,9 +27,11 @@ import com.x.base.core.project.config.DataServer;
 import com.x.base.core.project.config.StorageServer;
 import com.x.base.core.project.config.WebServer;
 import com.x.base.core.project.tools.DefaultCharset;
+import com.x.base.core.project.tools.StringTools;
 import com.x.server.console.action.ActionCompactData;
 import com.x.server.console.action.ActionConfig;
 import com.x.server.console.action.ActionCreateEncryptKey;
+import com.x.server.console.action.ActionDebugDetailDisplay;
 import com.x.server.console.action.ActionDumpData;
 import com.x.server.console.action.ActionDumpStorage;
 import com.x.server.console.action.ActionEraseContentBbs;
@@ -59,6 +53,14 @@ import com.x.server.console.action.ActionVersion;
 import com.x.server.console.log.LogTools;
 import com.x.server.console.server.Servers;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jetty.deploy.App;
+import org.eclipse.jetty.deploy.DeploymentManager;
+import org.quartz.Scheduler;
+
 public class Main {
 
 	private static final String MANIFEST_FILENAME = "manifest.cfg";
@@ -123,8 +125,9 @@ public class Main {
 						/** 在linux环境中当前端console窗口关闭后会导致可以立即read到一个null的input值 */
 						if (null != cmd) {
 							commandQueue.put(cmd);
+							continue;
 						}
-						Thread.sleep(4000);
+						Thread.sleep(5000);
 					}
 				} catch (Exception e) {
 					System.out.println("console input closed!");
@@ -369,6 +372,12 @@ public class Main {
 				continue;
 			}
 
+			matcher = CommandFactory.debugDetailDisplay_pattern.matcher(cmd);
+			if (matcher.find()) {
+				debugDetailDisplay(cmd);
+				continue;
+			}
+
 			matcher = CommandFactory.exit_pattern.matcher(cmd);
 			if (matcher.find()) {
 				exit();
@@ -730,6 +739,18 @@ public class Main {
 		}
 	}
 
+	
+	private static void debugDetailDisplay(String cmd) {
+		try {
+			String[] args = StringTools.translateCommandline(cmd);
+			args = Arrays.copyOfRange(args, 1, args.length);
+				ActionDebugDetailDisplay action = new ActionDebugDetailDisplay();
+				action.execute(args);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
 	private static void resotreStoragePath(String path, String password) {
 		try {
 			new ActionRestoreStorage().execute(path, password);

+ 3 - 1
o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java

@@ -244,8 +244,10 @@ public class ResourceFactory {
 	private static void processPlatformExecutors() throws Exception {
 		ExecutorService[] services = new ExecutorService[Config.processPlatform().getExecutorCount()];
 		for (int i = 0; i < Config.processPlatform().getExecutorCount(); i++) {
-			services[i] = Executors.newSingleThreadExecutor();
+			//services[i] = Executors.newSingleThreadExecutor();
+			services[i] = Executors.newFixedThreadPool(1);
 		}
+	
 		new Resource(Config.RESOURCE_NODE_PROCESSPLATFORMEXECUTORS, services);
 	}
 

+ 146 - 0
o2server/x_console/src/main/java/com/x/server/console/action/ActionDebugDetailDisplay.java

@@ -0,0 +1,146 @@
+package com.x.server.console.action;
+
+import java.lang.management.ManagementFactory;
+import com.sun.management.OperatingSystemMXBean;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import com.x.base.core.project.config.Config;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+
+public class ActionDebugDetailDisplay extends ActionBase {
+
+	private static Logger logger = LoggerFactory.getLogger(ActionShowMemory.class);
+
+	private static Options options;
+
+	private Date start;
+
+	private void init() throws Exception {
+		this.start = new Date();
+	}
+
+	public boolean execute(String... args) {
+		try {
+			this.init();
+			new Thread() {
+				public void run() {
+					try {
+						CommandLineParser parser = new DefaultParser();
+						CommandLine cmd = parser.parse(options(), args);
+						if (cmd.hasOption("ppe")) {
+							ppe(cmd);
+						} else if (cmd.hasOption("os")) {
+							os(cmd);
+						} else {
+							HelpFormatter formatter = new HelpFormatter();
+							formatter.printHelp("ddd (Debug Detail Display)", options);
+						}
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+			}.start();
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+
+	private Options options() {
+		if (null == options) {
+			options = new Options();
+			options.addOption(ppexeOption());
+			options.addOption(osOption());
+		}
+		return options;
+	}
+
+	private Option ppexeOption() {
+		Option opt = Option.builder("ppexe").desc("显示流程平台执行线程状态.").build();
+		return opt;
+	}
+
+	private Option osOption() {
+		Option opt = Option.builder("os").argName("repeat").optionalArg(true).hasArgs().type(Integer.class)
+				.desc("显示操作系统信息.").build();
+		return opt;
+	}
+
+	private void ppe(CommandLine cmd) throws Exception {
+		ExecutorService[] executorServices = Config.resource_node_processPlatformExecutors();
+		List<String> list = new ArrayList<>();
+		for (int i = 0; i < executorServices.length; i++) {
+			ExecutorService service = executorServices[i];
+			ThreadPoolExecutor executor = (ThreadPoolExecutor) service;
+			BlockingQueue<Runnable> queue = executor.getQueue();
+			list.add("processPlatform executorServices[" + i + "] completed: " + executor.getCompletedTaskCount()
+					+ ", block: " + queue.size() + ".");
+			if (!queue.isEmpty()) {
+				List<String> os = new ArrayList<>();
+				for (Runnable o : queue) {
+					os.add(o.getClass().toString());
+				}
+				list.add("\t┕blocking: " + StringUtils.join(os, ",") + ".");
+			}
+		}
+		System.out.println(StringUtils.join(list, StringUtils.LF));
+	}
+
+	private void os(CommandLine cmd) throws Exception {
+		Integer repeat = 10;
+		String r = cmd.getOptionValue("os", "10");
+		if (NumberUtils.isParsable(r)) {
+			repeat = NumberUtils.toInt(r);
+		}
+		if (repeat < 1 || repeat > 100) {
+			repeat = 10;
+		}
+		// final Integer interval_adjust = Math.min(Math.max(interval, 1), 20);
+		// final Integer repeat_repeat = Math.min(Math.max(repeat, 1), 200);
+		final Integer rpt = repeat;
+		new Thread() {
+			public void run() {
+				OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
+				try {
+					for (int i = 0; i < rpt; i++) {
+						StringBuffer buffer = new StringBuffer();
+						buffer.append("cpu:" + bean.getAvailableProcessors())
+								.append(", process load:" + percent(bean.getProcessCpuLoad()))
+								.append(", system load:" + percent(bean.getSystemCpuLoad()))
+								.append(". memory:").append(bean.getTotalPhysicalMemorySize() / (1024 * 1024))
+								.append("m, free:").append(bean.getFreePhysicalMemorySize() / (1024 * 1024))
+								.append("m, committed virtual:")
+								.append(bean.getCommittedVirtualMemorySize() / (1024 * 1024)).append("m.");
+						System.out.println(buffer.toString());
+						Thread.sleep(3000);
+					}
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+		}.start();
+	}
+
+	private String percent(Double d) {
+		return new Double((d * 100)).intValue() + "%";
+	}
+
+}