Repository navigation
Expand file tree
/
Copy pathRunApp.java
More file actions
75 lines (66 loc) · 2.73 KB
/
Copy pathRunApp.java
File metadata and controls
75 lines (66 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package act.boot.app;
import act.conf.AppConfigKey;
import act.util.SysProps;
import org.osgl.$;
import org.osgl.logging.L;
import org.osgl.logging.Logger;
import org.osgl.util.E;
import org.osgl.util.FastStr;
import org.osgl.util.S;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* The entry to start an Act full stack app
*/
public class RunApp {
private static final Logger logger = L.get(RunApp.class);
public static void start() throws Exception {
start(null, null, "");
}
public static void start(Class<?> anyController) throws Exception {
start(null, null, anyController);
}
public static void start(String appName, String appVersion, Class<?> anyController) throws Exception {
String pkg = anyController.getPackage().getName();
start(appName, appVersion, pkg);
}
public static void start(String appName, String appVersion, String packageName) throws Exception {
long ts = $.ms();
String profile = SysProps.get(AppConfigKey.PROFILE.key());
if (S.blank(profile)) {
profile = "";
} else {
profile = "using profile[" + profile + "]";
}
logger.info("run fullstack application with controller package[%s] %s", packageName, profile);
System.setProperty(AppConfigKey.CONTROLLER_PACKAGE.key(), packageName);
final String SCAN_KEY = AppConfigKey.SCAN_PACKAGE.key();
if (!System.getProperties().containsKey(SCAN_KEY)) {
String scan = packageName;
if (FastStr.of(packageName).afterLast('.').startsWith("controller")) {
scan = FastStr.of(packageName).beforeLast('.').toString();
}
System.setProperty(AppConfigKey.SCAN_PACKAGE.key(), scan);
}
logger.debug("loading bootstrap classloader...");
FullStackAppBootstrapClassLoader classLoader = new FullStackAppBootstrapClassLoader(RunApp.class.getClassLoader());
Thread.currentThread().setContextClassLoader(classLoader);
logger.debug("loading Act class...");
Class<?> actClass = classLoader.loadClass("act.Act");
Method m = actClass.getDeclaredMethod("startApp", String.class, String.class);
try {
m.invoke(null, appName, appVersion);
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t instanceof Exception) {
throw (Exception) t;
} else {
throw E.unexpected(t, "Unknown error captured starting the application");
}
}
System.out.printf("it talks %sms to start the app\n", $.ms() - ts);
}
public static void main(String[] args) throws Exception {
start();
}
}