Browse Source

CORE-76 Activator重复启动内置服务器、切换环境的支持

右上角的服务器开启关闭状态
master
ju 7 years ago
parent
commit
5230b3ff28
  1. 53
      designer-base/src/com/fr/start/server/FineEmbedServer.java
  2. 37
      designer-base/src/com/fr/start/server/ServerTray.java

53
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.log.FineLoggerFactory;
import com.fr.module.ModuleRole; import com.fr.module.ModuleRole;
import com.fr.stable.lifecycle.AbstractLifecycle; 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.startup.FineWebApplicationInitializer;
import com.fr.third.springframework.web.SpringServletContainerInitializer; import com.fr.third.springframework.web.SpringServletContainerInitializer;
import com.fr.third.springframework.web.context.support.AnnotationConfigWebApplicationContext; import com.fr.third.springframework.web.context.support.AnnotationConfigWebApplicationContext;
@ -21,12 +24,14 @@ import java.util.Set;
/** /**
* Created by juhaoyu on 2018/6/5. * Created by juhaoyu on 2018/6/5.
*/ */
public class FineEmbedServer extends AbstractLifecycle { public class FineEmbedServer {
private static final FineEmbedServer INSTANCE = new FineEmbedServer(); private static final FineEmbedServer INSTANCE = new FineEmbedServer();
private Tomcat tomcat; private Tomcat tomcat;
private volatile boolean isRunning = false;
public static FineEmbedServer getInstance() { public static FineEmbedServer getInstance() {
return INSTANCE; return INSTANCE;
@ -34,9 +39,12 @@ public class FineEmbedServer extends AbstractLifecycle {
private FineEmbedServer() {} private FineEmbedServer() {}
@Override
protected synchronized void executeStart() { public void start() {
if (isRunning) {
return;
}
EventDispatcher.fire(EmbedServerEvent.BeforeStart); EventDispatcher.fire(EmbedServerEvent.BeforeStart);
try { try {
//初始化tomcat //初始化tomcat
@ -45,9 +53,33 @@ public class FineEmbedServer extends AbstractLifecycle {
} catch (LifecycleException e) { } catch (LifecycleException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
isRunning = true;
EventDispatcher.fire(EmbedServerEvent.AfterStart); 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() { private void initTomcat() {
tomcat = new Tomcat(); tomcat = new Tomcat();
@ -67,22 +99,9 @@ public class FineEmbedServer extends AbstractLifecycle {
context.addServletContainerInitializer(initializer, classes); 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() { private void stopServerActivator() {
ModuleRole.ServerRoot.stop(); ModuleRole.ServerRoot.stop();
} }

37
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.BaseUtils;
import com.fr.base.FRContext; 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 com.fr.general.Inter;
import java.awt.*; import java.awt.*;
@ -28,12 +31,13 @@ public class ServerTray {
private ServerManageFrame serverManageFrame; private ServerManageFrame serverManageFrame;
private TrayIcon trayIcon; private TrayIcon trayIcon;
public ServerTray() { private ServerTray() {
//p:首先构建右键菜单 listen();
PopupMenu popup = new PopupMenu(); //p:首先构建右键菜单
PopupMenu popup = new PopupMenu();
MenuItem manangeMenu = new MenuItem(Inter.getLocText("Server-Open_Service_Manager")); MenuItem manangeMenu = new MenuItem(Inter.getLocText("Server-Open_Service_Manager"));
manangeMenu.addActionListener(new ActionListener() { manangeMenu.addActionListener(new ActionListener() {
@ -117,8 +121,22 @@ public class ServerTray {
checkPopupMenuItemEnabled(); 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(); FineEmbedServer.getInstance().stop();
SystemTray.getSystemTray().remove(trayIcon); SystemTray.getSystemTray().remove(trayIcon);
@ -150,5 +168,6 @@ public class ServerTray {
public static void init() { public static void init() {
INSTANCE = new ServerTray(); INSTANCE = new ServerTray();
}
}
} }
Loading…
Cancel
Save