Skip to content

Commit f26c01f

Browse files
committed
add View.appliedTo(ActContext) method; further optimize bootstrap log message
1 parent 1223b2b commit f26c01f

8 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/main/java/act/app/App.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
*/
6565
public class App extends DestroyableBase {
6666

67-
public static Logger logger = L.get(App.class);
67+
public static Logger logger = Act.logger;
6868

6969
private static App INST;
7070

@@ -887,7 +887,7 @@ private void loadRoutes() {
887887
logger.debug("loading app routing table: %s ...", appBase.getPath());
888888
File routes = RuntimeDirs.routes(this);
889889
if (!(routes.isFile() && routes.canRead())) {
890-
logger.warn("Cannot find routeTable file: %s", appBase.getPath());
890+
logger.debug("No route table find found");
891891
// guess the app is purely using annotation based routes
892892
return;
893893
}

src/main/java/act/app/AppServiceRegistry.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package act.app;
22

33
import act.Destroyable;
4+
import act.event.EventBus;
45
import org.osgl.$;
56
import org.osgl.logging.L;
67
import org.osgl.logging.LogManager;
@@ -35,7 +36,10 @@ synchronized void register(final AppService service) {
3536
tryRegisterSingletonService(c, service);
3637
} else {
3738
E.illegalStateIf(isSingletonService(c), "Singleton AppService[%s] cannot be re-registered", c);
38-
logger.warn("Service type[%s] already registered", service.getClass());
39+
// we know event bus will get registered twice for the `EventBus.onceBus`
40+
if (!(service instanceof EventBus)) {
41+
logger.warn("Service type[%s] already registered", service.getClass());
42+
}
3943
appendix.add(service);
4044
}
4145
}

src/main/java/act/app/CliServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package act.app;
22

3+
import act.Act;
34
import act.Destroyable;
45
import act.app.event.AppEventId;
56
import act.cli.CliSession;
@@ -136,7 +137,7 @@ public void run() {
136137
app().jobManager().on(AppEventId.POST_START, new Runnable() {
137138
@Override
138139
public void run() {
139-
logger.info("CLI server started on port: %s", port);
140+
Act.logger.info("CLI server started on port: %s", port);
140141
}
141142
});
142143
} catch (IOException e) {

src/main/java/act/app/DevModeClassLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private void scanSources() {
156156

157157
Set<String> classesNeedByteCodeScan = C.newSet();
158158
if (scanners.isEmpty()) {
159-
logger.warn("No source code scanner found");
159+
//logger.warn("No source code scanner found");
160160
for (String className : sources.keySet()) {
161161
classesNeedByteCodeScan.add(className);
162162
}

src/main/java/act/mail/MailerConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import act.app.AppHolderBase;
66
import org.osgl.exception.ConfigurationException;
77
import org.osgl.http.H;
8+
import org.osgl.logging.LogManager;
9+
import org.osgl.logging.Logger;
810
import org.osgl.util.C;
911
import org.osgl.util.E;
1012
import org.osgl.util.S;
@@ -24,6 +26,8 @@
2426
@ActComponent
2527
public class MailerConfig extends AppHolderBase {
2628

29+
public static final Logger logger = LogManager.get(MailerConfig.class);
30+
2731
public static final String FROM = "from";
2832
public static final String CONTENT_TYPE = "content_type";
2933
public static final String LOCALE = "locale";

src/main/java/act/view/View.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import act.plugin.AppServicePlugin;
88
import act.plugin.Plugin;
99
import act.util.ActContext;
10+
import org.osgl.http.H;
1011
import org.osgl.util.C;
1112
import org.osgl.util.IO;
1213
import org.osgl.util.S;
@@ -37,6 +38,11 @@ public void run() {
3738
});
3839
}
3940

41+
public boolean appliedTo(ActContext context) {
42+
H.Format format = context.accept();
43+
return format.isText();
44+
}
45+
4046
/**
4147
* Sub class must implement this method to load the template
4248
*

src/main/java/act/view/ViewManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private Template getTemplate(ActContext context, AppConfig config, String path)
106106

107107
if (multiViews) {
108108
View preferred = preferredViews.get(templatePath);
109-
if (null != preferred) {
109+
if (null != preferred && preferred.appliedTo(context)) {
110110
template = preferred.loadTemplate(templatePath, context);
111111
if (null != template) {
112112
context.cacheTemplate(template);
@@ -117,12 +117,12 @@ private Template getTemplate(ActContext context, AppConfig config, String path)
117117

118118
View defView = config.defaultView();
119119

120-
if (null != defView) {
120+
if (null != defView && defView.appliedTo(context)) {
121121
template = defView.loadTemplate(templatePath, context);
122122
}
123123
if (null == template && multiViews) {
124124
for (View view : viewList) {
125-
if (view == defView) continue;
125+
if (view == defView || !view.appliedTo(context)) continue;
126126
template = view.loadTemplate(templatePath, context);
127127
if (null != template) {
128128
if (multiViews) {

src/main/java/act/xio/NetworkBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package act.xio;
22

3+
import act.Act;
34
import act.Destroyable;
45
import act.util.DestroyableBase;
56
import org.osgl.logging.LogManager;
@@ -43,7 +44,7 @@ public void start() {
4344
if (!trySetUpClient(client, port)) {
4445
failed.put(port, client);
4546
} else {
46-
logger.info("network client hooked on port: %s", port);
47+
Act.logger.info("network client hooked on port: %s", port);
4748
}
4849
}
4950
started = true;

0 commit comments

Comments
 (0)