Skip to content

Commit 551ba9c

Browse files
committed
Plugin scanning testing passed
1 parent 95091d6 commit 551ba9c

74 files changed

Lines changed: 3705 additions & 349 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 224 additions & 224 deletions
Large diffs are not rendered by default.

src/main/java/org/osgl/oms/App.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/org/osgl/oms/AppConfig.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main/java/org/osgl/oms/AppContext.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@
33
import org.osgl._;
44
import org.osgl.concurrent.ContextLocal;
55
import org.osgl.http.H;
6+
import org.osgl.oms.app.App;
7+
import org.osgl.oms.conf.AppConfig;
68
import org.osgl.util.E;
79

810
import java.util.*;
911

12+
/**
13+
* {@code AppContext} encapsulate contextual properties needed by
14+
* an application session
15+
*/
1016
public class AppContext {
1117

12-
private AppConfig config;
18+
private App app;
1319
private H.Request request;
1420
private H.Response response;
1521
private Set<Map.Entry<String, String[]>> requestParamCache;
1622
private Map<String, String> extraParams;
1723
private Map<String, Object> renderArgs;
1824
private Map<String, String[]> allParams;
1925

20-
public AppContext(AppConfig config, H.Request request, H.Response response) {
21-
E.NPE(config, request, response);
22-
this.config = config;
26+
private AppContext(App app, H.Request request, H.Response response) {
27+
E.NPE(app, request, response);
28+
this.app = app;
2329
this.request = request;
2430
this.response = response;
2531
_init();
@@ -64,8 +70,12 @@ public AppContext renderArg(String name, Object val) {
6470
return this;
6571
}
6672

73+
public App app() {
74+
return app;
75+
}
76+
6777
public AppConfig config() {
68-
return this.config;
78+
return app.config();
6979
}
7080

7181
private Set<Map.Entry<String, String[]>> requestParamCache() {
@@ -181,11 +191,18 @@ public static AppContext get() {
181191
return _local.get();
182192
}
183193

184-
public static AppContext create(AppConfig config, H.Request request, H.Response resp) {
185-
return new AppContext(config, request, resp);
194+
/**
195+
* Create an new {@code AppContext} and return the new instance
196+
*/
197+
public static AppContext create(App app, H.Request request, H.Response resp) {
198+
return new AppContext(app, request, resp);
186199
}
187200

188-
public static void init(AppConfig config, H.Request request, H.Response resp) {
189-
_local.set(new AppContext(config, request, resp));
201+
/**
202+
* Create an new {@code AppContext} and save the context instance into
203+
* contextual local
204+
*/
205+
public static void init(App app, H.Request request, H.Response resp) {
206+
_local.set(new AppContext(app, request, resp));
190207
}
191208
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.osgl.oms;
2+
3+
import org.osgl.oms.cls.BootstrapClassLoader;
4+
5+
import java.lang.reflect.Method;
6+
7+
/**
8+
* bootstrap the OMS
9+
*/
10+
public class Bootstrap {
11+
public static void main(String[] args) throws Exception {
12+
BootstrapClassLoader classLoader = new BootstrapClassLoader(Bootstrap.class.getClassLoader());
13+
Class<?> omsClass = classLoader.loadClass("org.osgl.oms.OMS");
14+
Method m = omsClass.getDeclaredMethod("start");
15+
m.invoke(null);
16+
}
17+
}
Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,134 @@
11
package org.osgl.oms;
22

3+
import org.osgl._;
4+
import org.osgl.exception.NotAppliedException;
5+
import org.osgl.logging.L;
6+
import org.osgl.logging.Logger;
37
import org.osgl.mvc.annotation.*;
8+
import org.osgl.oms.app.AppManager;
9+
import org.osgl.oms.app.AppScanner;
10+
import org.osgl.oms.cls.BootstrapClassLoader;
11+
import org.osgl.oms.conf.OmsConfLoader;
12+
import org.osgl.oms.conf.OmsConfig;
13+
import org.osgl.oms.util.Banner;
414
import org.osgl.util.C;
15+
import org.osgl.util.E;
516

617
import java.lang.annotation.Annotation;
718
import java.util.List;
819

920
/**
10-
* Created by luog on 29/01/2015.
21+
* The OSGL MVC Server object
1122
*/
12-
public class OMS {
23+
public final class OMS {
1324

25+
public static enum Mode {
26+
PROD, UAT, SIT, DEV () {
27+
@Override
28+
public AppScanner appScanner() {
29+
return AppScanner.DEV_MODE_SCANNER;
30+
}
31+
};
32+
33+
private final String confPrefix = "%" + name().toLowerCase() + ".";
34+
35+
/**
36+
* DEV mode is special as OMS might load classes
37+
* directly from source code when running in this mode
38+
*/
39+
public boolean isDev() {
40+
return DEV == this;
41+
}
42+
43+
public String configKey(String key) {
44+
return confPrefix + key;
45+
}
46+
47+
public AppScanner appScanner() {
48+
return AppScanner.DEF_SCANNER;
49+
}
50+
51+
public static Mode valueOfIgnoreCase(String mode) {
52+
return valueOf(mode.trim().toUpperCase());
53+
}
54+
}
55+
56+
private static OmsConfig conf;
57+
private static Logger logger = L.get(OMS.class);
58+
private static Mode mode = Mode.PROD;
59+
private static AppManager appManager;
1460
private static List<Class<? extends Annotation>> actionAnnotationTypes = C.list(
1561
Action.class, GetAction.class, PostAction.class,
1662
PutAction.class, DeleteAction.class);
1763

64+
65+
public static BootstrapClassLoader classLoader() {
66+
return (BootstrapClassLoader)OMS.class.getClassLoader();
67+
}
68+
public static Mode mode() {
69+
return mode;
70+
}
71+
public static boolean isDev() {
72+
return mode.isDev();
73+
}
74+
public static OmsConfig conf() {
75+
return conf;
76+
}
77+
1878
public static boolean isActionAnnotation(Class<?> type) {
1979
return actionAnnotationTypes.contains(type);
2080
}
2181

82+
public static void start() {
83+
Banner.print("0.0.1-SNAPSHOT");
84+
loadConfig();
85+
loadPlugins();
86+
initExecuteService();
87+
initNetworkLayer();
88+
initApplicationManager();
89+
startNetworkLayer();
90+
}
91+
92+
private static void loadConfig() {
93+
logger.debug("loading configuration ...");
94+
95+
String s = System.getProperty("oms.mode");
96+
if (null != s) {
97+
mode = Mode.valueOfIgnoreCase(s);
98+
}
99+
logger.info("OMS start in %s mode", mode);
100+
101+
conf = new OmsConfLoader().load(null);
102+
}
103+
104+
private static void loadPlugins() {
105+
E.tbd("load plugins");
106+
}
107+
108+
private static void initExecuteService() {
109+
E.tbd("init execute service");
110+
}
111+
112+
private static void initNetworkLayer() {
113+
E.tbd("init network server");
114+
}
115+
116+
private static void initApplicationManager() {
117+
appManager = AppManager.scan();
118+
}
119+
120+
private static void startNetworkLayer() {
121+
122+
}
123+
124+
public static enum F {
125+
;
126+
public static final _.F0<Mode> MODE_ACCESSOR = new _.F0<Mode>() {
127+
@Override
128+
public Mode apply() throws NotAppliedException, _.Break {
129+
return mode;
130+
}
131+
};
132+
}
133+
22134
}

src/main/java/org/osgl/oms/RequestImplBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.osgl.oms;
22

33
import org.osgl.http.H;
4+
import org.osgl.oms.conf.AppConfig;
45
import org.osgl.util.FastStr;
56
import org.osgl.util.S;
67

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.osgl.oms.app;
2+
3+
import org.osgl._;
4+
import org.osgl.logging.L;
5+
import org.osgl.logging.Logger;
6+
import org.osgl.oms.cls.AppClassLoader;
7+
import org.osgl.oms.conf.AppConfLoader;
8+
import org.osgl.oms.conf.AppConfig;
9+
import org.osgl.oms.route.RouteTableRouterBuilder;
10+
import org.osgl.oms.route.Router;
11+
import org.osgl.util.IO;
12+
13+
import java.io.File;
14+
import java.util.List;
15+
16+
/**
17+
* {@code App} represents an application that is deployed in a OMS container
18+
*/
19+
public class App {
20+
21+
private static Logger logger = L.get(App.class);
22+
23+
private File appBase;
24+
private Router router;
25+
private AppConfig config;
26+
private AppClassLoader classLoader;
27+
private ProjectLayout layout;
28+
29+
private App(File appBase, ProjectLayout layout) {
30+
this.appBase = appBase;
31+
this.layout = layout;
32+
}
33+
34+
public AppConfig config() {
35+
return config;
36+
}
37+
38+
public Router router() {
39+
return router;
40+
}
41+
42+
public File base() {
43+
return appBase;
44+
}
45+
46+
public ProjectLayout layout() {
47+
return layout;
48+
}
49+
50+
public void refresh() {
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return appBase.hashCode();
56+
}
57+
58+
@Override
59+
public boolean equals(Object obj) {
60+
if (obj == this) {
61+
return true;
62+
}
63+
if (obj instanceof App) {
64+
App that = (App) obj;
65+
return _.eq(that.appBase, appBase);
66+
}
67+
return false;
68+
}
69+
70+
@Override
71+
public String toString() {
72+
return appBase.getName();
73+
}
74+
75+
private void loadConfig(File conf) {
76+
logger.debug("loading app configuration: %s ...", appBase.getPath());
77+
config = new AppConfLoader().load(conf);
78+
}
79+
80+
private void loadRoutes(File routes) {
81+
logger.debug("loading app routing table: %s ...", appBase.getPath());
82+
router = new Router(config);
83+
if (!(routes.isFile() && routes.canRead())) {
84+
return;
85+
}
86+
List<String> lines = IO.readLines(routes);
87+
new RouteTableRouterBuilder(lines).build(router);
88+
}
89+
90+
private void loadClasses() {
91+
classLoader = new AppClassLoader(appBase, config, layout);
92+
}
93+
94+
static App create(File appBase, ProjectLayout layout) {
95+
return new App(appBase, layout);
96+
}
97+
}

0 commit comments

Comments
 (0)