1. youhua
This commit is contained in:
parent
40e1932f0c
commit
0091075137
|
@ -1,13 +1,12 @@
|
||||||
package org.aohe;
|
package org.aohe;
|
||||||
|
|
||||||
import com.formdev.flatlaf.FlatDarkLaf;
|
import com.formdev.flatlaf.FlatDarculaLaf;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aohe.core.sane.utils.SaneSessionUtils;
|
import org.aohe.core.sane.utils.SaneSessionUtils;
|
||||||
import org.aohe.core.swing.MainWindow;
|
import org.aohe.core.swing.NewWindow;
|
||||||
import org.aohe.core.utils.CommandUtils;
|
import org.aohe.core.utils.CommandUtils;
|
||||||
import org.aohe.core.utils.SystemUtils;
|
import org.aohe.core.utils.SystemUtils;
|
||||||
import org.aohe.core.web.SocketFactory;
|
import org.aohe.core.web.SocketFactory;
|
||||||
import com.formdev.flatlaf.FlatLightLaf;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
@ -19,13 +18,13 @@ public class Main {
|
||||||
try {
|
try {
|
||||||
//设置窗口主题
|
//设置窗口主题
|
||||||
//FlatLightLaf.setup();
|
//FlatLightLaf.setup();
|
||||||
UIManager.setLookAndFeel(new FlatDarkLaf());
|
UIManager.setLookAndFeel(new FlatDarculaLaf());
|
||||||
} catch (UnsupportedLookAndFeelException e) {
|
} catch (UnsupportedLookAndFeelException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
//初始化其他资源
|
//初始化其他资源
|
||||||
init();
|
init();
|
||||||
SwingUtilities.invokeLater(() -> new MainWindow().setVisible(true));
|
SwingUtilities.invokeLater(() -> new NewWindow().setVisible(true));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ public class NewWindow extends JFrame {
|
||||||
|
|
||||||
private static JTextArea logTextArea;
|
private static JTextArea logTextArea;
|
||||||
|
|
||||||
|
private static final JLabel textField = new JLabel();
|
||||||
|
|
||||||
public NewWindow() {
|
public NewWindow() {
|
||||||
// 设置窗口标题
|
// 设置窗口标题
|
||||||
setTitle("扫描前端");
|
setTitle("扫描前端");
|
||||||
|
@ -30,7 +32,6 @@ public class NewWindow extends JFrame {
|
||||||
|
|
||||||
private void initializeComponents() {
|
private void initializeComponents() {
|
||||||
|
|
||||||
JLabel textField = new JLabel();
|
|
||||||
textField.setForeground(Color.GRAY);
|
textField.setForeground(Color.GRAY);
|
||||||
textField.setText("服务状态:启动中...");
|
textField.setText("服务状态:启动中...");
|
||||||
|
|
||||||
|
@ -43,12 +44,16 @@ public class NewWindow extends JFrame {
|
||||||
stopButton.addActionListener(e -> {
|
stopButton.addActionListener(e -> {
|
||||||
stopButton.setEnabled(false);
|
stopButton.setEnabled(false);
|
||||||
logTextArea.append("关闭服务中...\n");
|
logTextArea.append("关闭服务中...\n");
|
||||||
//开个新线程关闭,防止主UI线程卡死
|
//开个新线程关闭,防止主UI线程卡死
|
||||||
stopSocket();
|
new Thread( () ->{
|
||||||
textField.setForeground(Color.RED);
|
stopSocket();
|
||||||
textField.setText("服务状态:关闭");
|
//关闭任务
|
||||||
//关闭任务
|
sleep(1000);
|
||||||
System.exit(0);
|
textField.setForeground(Color.RED);
|
||||||
|
textField.setText("服务状态:关闭");
|
||||||
|
sleep(100);
|
||||||
|
System.exit(0);
|
||||||
|
} ).start();
|
||||||
});
|
});
|
||||||
|
|
||||||
getContentPane().add(textField, BorderLayout.NORTH);
|
getContentPane().add(textField, BorderLayout.NORTH);
|
||||||
|
@ -64,6 +69,8 @@ public class NewWindow extends JFrame {
|
||||||
public void initSocket() {
|
public void initSocket() {
|
||||||
if(SocketFactory.start()){
|
if(SocketFactory.start()){
|
||||||
setView("socket 服务启动成功");
|
setView("socket 服务启动成功");
|
||||||
|
textField.setForeground(Color.GREEN);
|
||||||
|
textField.setText("服务状态:启动");
|
||||||
}else{
|
}else{
|
||||||
setView("socket 服务启动失败,请检查8997端口是否被占用");
|
setView("socket 服务启动失败,请检查8997端口是否被占用");
|
||||||
}
|
}
|
||||||
|
@ -104,7 +111,11 @@ public class NewWindow extends JFrame {
|
||||||
getContentPane().add(scrollPane, BorderLayout.CENTER);
|
getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void sleep(long m){
|
||||||
SwingUtilities.invokeLater(() -> new NewWindow().setVisible(true));
|
try {
|
||||||
|
Thread.sleep(m);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ public class CommandUtils {
|
||||||
public static void killUsedPort(String port){
|
public static void killUsedPort(String port){
|
||||||
List<LsofInfo> lsofInfos = findPort(port);
|
List<LsofInfo> lsofInfos = findPort(port);
|
||||||
for(LsofInfo lsofInfo : lsofInfos){
|
for(LsofInfo lsofInfo : lsofInfos){
|
||||||
|
log.info(" pro kill begin {}", lsofInfo);
|
||||||
destroy(lsofInfo.getPid());
|
destroy(lsofInfo.getPid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,12 +72,14 @@ public class CommandUtils {
|
||||||
public static List<LsofInfo> findPort(String port){
|
public static List<LsofInfo> findPort(String port){
|
||||||
String exec = StrUtil.format("lsof -i:{}",port);
|
String exec = StrUtil.format("lsof -i:{}",port);
|
||||||
String s = execForStrUtf8Sudo(exec);
|
String s = execForStrUtf8Sudo(exec);
|
||||||
|
log.info(s);
|
||||||
return parseCommandOutput(s);
|
return parseCommandOutput(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void destroy(String pid){
|
public static void destroy(String pid){
|
||||||
String exec = StrUtil.format("kill -9 {}",pid);
|
String exec = StrUtil.format("kill -9 {}",pid);
|
||||||
execForStrUtf8Sudo(exec);
|
String s = execForStrUtf8Sudo(exec);
|
||||||
|
log.info(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue