|
@@ -1,485 +0,0 @@
|
|
|
-package com.leanwo.management;
|
|
|
|
|
-
|
|
|
|
|
-import java.awt.AWTEvent;
|
|
|
|
|
-import java.awt.AWTException;
|
|
|
|
|
-import java.awt.BorderLayout;
|
|
|
|
|
-import java.awt.GridBagConstraints;
|
|
|
|
|
-import java.awt.GridBagLayout;
|
|
|
|
|
-import java.awt.Image;
|
|
|
|
|
-import java.awt.Insets;
|
|
|
|
|
-import java.awt.Label;
|
|
|
|
|
-import java.awt.SystemTray;
|
|
|
|
|
-import java.awt.Toolkit;
|
|
|
|
|
-import java.awt.TrayIcon;
|
|
|
|
|
-import java.awt.event.ActionEvent;
|
|
|
|
|
-import java.awt.event.ActionListener;
|
|
|
|
|
-import java.awt.event.MouseAdapter;
|
|
|
|
|
-import java.awt.event.MouseEvent;
|
|
|
|
|
-import java.awt.event.WindowAdapter;
|
|
|
|
|
-import java.awt.event.WindowEvent;
|
|
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
|
|
-import java.io.File;
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.net.URL;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-import java.util.Timer;
|
|
|
|
|
-import java.util.TimerTask;
|
|
|
|
|
-
|
|
|
|
|
-import javax.imageio.ImageIO;
|
|
|
|
|
-import javax.swing.BorderFactory;
|
|
|
|
|
-import javax.swing.JButton;
|
|
|
|
|
-import javax.swing.JFrame;
|
|
|
|
|
-import javax.swing.JLabel;
|
|
|
|
|
-import javax.swing.JOptionPane;
|
|
|
|
|
-import javax.swing.JPanel;
|
|
|
|
|
-import javax.swing.SwingUtilities;
|
|
|
|
|
-
|
|
|
|
|
-import org.apache.commons.exec.CommandLine;
|
|
|
|
|
-import org.apache.commons.exec.DefaultExecuteResultHandler;
|
|
|
|
|
-import org.apache.commons.exec.DefaultExecutor;
|
|
|
|
|
-import org.apache.commons.exec.ExecuteWatchdog;
|
|
|
|
|
-import org.apache.commons.exec.PumpStreamHandler;
|
|
|
|
|
-import org.apache.commons.logging.Log;
|
|
|
|
|
-import org.apache.commons.logging.LogFactory;
|
|
|
|
|
-import org.leanwo.management.util.AutoUpdateService;
|
|
|
|
|
-import org.leanwo.management.util.SpringUtil;
|
|
|
|
|
-import org.springframework.http.HttpEntity;
|
|
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
|
|
-import org.springframework.http.MediaType;
|
|
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
|
|
-import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
|
|
|
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
|
|
-
|
|
|
|
|
-import com.leanwo.management.model.ApplicationSetting;
|
|
|
|
|
-import com.leanwo.management.model.ApplicationSettingCache;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * 服务器管理界面
|
|
|
|
|
- *
|
|
|
|
|
- * @author YangZhiJie
|
|
|
|
|
- *
|
|
|
|
|
- */
|
|
|
|
|
-public class ServerManagmentJFrame extends JFrame {
|
|
|
|
|
- private static Log logger = LogFactory.getLog(ServerManagmentJFrame.class);
|
|
|
|
|
-
|
|
|
|
|
- // 得到显示器屏幕的宽高
|
|
|
|
|
- private int width = Toolkit.getDefaultToolkit().getScreenSize().width;
|
|
|
|
|
- private int height = Toolkit.getDefaultToolkit().getScreenSize().height;
|
|
|
|
|
-
|
|
|
|
|
- // 定义窗体的宽高
|
|
|
|
|
- private int windowsWidth = 800;
|
|
|
|
|
- private int windowsHeight = 400;
|
|
|
|
|
-
|
|
|
|
|
- private JPanel jPanel = null;
|
|
|
|
|
- private Timer timer;
|
|
|
|
|
-
|
|
|
|
|
- private TrayIcon trayIcon; // 托盘图标
|
|
|
|
|
- private SystemTray systemTray; // 系统托盘
|
|
|
|
|
-
|
|
|
|
|
- private Map<ApplicationSetting, JLabel> statusLabels = null;
|
|
|
|
|
- private ApplicationSettingCache applicationSettingCache;
|
|
|
|
|
- private boolean isRunning = false;
|
|
|
|
|
-
|
|
|
|
|
- public ServerManagmentJFrame(boolean isAutoRun) {
|
|
|
|
|
- this.setLayout(new BorderLayout());
|
|
|
|
|
-
|
|
|
|
|
- jPanel = new JPanel(new GridBagLayout());
|
|
|
|
|
- this.add(jPanel, BorderLayout.NORTH);
|
|
|
|
|
-
|
|
|
|
|
- this.setTitle("Prodog程序管理器");
|
|
|
|
|
- // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设定按关闭时的操作,这里是关闭窗口,如果不设定,就什么也不会发生
|
|
|
|
|
-
|
|
|
|
|
- //激活窗口事件
|
|
|
|
|
- this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);
|
|
|
|
|
-
|
|
|
|
|
- // 设置窗体位置和大小
|
|
|
|
|
- this.setBounds((width - windowsWidth) / 2, (height - windowsHeight) / 2, windowsWidth, windowsHeight);
|
|
|
|
|
-
|
|
|
|
|
- statusLabels = new HashMap<ApplicationSetting, JLabel>();
|
|
|
|
|
-
|
|
|
|
|
- generateViewFromJson();
|
|
|
|
|
-
|
|
|
|
|
- this.setVisible(true); // 显示,如果不设置就什么都看不到
|
|
|
|
|
-
|
|
|
|
|
- timer = new Timer();
|
|
|
|
|
- timer.schedule(timerTimerTask, 2000L, 2000L);
|
|
|
|
|
-
|
|
|
|
|
- // 判断当前平台是否支持系统托盘
|
|
|
|
|
- if(SystemTray.isSupported()) {
|
|
|
|
|
- // 获得系统托盘的实例
|
|
|
|
|
- systemTray = SystemTray.getSystemTray();
|
|
|
|
|
- try {
|
|
|
|
|
- URL path = ServerManagmentJFrame.class.getResource("prodog_16.png");
|
|
|
|
|
- Image imgae = ImageIO.read(path);
|
|
|
|
|
- trayIcon = new TrayIcon(imgae);
|
|
|
|
|
- trayIcon.displayMessage("通知:", "程序最小化到系统托盘", TrayIcon.MessageType.INFO);
|
|
|
|
|
- // 设置托盘的图标
|
|
|
|
|
- systemTray.add(trayIcon);
|
|
|
|
|
-
|
|
|
|
|
- trayIcon.addMouseListener(new MouseAdapter() {
|
|
|
|
|
- public void mouseClicked(MouseEvent e) {
|
|
|
|
|
- // 双击托盘窗口再现
|
|
|
|
|
- if (e.getClickCount() == 2) {
|
|
|
|
|
- boolean visible = isVisible();
|
|
|
|
|
- // setExtendedState(Frame.NORMAL);
|
|
|
|
|
- setVisible(!visible);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- this.addWindowListener(new WindowAdapter() {
|
|
|
|
|
- public void windowIconified(WindowEvent e) {
|
|
|
|
|
- // 窗口最小化时
|
|
|
|
|
- setVisible(false);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- } catch (IOException e1) {
|
|
|
|
|
- e1.printStackTrace();
|
|
|
|
|
- } catch (AWTException e2) {
|
|
|
|
|
- e2.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 程序自动运行
|
|
|
|
|
- if(isAutoRun) {
|
|
|
|
|
- autoStart();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //重写这个方法
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void processWindowEvent(WindowEvent e) {
|
|
|
|
|
- if (e.getID() == WindowEvent.WINDOW_CLOSING) {
|
|
|
|
|
- setVisible(false);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- super.processWindowEvent(e); //该语句会执行窗口事件的默认动作(如:隐藏)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void generateViewFromJson() {
|
|
|
|
|
- GridBagConstraints constrains = null;
|
|
|
|
|
-
|
|
|
|
|
- JLabel label = new JLabel("程序");
|
|
|
|
|
- label.setBorder(BorderFactory.createEtchedBorder());
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 0;
|
|
|
|
|
- constrains.gridy = 0;
|
|
|
|
|
- constrains.weightx = 25;
|
|
|
|
|
- constrains.anchor = GridBagConstraints.NORTH;
|
|
|
|
|
- jPanel.add(label, constrains);
|
|
|
|
|
-
|
|
|
|
|
- label = new JLabel("状态");
|
|
|
|
|
- label.setBorder(BorderFactory.createEtchedBorder());
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 1;
|
|
|
|
|
- constrains.gridy = 0;
|
|
|
|
|
- constrains.weightx = 25;
|
|
|
|
|
- constrains.anchor = GridBagConstraints.NORTH;
|
|
|
|
|
- jPanel.add(label, constrains);
|
|
|
|
|
-
|
|
|
|
|
- label = new JLabel("启动");
|
|
|
|
|
- label.setBorder(BorderFactory.createEtchedBorder());
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 2;
|
|
|
|
|
- constrains.gridy = 0;
|
|
|
|
|
- constrains.weightx = 10;
|
|
|
|
|
- constrains.anchor = GridBagConstraints.NORTH;
|
|
|
|
|
- jPanel.add(label, constrains);
|
|
|
|
|
-
|
|
|
|
|
- label = new JLabel("关闭");
|
|
|
|
|
- label.setBorder(BorderFactory.createEtchedBorder());
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 3;
|
|
|
|
|
- constrains.gridy = 0;
|
|
|
|
|
- constrains.weightx = 10;
|
|
|
|
|
- constrains.anchor = GridBagConstraints.NORTH;
|
|
|
|
|
- jPanel.add(label, constrains);
|
|
|
|
|
-
|
|
|
|
|
- label = new JLabel("检查更新");
|
|
|
|
|
- label.setBorder(BorderFactory.createEtchedBorder());
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 4;
|
|
|
|
|
- constrains.gridy = 0;
|
|
|
|
|
- constrains.weightx = 10;
|
|
|
|
|
- constrains.anchor = GridBagConstraints.NORTH;
|
|
|
|
|
- jPanel.add(label, constrains);
|
|
|
|
|
-
|
|
|
|
|
- label = new JLabel("修改配置");
|
|
|
|
|
- label.setBorder(BorderFactory.createEtchedBorder());
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 5;
|
|
|
|
|
- constrains.gridy = 0;
|
|
|
|
|
- constrains.weightx = 10;
|
|
|
|
|
- constrains.anchor = GridBagConstraints.NORTH;
|
|
|
|
|
- jPanel.add(label, constrains);
|
|
|
|
|
-
|
|
|
|
|
- applicationSettingCache = (ApplicationSettingCache) SpringUtil.getSingleBean(ApplicationSettingCache.class);
|
|
|
|
|
- List<ApplicationSetting> settings = applicationSettingCache.getSettings();
|
|
|
|
|
- if (settings != null && settings.size() > 0) {
|
|
|
|
|
- for(int i = 0; i < settings.size(); i ++) {
|
|
|
|
|
- int rowIndex = (i + 1);
|
|
|
|
|
- final ApplicationSetting setting = settings.get(i);
|
|
|
|
|
-
|
|
|
|
|
- label = new JLabel(setting.getName());
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(5, 5, 5, 5);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 0;
|
|
|
|
|
- constrains.gridy = rowIndex;
|
|
|
|
|
- constrains.weightx = 25;
|
|
|
|
|
- jPanel.add(label, constrains);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- label = new JLabel(setting.getStatus());
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(5, 5, 5, 5);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 1;
|
|
|
|
|
- constrains.gridy = rowIndex;
|
|
|
|
|
- constrains.weightx = 25;
|
|
|
|
|
- jPanel.add(label, constrains);
|
|
|
|
|
-
|
|
|
|
|
- statusLabels.put(setting, label);
|
|
|
|
|
-
|
|
|
|
|
- JButton startButton = new JButton("启动");
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(5, 5, 5, 5);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 2;
|
|
|
|
|
- constrains.gridy = rowIndex;
|
|
|
|
|
- constrains.weightx = 10;
|
|
|
|
|
- jPanel.add(startButton, constrains);
|
|
|
|
|
- startButton.addActionListener(new ActionListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
|
|
- try {
|
|
|
|
|
- String path = setting.getInstallPath() + File.separator + setting.getStartBatFile();
|
|
|
|
|
- ExecuteWatchdog executeWatchdog = runProcess(path);
|
|
|
|
|
- setting.setExecuteWatchdog(executeWatchdog);
|
|
|
|
|
- } catch (IOException e1) {
|
|
|
|
|
- e1.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- JButton stopButton = new JButton("停止");
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(5, 5, 5, 5);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 3;
|
|
|
|
|
- constrains.gridy = rowIndex;
|
|
|
|
|
- constrains.weightx = 10;
|
|
|
|
|
- jPanel.add(stopButton, constrains);
|
|
|
|
|
- stopButton.addActionListener(new ActionListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
|
|
- try {
|
|
|
|
|
- String path = setting.getInstallPath() + File.separator + setting.getStopBatFile();
|
|
|
|
|
- ExecuteWatchdog executeWatchdog = runProcess(path);
|
|
|
|
|
- setting.setExecuteWatchdog(null);
|
|
|
|
|
- } catch (IOException e1) {
|
|
|
|
|
- logger.error("程序启动失败", e1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- JButton checkUpdate = new JButton("检查更新");
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(5, 5, 5, 5);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 4;
|
|
|
|
|
- constrains.gridy = rowIndex;
|
|
|
|
|
- constrains.weightx = 10;
|
|
|
|
|
- jPanel.add(checkUpdate, constrains);
|
|
|
|
|
- checkUpdate.addActionListener(new ActionListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
|
|
- AutoUpdateService autoUpdateService = (AutoUpdateService) SpringUtil.getSingleBean(AutoUpdateService.class);
|
|
|
|
|
- if(autoUpdateService.canUpdate(setting)) {
|
|
|
|
|
- Object[] options = {"确定","取消"};
|
|
|
|
|
- int response = JOptionPane.showOptionDialog(null, "如果您确定要升级,请点击\'确定\'按钮,否则点击\'取消\'按钮", "确定是否升级", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
|
|
|
|
|
- if(response==0)
|
|
|
|
|
- {
|
|
|
|
|
- autoUpdateService.autoUpdate(setting);
|
|
|
|
|
- }
|
|
|
|
|
- }else {
|
|
|
|
|
- JOptionPane.showMessageDialog(null, "在服务器上未找到可更新的程序", "没有可更新的程序", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- JButton config = new JButton("配置");
|
|
|
|
|
- constrains = new GridBagConstraints();
|
|
|
|
|
- constrains.insets = new Insets(5, 5, 5, 5);
|
|
|
|
|
- constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
- constrains.gridx = 5;
|
|
|
|
|
- constrains.gridy = rowIndex;
|
|
|
|
|
- constrains.weightx = 10;
|
|
|
|
|
- jPanel.add(config, constrains);
|
|
|
|
|
- config.addActionListener(new ActionListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
|
|
- ServerSettingJFrame serverSettingJFrame = new ServerSettingJFrame(setting);
|
|
|
|
|
- serverSettingJFrame.setVisible(true);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 运行流程
|
|
|
|
|
- * @param command "cmd.exe /c start c://example.exe"
|
|
|
|
|
- * @return
|
|
|
|
|
- * @throws IOException
|
|
|
|
|
- */
|
|
|
|
|
- private ExecuteWatchdog runProcess(String command) throws IOException {
|
|
|
|
|
- if(command == null || command.length() == 0) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- logger.info("即将运行命令:" + command);
|
|
|
|
|
-
|
|
|
|
|
- final CommandLine cmdLine = CommandLine.parse(command);
|
|
|
|
|
-
|
|
|
|
|
- final ExecuteWatchdog watchDog = new ExecuteWatchdog(Long.MAX_VALUE);
|
|
|
|
|
-
|
|
|
|
|
- final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
|
|
|
|
|
- DefaultExecutor executor = new DefaultExecutor();
|
|
|
|
|
- executor.setWatchdog(watchDog);
|
|
|
|
|
-
|
|
|
|
|
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
|
- executor.setStreamHandler(new PumpStreamHandler(baos, baos));
|
|
|
|
|
-
|
|
|
|
|
- executor.execute(cmdLine, resultHandler);
|
|
|
|
|
-
|
|
|
|
|
- //等待5秒。
|
|
|
|
|
- try {
|
|
|
|
|
- resultHandler.waitFor(2000);
|
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //这里开始的代码会被立即执行下去,因为上面的语句不会被阻塞。
|
|
|
|
|
- final String result = baos.toString().trim();
|
|
|
|
|
- logger.debug(result);//这个result就是ping输出的结果。如果是JAVA程序,抛出了异常,也被它获取。
|
|
|
|
|
- return watchDog;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 程序自动运行
|
|
|
|
|
- */
|
|
|
|
|
- private void autoStart() {
|
|
|
|
|
- List<ApplicationSetting> settings = applicationSettingCache.getSettings();
|
|
|
|
|
- if (settings != null && settings.size() > 0) {
|
|
|
|
|
- for(int i = 0; i < settings.size(); i ++) {
|
|
|
|
|
- final ApplicationSetting setting = settings.get(i);
|
|
|
|
|
- ExecuteWatchdog executeWatchdog;
|
|
|
|
|
- try {
|
|
|
|
|
- String path = setting.getInstallPath() + File.separator + setting.getStartBatFile();
|
|
|
|
|
- executeWatchdog = runProcess(path);
|
|
|
|
|
- if(executeWatchdog != null) {
|
|
|
|
|
- boolean isWatch = executeWatchdog.isWatching();
|
|
|
|
|
- if(! isWatch) {
|
|
|
|
|
- logger.error("程序" + setting.getName() + "启动失败");
|
|
|
|
|
- }
|
|
|
|
|
- setting.setExecuteWatchdog(executeWatchdog);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- logger.error("程序" + setting.getName() + "启动失败", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private TimerTask timerTimerTask = new TimerTask() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- if(isRunning) {
|
|
|
|
|
- logger.debug("上个定时程序还未运行完成,本次运行跳过");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- isRunning = true;
|
|
|
|
|
- List<ApplicationSetting> settings = applicationSettingCache.getSettings();
|
|
|
|
|
- if (settings != null && settings.size() > 0) {
|
|
|
|
|
- for(int i = 0; i < settings.size(); i ++) {
|
|
|
|
|
- final ApplicationSetting setting = settings.get(i);
|
|
|
|
|
- JLabel statusLabel = statusLabels.get(setting);
|
|
|
|
|
- if(statusLabel != null) {
|
|
|
|
|
- /*
|
|
|
|
|
- ExecuteWatchdog executeWatchdog = setting.getExecuteWatchdog();
|
|
|
|
|
- if(executeWatchdog == null) {
|
|
|
|
|
- statusLabel.setText("未运行");
|
|
|
|
|
- }else{
|
|
|
|
|
- if(executeWatchdog.isWatching()) {
|
|
|
|
|
- statusLabel.setText("运行中");
|
|
|
|
|
- }else {
|
|
|
|
|
- statusLabel.setText("已停止");
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
- // 监控各个服务程序是否正在运行
|
|
|
|
|
- String status = null;
|
|
|
|
|
- String url = setting.getMonitorUrl();
|
|
|
|
|
- String token = setting.getToken();
|
|
|
|
|
- if(url == null || "".equals(url) || token == null || "".equals(token)){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
- restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
|
|
- headers.add("account", "2");
|
|
|
|
|
- headers.add("token", token);
|
|
|
|
|
- HttpEntity entity = new HttpEntity(headers);
|
|
|
|
|
- try{
|
|
|
|
|
- ResponseEntity<Long> response = restTemplate.exchange(url, HttpMethod.GET, entity, Long.class);
|
|
|
|
|
- ((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(1000*30);
|
|
|
|
|
- ((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(1000*30);
|
|
|
|
|
- Long result = response.getBody();
|
|
|
|
|
- long mills = new Date().getTime() - result;
|
|
|
|
|
- status = "运行中(" + mills + "ms)";
|
|
|
|
|
- }catch(Exception ex){
|
|
|
|
|
- status = "已停止";
|
|
|
|
|
- }
|
|
|
|
|
- updateStatus(statusLabel, status);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- isRunning = false;
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 在其他线程更新状态Label的文本
|
|
|
|
|
- * @param statusLabel
|
|
|
|
|
- * @param status
|
|
|
|
|
- */
|
|
|
|
|
- private void updateStatus(JLabel statusLabel, String status) {
|
|
|
|
|
- SwingUtilities.invokeLater(new Runnable() {
|
|
|
|
|
- public void run() {
|
|
|
|
|
- statusLabel.setText(status);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|