Browse Source

Merge pull request #83 in DESIGN/design from ~JU/design:feature/10.0 to feature/10.0

* commit '5230b3ff28c2bd6468bf52b6716581b3491a25de':
  CORE-76 Activator重复启动内置服务器、切换环境的支持 右上角的服务器开启关闭状态
master
superman 7 years ago
parent
commit
52cde471ab
  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.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();
}

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.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();
}
}
}
Loading…
Cancel
Save