Browse Source

REPORT-10384 设计器预览启动假死问题,内置服务器提前启动

research/10.0
zack 6 years ago
parent
commit
a92ed2f840
  1. 3
      designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java
  2. 30
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java
  3. 12
      designer-base/src/main/java/com/fr/start/BaseDesigner.java
  4. 31
      designer-base/src/main/java/com/fr/start/ServerStarter.java
  5. 2
      designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java
  6. 89
      designer-base/src/main/java/com/fr/start/server/FineEmbedServerMonitor.java
  7. 9
      designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

3
designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java

@ -77,4 +77,7 @@ public class ProgressDialog extends UIDialog {
centerDialog.dispose();
super.dispose();
}
public void updateLoadingText(String text) {
this.text.setText(text);
}
}

30
designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java

@ -1153,4 +1153,34 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
return progressDialog;
}
public void showProgressDialog() {
progressDialog.setVisible(true);
}
/**
* 隐藏进度框
*/
public void hideProgressDialog() {
progressDialog.setVisible(false);
}
/**
* 更新进度框进度
* @param progress
*/
public void updateProgress(int progress) {
progressDialog.setProgressValue(progress);
}
/**
* 释放进度框
*/
public void disposeProgressDialog() {
progressDialog.dispose();
}
}

12
designer-base/src/main/java/com/fr/start/BaseDesigner.java

@ -31,6 +31,10 @@ import java.lang.reflect.Method;
* The main class of Report Designer.
*/
public abstract class BaseDesigner extends ToolBarMenuDock {
private static final int PERCENT_TEN = 10;
private static final int PERCENT_SIXTY = 60;
private static final int PERCENT_NINTY= 90;
private static final int PERCENT_COMPLETE= 100;
private static final int LOAD_TREE_MAXNUM = 10;
@ -51,15 +55,15 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
public void show(final String[] args) {
collectUserInformation();
DesignerContext.getDesignerFrame().getProgressDialog().setProgressValue(10);
DesignerContext.getDesignerFrame().updateProgress(PERCENT_TEN);
showDesignerFrame(args, DesignerContext.getDesignerFrame(), false);
DesignerContext.getDesignerFrame().getProgressDialog().setProgressValue(60);
DesignerContext.getDesignerFrame().updateProgress(PERCENT_SIXTY);
DesignerContext.getDesignerFrame().refreshEnv();
DesignerContext.getDesignerFrame().getProgressDialog().setProgressValue(90);
DesignerContext.getDesignerFrame().updateProgress(PERCENT_NINTY);
for (int i = 0; !TemplateTreePane.getInstance().getTemplateFileTree().isTemplateShowing() && i < LOAD_TREE_MAXNUM; i++) {
TemplateTreePane.getInstance().getTemplateFileTree().refresh();
}
DesignerContext.getDesignerFrame().getProgressDialog().setProgressValue(100);
DesignerContext.getDesignerFrame().updateProgress(PERCENT_COMPLETE);
}

31
designer-base/src/main/java/com/fr/start/ServerStarter.java

@ -5,20 +5,21 @@ import com.fr.base.ServerConfig;
import com.fr.design.DesignerEnvManager;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralContext;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.OperatingSystem;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.start.server.FineEmbedServer;
import com.fr.start.server.FineEmbedServerMonitor;
import com.fr.workspace.WorkContext;
import javax.swing.*;
import java.awt.*;
import javax.swing.JOptionPane;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ServerStarter {
@ -57,10 +58,24 @@ public class ServerStarter {
*
* @param url 指定路径
*/
public static void browserURLWithLocalEnv(String url) {
FineEmbedServer.start();
browser(url);
public static void browserURLWithLocalEnv(final String url) {
if(!FineEmbedServerMonitor.getInstance().isComplete()){
FineEmbedServerMonitor.getInstance().monitor();
ExecutorService service = Executors.newSingleThreadExecutor();
service.submit(new Runnable() {
@Override
public void run() {
FineEmbedServer.start();
browser(url);
}
});
service.shutdown();
}else{
FineEmbedServer.start();
browser(url);
}
}
private static void browser(String uri) {

2
designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java

@ -30,9 +30,11 @@ public class FineEmbedServerActivator extends Activator {
public synchronized void start() {
try {
FineEmbedServerMonitor.getInstance().reset();
//初始化tomcat
initTomcat();
tomcat.start();
FineEmbedServerMonitor.getInstance().setComplete();
} catch (LifecycleException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}

89
designer-base/src/main/java/com/fr/start/server/FineEmbedServerMonitor.java

@ -0,0 +1,89 @@
package com.fr.start.server;
import com.fr.design.mainframe.DesignerContext;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.fr.event.Null;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 内置服务器启动监视器
* Created by zack on 2018/8/21.
*/
public class FineEmbedServerMonitor {
private int progress;
private static final int COMPLETE = 100;//启动完成
private static final int STEP = 5;//随便设置一个假的进度条
private static final int STEP_HEARTBEAT = 2000;//2秒更新进度
private static volatile FineEmbedServerMonitor monitor;
private FineEmbedServerMonitor() {
}
static {
EventDispatcher.listen(EmbedServerEvent.AfterStop, new Listener<Null>() {
@Override
public void on(Event event, Null aNull) {
DesignerContext.getDesignerFrame().disposeProgressDialog();
}
});
}
public static FineEmbedServerMonitor getInstance() {
if (monitor == null) {
synchronized (FineEmbedServerMonitor.class) {
if (monitor == null) {
monitor = new FineEmbedServerMonitor();
}
}
}
return monitor;
}
public int getProgress() {
if (progress == COMPLETE) {
return progress;
} else {
progress += STEP;
return progress;
}
}
public void setComplete() {
this.progress = COMPLETE;
}
public void reset() {
this.progress = 0;
}
public boolean isComplete() {
return this.progress == COMPLETE;
}
public void monitor() {
ExecutorService service = Executors.newSingleThreadExecutor();
service.submit(new Runnable() {
@Override
public void run() {
while (!isComplete()) {
if (!DesignerContext.getDesignerFrame().getProgressDialog().isVisible()) {
DesignerContext.getDesignerFrame().showProgressDialog();
DesignerContext.getDesignerFrame().getProgressDialog().updateLoadingText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Loading_Embed_Server"));
}
DesignerContext.getDesignerFrame().updateProgress(getProgress());
try {
Thread.sleep(STEP_HEARTBEAT);
} catch (InterruptedException ignore) {
}
}
DesignerContext.getDesignerFrame().disposeProgressDialog();
}
});
service.shutdown();
}
}

9
designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

@ -10,6 +10,7 @@ import com.fr.record.analyzer.Metrics;
import com.fr.start.Designer;
import com.fr.start.ServerStarter;
import com.fr.start.SplashContext;
import com.fr.start.server.FineEmbedServer;
import com.fr.startup.activators.BasicActivator;
import com.fr.workspace.Workspace;
import com.fr.workspace.WorkspaceEvent;
@ -39,7 +40,13 @@ public class DesignerStartup extends Activator {
startSub(EnvBasedModule.class);
//designer模块启动好后,查看demo
browserDemo();
ExecutorService service = Executors.newSingleThreadExecutor();
ExecutorService service = Executors.newFixedThreadPool(2);
service.submit(new Runnable() {
@Override
public void run() {
FineEmbedServer.start();
}
});
service.submit(new Runnable() {
@Override

Loading…
Cancel
Save