From 5230b3ff28c2bd6468bf52b6716581b3491a25de Mon Sep 17 00:00:00 2001 From: ju Date: Wed, 6 Jun 2018 15:41:07 +0800 Subject: [PATCH] =?UTF-8?q?CORE-76=20Activator=E9=87=8D=E5=A4=8D=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=86=85=E7=BD=AE=E6=9C=8D=E5=8A=A1=E5=99=A8=E3=80=81?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E7=8E=AF=E5=A2=83=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20=E5=8F=B3=E4=B8=8A=E8=A7=92=E7=9A=84=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E5=BC=80=E5=90=AF=E5=85=B3=E9=97=AD=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/start/server/FineEmbedServer.java | 53 +++++++++++++------ .../src/com/fr/start/server/ServerTray.java | 37 +++++++++---- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/designer-base/src/com/fr/start/server/FineEmbedServer.java b/designer-base/src/com/fr/start/server/FineEmbedServer.java index 64201f9c4c..effef1bb7e 100644 --- a/designer-base/src/com/fr/start/server/FineEmbedServer.java +++ b/designer-base/src/com/fr/start/server/FineEmbedServer.java @@ -6,6 +6,9 @@ import com.fr.event.EventDispatcher; import com.fr.log.FineLoggerFactory; import com.fr.module.ModuleRole; import com.fr.stable.lifecycle.AbstractLifecycle; +import com.fr.stable.lifecycle.Lifecycle; +import com.fr.stable.lifecycle.LifecycleEvent; +import com.fr.stable.lifecycle.LifecycleListener; import com.fr.startup.FineWebApplicationInitializer; import com.fr.third.springframework.web.SpringServletContainerInitializer; import com.fr.third.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -21,12 +24,14 @@ import java.util.Set; /** * Created by juhaoyu on 2018/6/5. */ -public class FineEmbedServer extends AbstractLifecycle { +public class FineEmbedServer { private static final FineEmbedServer INSTANCE = new FineEmbedServer(); private Tomcat tomcat; + private volatile boolean isRunning = false; + public static FineEmbedServer getInstance() { return INSTANCE; @@ -34,9 +39,12 @@ public class FineEmbedServer extends AbstractLifecycle { private FineEmbedServer() {} - @Override - protected synchronized void executeStart() { + + public void start() { + if (isRunning) { + return; + } EventDispatcher.fire(EmbedServerEvent.BeforeStart); try { //初始化tomcat @@ -45,9 +53,33 @@ public class FineEmbedServer extends AbstractLifecycle { } catch (LifecycleException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } + isRunning = true; EventDispatcher.fire(EmbedServerEvent.AfterStart); } + public void stop() { + + if (!isRunning) { + return; + } + EventDispatcher.fire(EmbedServerEvent.BeforeStop); + try { + stopSpring(); + stopServerActivator(); + stopTomcat(); + } catch (LifecycleException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + isRunning = false; + EventDispatcher.fire(EmbedServerEvent.AfterStop); + } + + public boolean isRunning() { + + return isRunning; + } + + private void initTomcat() { tomcat = new Tomcat(); @@ -67,22 +99,9 @@ public class FineEmbedServer extends AbstractLifecycle { context.addServletContainerInitializer(initializer, classes); } - @Override - protected synchronized void executeStop() { - - EventDispatcher.fire(EmbedServerEvent.BeforeStop); - try { - stopSpring(); - stopServerActivator(); - stopTomcat(); - } catch (LifecycleException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - EventDispatcher.fire(EmbedServerEvent.AfterStop); - } private void stopServerActivator() { - + ModuleRole.ServerRoot.stop(); } diff --git a/designer-base/src/com/fr/start/server/ServerTray.java b/designer-base/src/com/fr/start/server/ServerTray.java index 05e35a40f9..4598be3e0e 100644 --- a/designer-base/src/com/fr/start/server/ServerTray.java +++ b/designer-base/src/com/fr/start/server/ServerTray.java @@ -2,6 +2,9 @@ package com.fr.start.server; import com.fr.base.BaseUtils; import com.fr.base.FRContext; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.ListenerAdaptor; import com.fr.general.Inter; import java.awt.*; @@ -28,12 +31,13 @@ public class ServerTray { private ServerManageFrame serverManageFrame; private TrayIcon trayIcon; - - - public ServerTray() { - - //p:首先构建右键菜单 - PopupMenu popup = new PopupMenu(); + + + private ServerTray() { + + listen(); + //p:首先构建右键菜单 + PopupMenu popup = new PopupMenu(); MenuItem manangeMenu = new MenuItem(Inter.getLocText("Server-Open_Service_Manager")); manangeMenu.addActionListener(new ActionListener() { @@ -117,8 +121,22 @@ public class ServerTray { checkPopupMenuItemEnabled(); } - - private void exit() { + + private void listen() { + + ListenerAdaptor listenerAdaptor = new ListenerAdaptor() { + + @Override + protected void on(Event event) { + + checkPopupMenuItemEnabled(); + } + }; + EventDispatcher.listen(EmbedServerEvent.AfterStart, listenerAdaptor); + EventDispatcher.listen(EmbedServerEvent.AfterStop, listenerAdaptor); + } + + private void exit() { FineEmbedServer.getInstance().stop(); SystemTray.getSystemTray().remove(trayIcon); @@ -150,5 +168,6 @@ public class ServerTray { public static void init() { INSTANCE = new ServerTray(); - } + + } } \ No newline at end of file