Skip to content

Commit 2442e0a

Browse files
committed
Merge branch '1.3'
2 parents 14b665d + 5e66963 commit 2442e0a

9 files changed

Lines changed: 142 additions & 66 deletions

File tree

pom.xml

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,9 @@
1818
********************************************
1919
* version history
2020
********************************************
21-
1.4.1
22-
* #239 `DbServiceManager.hasDbService()` error implementation
23-
24-
1.4.0
25-
* #235 Update fastjson to 1.2.33
26-
* #234 App start event listener not called when there is no Async DbService
27-
* #228 Generate ASCII banner for favicon
28-
* #227 Support colorful console output
29-
* #226 Support customized banner text
30-
* #223 Allow app to terminate `@InheritedStateless`
31-
* #221 Make `Dao` implementation be stateless
32-
* #220 Automatically register a class with `@Stateless` tag into app's singleton registry
33-
* #219 Support Lazy initialized singleton
34-
* #217 Support initialize DbService asynchronously
35-
* #212 Support easy configuring of header session mapper
36-
* #211 Smart initialize Job instance
37-
* #207 Deprecate `@Env.Mode` for `@Env.RequireMode`
38-
* #206 Deprecate `@Env.Profile` for `@Env.RequireProfile`
39-
* #205 Deprecate `@Env.Group` for `@Env.RequireGroup`
40-
* #192 Log the URL with handler error message
41-
* #191 Review and fix the use of `ConcurrentMap`
42-
* #17 Support WebSocket
21+
1.3.5
22+
* #246 Returning Locale type result does not rendering valid JSON response
23+
* #244 Resource consumption issue with DEV mode
4324
4425
1.3.4
4526
* #233 When action handler returning an object, it failed to apply the `@ResponseStatus` annotation in certain cases
@@ -216,7 +197,7 @@
216197
<groupId>org.actframework</groupId>
217198
<artifactId>act</artifactId>
218199
<packaging>jar</packaging>
219-
<version>1.4.2-SNAPSHOT</version>
200+
<version>1.3.6-SNAPSHOT</version>
220201

221202
<name>ACT Framework</name>
222203
<description>The ACT full stack MVC framework</description>
@@ -263,9 +244,9 @@
263244
<jline.version>2.14.3</jline.version>
264245
<joda-time.version>2.9.9</joda-time.version>
265246
<okhttp.version>3.8.0</okhttp.version>
266-
<osgl-tool.version>1.2.0</osgl-tool.version>
267-
<osgl-genie.version>1.1.2</osgl-genie.version>
268-
<osgl-mvc.version>1.1.1</osgl-mvc.version>
247+
<osgl-tool.version>1.2.1</osgl-tool.version>
248+
<osgl-genie.version>1.0.2</osgl-genie.version>
249+
<osgl-mvc.version>1.0.6</osgl-mvc.version>
269250
<osgl-storage.version>1.2.0</osgl-storage.version>
270251
<osgl-tool-ext.version>1.0.1</osgl-tool-ext.version>
271252
<reflectasm.version>1.11.3</reflectasm.version>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@ public void shutdown() {
467467

468468
@Override
469469
protected void releaseResources() {
470-
mainThread.interrupt();
470+
// shall not interrupt main thread
471+
// see https://stackoverflow.com/questions/44665552/undertow-xnio-i-o-thread-consistently-eat-cpu
472+
// mainThread.interrupt();
471473
if (null == daemonRegistry) {
472474
return;
473475
}

src/main/java/act/app/event/AppEvent.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@
2525
import act.event.SystemEvent;
2626

2727
public abstract class AppEvent extends ActEvent<App> implements SystemEvent {
28-
private int id;
28+
29+
private AppEventId id;
30+
2931
public AppEvent(AppEventId id, App source) {
3032
super(source);
31-
this.id = id.ordinal();
33+
this.id = id;
3234
}
35+
36+
@Override
37+
public String toString() {
38+
return id.name();
39+
}
40+
3341
public int id() {
34-
return id;
42+
return id.ordinal();
3543
}
3644
}

src/main/java/act/db/DbService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@
3333

3434
public abstract class DbService extends AppHolderBase<DbService> {
3535

36+
/**
37+
* This is deprecated, please use {@link #logger} instead
38+
*/
39+
@Deprecated
3640
protected static final Logger _logger = LogManager.get(DbService.class);
3741

42+
protected final Logger logger = LogManager.get(getClass());
43+
3844
private String id;
3945

4046
/**

src/main/java/act/event/EventBus.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
import act.inject.DependencyInjectionBinder;
3131
import act.inject.DependencyInjector;
3232
import act.job.AppJobManager;
33+
import org.osgl.logging.LogManager;
34+
import org.osgl.logging.Logger;
3335
import org.osgl.mvc.result.Result;
3436
import org.osgl.util.C;
3537
import org.osgl.util.E;
38+
import org.osgl.util.S;
3639

3740
import javax.enterprise.context.ApplicationScoped;
3841
import javax.inject.Inject;
@@ -43,11 +46,11 @@
4346
import java.util.concurrent.ConcurrentMap;
4447
import java.util.concurrent.TimeUnit;
4548

46-
import static act.app.App.LOGGER;
47-
4849
@ApplicationScoped
4950
public class EventBus extends AppServiceBase<EventBus> {
5051

52+
private static final Logger LOGGER = LogManager.get(EventBus.class);
53+
5154
private boolean once;
5255

5356
private final List[] appEventListeners;
@@ -296,6 +299,9 @@ public synchronized EventBus emit(AppEventId eventId) {
296299
}
297300

298301
public synchronized EventBus emit(final AppEvent event) {
302+
if (isTraceEnabled()) {
303+
trace("emitting app event: %s", event);
304+
}
299305
if (isDestroyed()) {
300306
return this;
301307
}
@@ -313,6 +319,9 @@ public synchronized EventBus emitAsync(AppEventId eventId) {
313319
}
314320

315321
public synchronized EventBus emitAsync(final AppEvent event) {
322+
if (isTraceEnabled()) {
323+
trace("emitting app event asynchronously: %s", event);
324+
}
316325
if (isDestroyed()) {
317326
return this;
318327
}
@@ -374,6 +383,10 @@ public EventBus triggerSync(final ActEvent event) {
374383

375384
@SuppressWarnings("unchecked")
376385
public EventBus emit(final ActEvent event) {
386+
if (isTraceEnabled()) {
387+
trace("emitting act event: %s", event);
388+
}
389+
377390
if (isDestroyed()) {
378391
return this;
379392
}
@@ -401,6 +414,10 @@ public EventBus trigger(final ActEvent event) {
401414
}
402415

403416
public EventBus emitAsync(final ActEvent event) {
417+
if (isTraceEnabled()) {
418+
trace("emitting act event asynchronously: %s", event);
419+
}
420+
404421
if (isDestroyed()) {
405422
return this;
406423
}
@@ -591,5 +608,16 @@ public void on(DependencyInjectionBinder event) throws Exception {
591608
});
592609
}
593610

611+
private static boolean isTraceEnabled() {
612+
return LOGGER.isTraceEnabled();
613+
}
614+
615+
private void trace(String msg, Object... args) {
616+
msg = S.fmt(msg, args);
617+
if (once) {
618+
msg = S.builder("[once]").append(msg).toString();
619+
}
620+
LOGGER.trace(msg);
621+
}
594622

595623
}

src/main/java/act/job/AppJobManager.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.joda.time.Seconds;
3434
import org.osgl.$;
3535
import org.osgl.exception.NotAppliedException;
36+
import org.osgl.logging.LogManager;
37+
import org.osgl.logging.Logger;
3638
import org.osgl.util.C;
3739
import org.osgl.util.E;
3840
import org.osgl.util.S;
@@ -44,6 +46,8 @@
4446

4547
public class AppJobManager extends AppServiceBase<AppJobManager> {
4648

49+
private static final Logger LOGGER = LogManager.get(AppJobManager.class);
50+
4751
private ScheduledThreadPoolExecutor executor;
4852
private ConcurrentMap<String, _Job> jobs = new ConcurrentHashMap<String, _Job>();
4953
private ConcurrentMap<String, ScheduledFuture> scheduled = new ConcurrentHashMap<>();
@@ -62,12 +66,13 @@ public AppJobManager(App app) {
6266

6367
@Override
6468
protected void releaseResources() {
69+
LOGGER.trace("release job manager resources");
6570
for (_Job job : jobs.values()) {
6671
job.destroy();
6772
}
6873
jobs.clear();
69-
executor.shutdown();
7074
executor.getQueue().clear();
75+
executor.shutdownNow();
7176
}
7277

7378
public <T> Future<T> now(Callable<T> callable) {
@@ -130,19 +135,25 @@ public void fixedDelay(String id, Runnable runnable, long interval, TimeUnit tim
130135

131136
private int parseTime(String timeDuration) {
132137
if (timeDuration.startsWith("${") && timeDuration.endsWith("}")) {
133-
timeDuration = (String) app().config().get(timeDuration.substring(2, timeDuration.length() - 1));
138+
timeDuration = app().config().get(timeDuration.substring(2, timeDuration.length() - 1));
134139
}
135140
return Time.parseDuration(timeDuration);
136141
}
137142

138143
public void on(DateTime instant, Runnable runnable) {
144+
if (LOGGER.isTraceEnabled()) {
145+
LOGGER.trace("schedule runnable[%s] on %s", runnable, instant);
146+
}
139147
DateTime now = DateTime.now();
140148
E.illegalArgumentIf(instant.isBefore(now));
141149
Seconds seconds = Seconds.secondsBetween(now, instant);
142150
executor().schedule(wrap(runnable), seconds.getSeconds(), TimeUnit.SECONDS);
143151
}
144152

145153
public <T> Future<T> on(DateTime instant, Callable<T> callable) {
154+
if (LOGGER.isTraceEnabled()) {
155+
LOGGER.trace("schedule callable[%s] on %s", callable, instant);
156+
}
146157
DateTime now = DateTime.now();
147158
E.illegalArgumentIf(instant.isBefore(now));
148159
Seconds seconds = Seconds.secondsBetween(now, instant);
@@ -154,12 +165,7 @@ public void on(AppEventId appEvent, final Runnable runnable) {
154165
}
155166

156167
public void on(AppEventId appEvent, final Runnable runnable, boolean runImmediatelyIfEventDispatched) {
157-
_Job job = jobById(appEventJobId(appEvent));
158-
if (null == job) {
159-
processDelayedJob(wrap(runnable), runImmediatelyIfEventDispatched);
160-
} else {
161-
job.addPrecedenceJob(_Job.once(runnable, this));
162-
}
168+
on(appEvent, runnable.toString(), runnable, runImmediatelyIfEventDispatched);
163169
}
164170

165171
public void post(AppEventId appEvent, final Runnable runnable) {
@@ -180,10 +186,20 @@ public void on(AppEventId appEvent, String jobId, final Runnable runnable) {
180186
}
181187

182188
public void on(AppEventId appEvent, String jobId, final Runnable runnable, boolean runImmediatelyIfEventDispatched) {
189+
boolean traceEnabled = LOGGER.isTraceEnabled();
190+
if (traceEnabled) {
191+
LOGGER.trace("binding job[%s] to app event: %s, run immediately if event dispatched: %s", jobId, appEvent, runImmediatelyIfEventDispatched);
192+
}
183193
_Job job = jobById(appEventJobId(appEvent));
184194
if (null == job) {
195+
if (traceEnabled) {
196+
LOGGER.trace("process delayed job: %s", jobId);
197+
}
185198
processDelayedJob(wrap(runnable), runImmediatelyIfEventDispatched);
186199
} else {
200+
if (traceEnabled) {
201+
LOGGER.trace("schedule job: %s", jobId);
202+
}
187203
job.addPrecedenceJob(_Job.once(jobId, runnable, this));
188204
}
189205
}
@@ -291,7 +307,10 @@ ScheduledThreadPoolExecutor executor() {
291307
private void initExecutor(App app) {
292308
int poolSize = app.config().jobPoolSize();
293309
executor = new ScheduledThreadPoolExecutor(poolSize, new AppThreadFactory("jobs"), new ThreadPoolExecutor.AbortPolicy());
294-
//JDK1.7 API: executor.setRemoveOnCancelPolicy(true);
310+
executor.setRemoveOnCancelPolicy(true);
311+
if (LOGGER.isTraceEnabled()) {
312+
LOGGER.trace("init executor with thread pool: %s", poolSize);
313+
}
295314
}
296315

297316
private void createAppEventListener(AppEventId appEventId) {

src/main/java/act/job/JobAnnotationProcessor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import act.job.meta.JobClassMetaInfo;
2828
import act.job.meta.JobMethodMetaInfo;
2929
import org.osgl.$;
30+
import org.osgl.logging.LogManager;
31+
import org.osgl.logging.Logger;
3032
import org.osgl.util.E;
3133
import org.osgl.util.S;
3234

@@ -35,6 +37,8 @@
3537

3638
public class JobAnnotationProcessor extends AppHolderBase<JobAnnotationProcessor> {
3739

40+
private static final Logger LOGGER = LogManager.get(JobAnnotationProcessor.class);
41+
3842
private AppJobManager manager;
3943

4044
public JobAnnotationProcessor(App app) {
@@ -43,6 +47,9 @@ public JobAnnotationProcessor(App app) {
4347
}
4448

4549
public void register(final JobMethodMetaInfo method, final Class<? extends Annotation> anno, final Object v) {
50+
if (LOGGER.isTraceEnabled()) {
51+
LOGGER.trace("register job[%s] on anno[%s] with arg[%s]", method, anno, v);
52+
}
4653
if (isAbstract(method)) {
4754
app().jobManager().on(AppEventId.SINGLETON_PROVISIONED, new Runnable() {
4855
@Override

0 commit comments

Comments
 (0)