Browse Source

REPORT-17988 设计器启动速度--本机大概从 14.2s -> 10.2

1、basic并行
2、new Designer和env、core并行,但是和showDesigner串行
3、去掉读模板时候的进度条(待讨论,总共快了1s左右不过启动动画的时间长了,客户感受不确定)
research/10.0
ju 6 years ago
parent
commit
1c70ee19f3
  1. 11
      designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java
  2. 47
      designer-base/src/main/java/com/fr/start/BaseDesigner.java
  3. 24
      designer-realize/src/main/java/com/fr/start/DesignerInitial.java
  4. 21
      designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java
  5. 21
      designer-realize/src/main/java/com/fr/start/module/DesignerShowActivator.java
  6. 111
      designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java
  7. 94
      designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java

11
designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java

@ -102,11 +102,7 @@ public class EnvChangeEntrance {
return false;
}
//REPORT-13810如果只是添加了工作目录,没有切换,这里ToolArea也是要显示新建的工作目录
JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (template != null) {
template.refreshToolArea();
}
WorkContext.switchTo(workspace, new WorkContextCallback() {
@Override
public void done() {
@ -119,6 +115,11 @@ public class EnvChangeEntrance {
}
}
});
//REPORT-13810如果只是添加了工作目录,没有切换,这里ToolArea也是要显示新建的工作目录
JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (template != null) {
template.refreshToolArea();
}
} catch (WorkspaceAuthException | RegistEditionException e) {
// String title = Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed");

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

@ -31,19 +31,18 @@ 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;
private final String[] args;
public BaseDesigner(String[] args) {
init(args);
this.args = args;
init();
}
private void init(String[] args) {
private void init() {
//初始化
EventDispatcher.fire(ModuleEvent.MajorModuleStarting, Toolkit.i18nText("Fine-Design_Basic_Initializing"));
// 初始化look and feel.这个在预加载之前执行是因为lookAndFeel里的东西,预加载时也要用到
@ -52,18 +51,15 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
DesignerEnvManager.loadLogSetting();
createDesignerFrame();
}
public void show(final String[] args) {
public void show() {
collectUserInformation();
DesignerContext.getDesignerFrame().updateProgress(PERCENT_TEN);
showDesignerFrame(args, DesignerContext.getDesignerFrame(), false);
DesignerContext.getDesignerFrame().updateProgress(PERCENT_SIXTY);
showDesignerFrame(false);
DesignerContext.getDesignerFrame().setVisible(true);
DesignerContext.getDesignerFrame().refreshEnv();
DesignerContext.getDesignerFrame().updateProgress(PERCENT_NINTY);
for (int i = 0; !TemplateTreePane.getInstance().getTemplateFileTree().isTemplateShowing() && i < LOAD_TREE_MAXNUM; i++) {
TemplateTreePane.getInstance().getTemplateFileTree().refresh();
}
DesignerContext.getDesignerFrame().updateProgress(PERCENT_COMPLETE);
}
@ -71,10 +67,9 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
new DesignerFrame(this);
}
private void showDesignerFrame(String[] args, final DesignerFrame df,
boolean isException) {
private void showDesignerFrame(boolean isException) {
try {
FILE file = null;
if (args != null && args.length > 0) {
@ -101,12 +96,13 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
file = FILEFactory.createFILE(FILEFactory.ENV_PREFIX
+ DesignerEnvManager.getEnvManager().getLastOpenFile());
}
DesignerFrame df = DesignerContext.getDesignerFrame();
isException = openFile(df, isException, file);
df.fireDesignerOpened();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
if (!isException) {
showDesignerFrame(args, df, true);
showDesignerFrame(true);
} else {
System.exit(0);
}
@ -137,19 +133,14 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
df.getSelectedJTemplate().requestGridFocus();
return isException;
}
/**
* @param window
*/
private void enableFullScreenMode(Window window) {
String className = "com.apple.eawt.FullScreenUtilities";
String methodName = "setWindowCanFullScreen";
try {
Class<?> clazz = Class.forName(className);
Method method = clazz.getMethod(methodName, new Class<?>[]{
Window.class, boolean.class});
Method method = clazz.getMethod(methodName, Window.class, boolean.class);
method.invoke(null, window, true);
} catch (Throwable t) {
FineLoggerFactory.getLogger().error("Full screen mode is not supported");

24
designer-realize/src/main/java/com/fr/start/DesignerInitial.java

@ -0,0 +1,24 @@
package com.fr.start;
/**
* Created by juhaoyu on 2019-06-14.
* 设计器上下文
*/
public class DesignerInitial {
private static volatile Designer designer;
public synchronized static void init(String... args) {
designer = new Designer(args);
}
public synchronized static void show() {
if (designer != null) {
designer.show();
}
//启动画面结束
SplashContext.getInstance().hide();
}
}

21
designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java

@ -0,0 +1,21 @@
package com.fr.start.module;
import com.fr.module.Activator;
import com.fr.start.DesignerInitial;
/**
* Created by juhaoyu on 2019-06-14.
*/
public class DesignerInitActivator extends Activator {
@Override
public void start() {
DesignerInitial.init(upFindSingleton(StartupArgs.class).get());
}
@Override
public void stop() {
}
}

21
designer-realize/src/main/java/com/fr/start/module/DesignerShowActivator.java

@ -0,0 +1,21 @@
package com.fr.start.module;
import com.fr.module.Activator;
import com.fr.start.DesignerInitial;
/**
* Created by juhaoyu on 2019-06-14.
*/
public class DesignerShowActivator extends Activator {
@Override
public void start() {
DesignerInitial.show();
}
@Override
public void stop() {
}
}

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

@ -2,20 +2,15 @@ package com.fr.start.module;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.mainframe.DesignerContext;
import com.fr.event.Event;
import com.fr.event.Listener;
import com.fr.log.FineLoggerFactory;
import com.fr.module.Activator;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.record.analyzer.Metrics;
import com.fr.runtime.FineRuntime;
import com.fr.start.Designer;
import com.fr.start.DesignerInitial;
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.third.org.apache.commons.lang3.time.StopWatch;
import com.fr.workspace.Workspace;
import com.fr.workspace.WorkspaceEvent;
@ -27,115 +22,31 @@ import java.util.concurrent.Executors;
*/
@EnableMetrics
public class DesignerStartup extends Activator {
@Override
@Metrics
public void start() {
startSub(PreStartActivator.class);
//启动基础部分
startSub(BasicActivator.class);
final String[] args = getModule().upFindSingleton(StartupArgs.class).get();
final Designer designer = new Designer(args);
startSub(DesignerWorkspaceProvider.class);
registerEnvListener();
//启动env
startSub(EnvBasedModule.class);
getSub("parallel").start();
//designer模块启动好后,查看demo
browserDemo();
ExecutorService service = Executors.newFixedThreadPool(2);
service.submit(new Runnable() {
@Override
public void run() {
FineEmbedServer.start();
}
});
final StopWatch watch = new StopWatch();
service.submit(new Runnable() {
@Override
public void run() {
try {
watch.start();
designer.show(args);
} finally {
DesignerContext.getDesignerFrame().getProgressDialog().dispose();
FineLoggerFactory.getLogger().info("Designer showed.Time used {} ms", watch.getTime());
watch.stop();
}
}
});
service.shutdown();
DesignerContext.getDesignerFrame().setVisible(true);
//启动画面结束
SplashContext.getInstance().hide();
DesignerContext.getDesignerFrame().getProgressDialog().setVisible(true);
startSub(DesignerShowActivator.class);
startSub(StartFinishActivator.class);
FineRuntime.startFinish();
}
private void browserDemo() {
if (getModule().leftFindSingleton(StartupArgs.class) != null && getModule().leftFindSingleton(StartupArgs.class).isDemo()) {
ServerStarter.browserDemoURL();
}
}
/**
* 注册切换环境前后事件监听
*/
private void registerEnvListener() {
/*切换环境前,关闭所有相关模块,最后执行*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MIN_VALUE) {
@Override
public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).stop();
}
});
/*切换环境后,重新启动所有相关模块,最先执行*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override
public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).start();
// 切换后的环境是本地环境才启动内置服务器
if (current.isLocal()) {
ExecutorService service = Executors.newSingleThreadExecutor();
service.submit(new Runnable() {
@Override
public void run() {
FineEmbedServer.start();
}
});
service.shutdown();
}
}
});
/*切换环境前,存储一下打开的所有文件对象,要先于 关闭相关模块部分 被触发*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override
public void on(Event event, Workspace workspace) {
HistoryTemplateListCache.getInstance().stash();
}
});
/*切换环境后,装载一下打开的所有文件对象,优先级低于默认优先级,要后于 启动相关模块部分 被触发*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MIN_VALUE) {
@Override
public void on(Event event, Workspace workspace) {
HistoryTemplateListCache.getInstance().load();
}
});
}
@Override
public void stop() {
}
}

94
designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java

@ -0,0 +1,94 @@
package com.fr.start.module;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.event.Event;
import com.fr.event.Listener;
import com.fr.module.Activator;
import com.fr.start.server.FineEmbedServer;
import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace;
import com.fr.workspace.WorkspaceEvent;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created by juhaoyu on 2019-06-14.
*/
public class DesignerWorkspaceActivator extends Activator {
@Override
public void start() {
registerEnvListener();
startServer(WorkContext.getCurrent());
}
/**
* 注册切换环境前后事件监听
*/
private void registerEnvListener() {
/*切换环境前,关闭所有相关模块,最后执行*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MIN_VALUE) {
@Override
public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).stop();
}
});
/*切换环境后,重新启动所有相关模块,最先执行*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override
public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).start();
startServer(current);
}
});
/*切换环境前,存储一下打开的所有文件对象,要先于 关闭相关模块部分 被触发*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override
public void on(Event event, Workspace workspace) {
HistoryTemplateListCache.getInstance().stash();
}
});
/*切换环境后,装载一下打开的所有文件对象,优先级低于默认优先级,要后于 启动相关模块部分 被触发*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MIN_VALUE) {
@Override
public void on(Event event, Workspace workspace) {
HistoryTemplateListCache.getInstance().load();
}
});
}
private void startServer(Workspace current) {
// 切换后的环境是本地环境才启动内置服务器
if (current.isLocal()) {
ExecutorService service = Executors.newSingleThreadExecutor();
service.submit(new Runnable() {
@Override
public void run() {
FineEmbedServer.start();
}
});
service.shutdown();
}
}
@Override
public void stop() {
}
}
Loading…
Cancel
Save