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