Skip to content

Commit ca733a9

Browse files
committed
format
1 parent fa802ae commit ca733a9

File tree

9 files changed

+36
-40
lines changed

9 files changed

+36
-40
lines changed

adapter/adapter-webserver/src/main/java/com/dtp/adapter/webserver/AbstractWebServerDtpAdapter.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import com.dtp.adapter.common.AbstractDtpAdapter;
44
import com.dtp.common.ApplicationContextHolder;
5-
import com.dtp.common.entity.TpExecutorProps;
6-
import com.dtp.common.entity.TpMainFields;
5+
import com.dtp.common.entity.ThreadPoolStats;
76
import com.dtp.common.properties.DtpProperties;
8-
import com.dtp.core.convert.ExecutorConverter;
97
import com.dtp.core.support.ExecutorWrapper;
10-
import com.dtp.common.entity.ThreadPoolStats;
118
import com.dtp.core.thread.ExecutorAdapter;
129
import com.google.common.collect.Lists;
1310
import lombok.extern.slf4j.Slf4j;
@@ -88,13 +85,6 @@ protected ExecutorAdapter<A> getExecutor() {
8885
return (ExecutorAdapter<A>) wrapper.getExecutor();
8986
}
9087

91-
@Override
92-
protected TpMainFields getTpMainFields(ExecutorWrapper executorWrapper, TpExecutorProps props) {
93-
final ExecutorAdapter<?> adapter = executorWrapper.getExecutor();
94-
return ExecutorConverter.ofSimple(executorWrapper.getThreadPoolName(), adapter.getCorePoolSize(),
95-
adapter.getMaximumPoolSize(), adapter.getKeepAliveTime(props.getUnit()));
96-
}
97-
9888
/**
9989
* Get thread pool executor wrapper.
10090
*

adapter/adapter-webserver/src/main/java/com/dtp/adapter/webserver/JettyDtpAdapter.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.dtp.adapter.webserver;
22

3+
import com.dtp.common.entity.ThreadPoolStats;
34
import com.dtp.common.properties.DtpProperties;
45
import com.dtp.common.util.ReflectionUtil;
56
import com.dtp.core.support.ExecutorWrapper;
6-
import com.dtp.common.entity.ThreadPoolStats;
77
import com.dtp.core.thread.ExecutorAdapter;
88
import lombok.extern.slf4j.Slf4j;
99
import org.eclipse.jetty.util.thread.MonitoredQueuedThreadPool;
@@ -144,13 +144,5 @@ public long getKeepAliveTime(TimeUnit unit) {
144144
}
145145
return 0;
146146
}
147-
148-
@Override
149-
public void setKeepAliveTime(long time, TimeUnit unit) {
150-
if (this.executor instanceof QueuedThreadPool) {
151-
final int keepAliveMs = (int) TimeUnit.MILLISECONDS.convert(time, unit);
152-
((QueuedThreadPool) this.executor).setIdleTimeout(keepAliveMs);
153-
}
154-
}
155147
}
156148
}

common/src/main/java/com/dtp/common/timer/HashedWheelTimer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* <a href="http://cseweb.ucsd.edu/users/varghese/PAPERS/twheel.ps.Z">'Hashed
6060
* and Hierarchical Timing Wheels: data structures to efficiently implement a
6161
* timer facility'</a>. More comprehensive slides are located
62-
* <a href="http://www.cse.wustl.edu/~cdgill/courses/cs6874/TimingWheels.ppt">here</a>.<br/>
62+
* <a href="http://www.cse.wustl.edu/~cdgill/courses/cs6874/TimingWheels.ppt">here</a>.<br>
6363
* Copy from dubbo, see <a href="https://github.com/apache/dubbo/blob/3.2/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java">here</a> for more details.
6464
*/
6565
@Slf4j
@@ -394,7 +394,7 @@ public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) {
394394
}
395395

396396
/**
397-
* Returns the number of pending timeouts of this {@link Timer}.
397+
* @return the number of pending timeouts of this {@link Timer}.
398398
*/
399399
public long pendingTimeouts() {
400400
return pendingTimeouts.get();

common/src/main/java/com/dtp/common/timer/Timeout.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
package com.dtp.common.timer;
22

33
/**
4-
* A handle associated with a {@link TimerTask} that is returned by a{@link Timer}.<br/>
4+
* A handle associated with a {@link TimerTask} that is returned by a{@link Timer}.<br>
55
* Copy from dubbo, see <a href="https://github.com/apache/dubbo/blob/3.2/dubbo-common/src/main/java/org/apache/dubbo/common/timer/Timeout.java">here</a> for more details.
66
*/
77
public interface Timeout {
88

99
/**
1010
* Returns the {@link Timer} that created this handle.
11+
*
12+
* @return the {@link Timer} that created this handle
1113
*/
1214
Timer timer();
1315

1416
/**
1517
* Returns the {@link TimerTask} which is associated with this handle.
18+
*
19+
* @return the {@link TimerTask} which is associated with this handle
1620
*/
1721
TimerTask task();
1822

1923
/**
2024
* Returns {@code true} if and only if the {@link TimerTask} associated
2125
* with this handle has been expired.
26+
*
27+
* @return {@code true} if and only if the {@link TimerTask} associated
2228
*/
2329
boolean isExpired();
2430

2531
/**
2632
* Returns {@code true} if and only if the {@link TimerTask} associated
2733
* with this handle has been cancelled.
34+
*
35+
* @return {@code true} if and only if the {@link TimerTask} associated
2836
*/
2937
boolean isCancelled();
3038

common/src/main/java/com/dtp/common/timer/Timer.java

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public interface Timer {
1313
/**
1414
* Schedules the specified {@link TimerTask} for one-time execution after
1515
* the specified delay.
16+
* @param task the task to execute
17+
* @param delay the time from now to delay execution
18+
* @param unit the time unit of the delay parameter
1619
*
1720
* @return a handle which is associated with the specified task
1821
* @throws IllegalStateException if this timer has been {@linkplain #stop() stopped} already

common/src/main/java/com/dtp/common/timer/TimerTask.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/**
66
* A task which is executed after the delay specified with
7-
* {@link Timer#newTimeout(TimerTask, long, TimeUnit)} (TimerTask, long, TimeUnit)}. <br/>
7+
* {@link Timer#newTimeout(TimerTask, long, TimeUnit)} (TimerTask, long, TimeUnit)}. <br>
88
* Copy from dubbo, see <a href="https://github.com/apache/dubbo/blob/3.2/dubbo-common/src/main/java/org/apache/dubbo/common/timer/TimeTask.java">here</a> for more details.
99
*/
1010
public interface TimerTask {
@@ -14,6 +14,7 @@ public interface TimerTask {
1414
* {@link Timer#newTimeout(TimerTask, long, TimeUnit)}.
1515
*
1616
* @param timeout a handle which is associated with this task
17+
* @throws Exception if an error occurs
1718
*/
1819
void run(Timeout timeout) throws Exception;
1920
}

core/src/main/java/com/dtp/core/reject/RejectedAware.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.dtp.core.notify.manager.AlarmManager;
44
import com.dtp.core.support.runnable.DtpRunnable;
5-
import com.dtp.core.support.runnable.NamedRunnable;
65
import com.dtp.core.thread.DtpExecutor;
6+
import lombok.val;
77
import org.slf4j.Logger;
88
import org.slf4j.MDC;
99

@@ -29,19 +29,16 @@ public interface RejectedAware {
2929
*/
3030
default void beforeReject(Runnable runnable, ThreadPoolExecutor executor, Logger log) {
3131
if (executor instanceof DtpExecutor) {
32-
if (runnable instanceof DtpRunnable) {
33-
((DtpRunnable) runnable).cancelQueueTimeoutTask();
34-
log.warn("DynamicTp execute, thread pool is exhausted, cancel queue timeout task, traceId: {}", MDC.get(TRACE_ID));
35-
}
32+
val dtpRunnable = (DtpRunnable) runnable;
33+
dtpRunnable.cancelQueueTimeoutTask();
3634
DtpExecutor dtpExecutor = (DtpExecutor) executor;
3735
dtpExecutor.incRejectCount(1);
3836
AlarmManager.doAlarmAsync(dtpExecutor, REJECT);
39-
String taskName = (runnable instanceof NamedRunnable) ? ((NamedRunnable) runnable).getName() : null;
4037
log.warn("DynamicTp execute, thread pool is exhausted, tpName: {}, taskName: {}, traceId: {}, " +
4138
"poolSize: {} (active: {}, core: {}, max: {}, largest: {}), " +
4239
"task: {} (completed: {}), queueCapacity: {}, (currSize: {}, remaining: {}), " +
4340
"executorStatus: (isShutdown: {}, isTerminated: {}, isTerminating: {})",
44-
dtpExecutor.getThreadPoolName(), taskName, MDC.get(TRACE_ID), executor.getPoolSize(),
41+
dtpExecutor.getThreadPoolName(), dtpRunnable.getTaskName(), MDC.get(TRACE_ID), executor.getPoolSize(),
4542
executor.getActiveCount(), executor.getCorePoolSize(), executor.getMaximumPoolSize(),
4643
executor.getLargestPoolSize(), executor.getTaskCount(), executor.getCompletedTaskCount(),
4744
dtpExecutor.getQueueCapacity(), dtpExecutor.getQueue().size(), executor.getQueue().remainingCapacity(),

core/src/main/java/com/dtp/core/timer/QueueTimeoutTimerTask.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
import com.dtp.core.thread.DtpExecutor;
99
import lombok.extern.slf4j.Slf4j;
1010

11+
/**
12+
* A timer task used to handle queued timeout.
13+
*
14+
* @author kamtohung
15+
**/
1116
@Slf4j
1217
public class QueueTimeoutTimerTask implements TimerTask {
1318

1419
private final DtpExecutor dtpExecutor;
1520

1621
private final DtpRunnable runnable;
1722

18-
public QueueTimeoutTimerTask(DtpExecutor dtpExecutor,
19-
DtpRunnable runnable) {
23+
public QueueTimeoutTimerTask(DtpExecutor dtpExecutor, DtpRunnable runnable) {
2024
this.dtpExecutor = dtpExecutor;
2125
this.runnable = runnable;
2226
}
@@ -28,5 +32,4 @@ public void run(Timeout timeout) {
2832
log.warn("DynamicTp execute, queue timeout, tpName: {}, taskName: {}, traceId: {}",
2933
dtpExecutor.getThreadPoolName(), runnable.getTaskName(), runnable.getTraceId());
3034
}
31-
3235
}

core/src/main/java/com/dtp/core/timer/RunTimeoutTimerTask.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import com.dtp.core.thread.DtpExecutor;
99
import lombok.extern.slf4j.Slf4j;
1010

11-
11+
/**
12+
* A timer task used to handle run timeout.
13+
*
14+
* @author kamtohung
15+
**/
1216
@Slf4j
1317
public class RunTimeoutTimerTask implements TimerTask {
1418

@@ -18,9 +22,7 @@ public class RunTimeoutTimerTask implements TimerTask {
1822

1923
private final Thread thread;
2024

21-
public RunTimeoutTimerTask(DtpExecutor dtpExecutor,
22-
DtpRunnable runnable,
23-
Thread thread) {
25+
public RunTimeoutTimerTask(DtpExecutor dtpExecutor, DtpRunnable runnable, Thread thread) {
2426
this.dtpExecutor = dtpExecutor;
2527
this.runnable = runnable;
2628
this.thread = thread;
@@ -31,7 +33,8 @@ public void run(Timeout timeout) {
3133
dtpExecutor.getRunTimeoutCount().increment();
3234
AlarmManager.doAlarmAsync(dtpExecutor, NotifyItemEnum.RUN_TIMEOUT);
3335
log.warn("DynamicTp execute, run timeout, tpName: {}, taskName: {}, traceId: {}, stackTrace: {}",
34-
dtpExecutor.getThreadPoolName(), runnable.getTaskName(), runnable.getTraceId(), traceToString(thread.getStackTrace()));
36+
dtpExecutor.getThreadPoolName(), runnable.getTaskName(),
37+
runnable.getTraceId(), traceToString(thread.getStackTrace()));
3538
}
3639

3740

@@ -43,5 +46,4 @@ public String traceToString(StackTraceElement[] trace) {
4346
}
4447
return builder.toString();
4548
}
46-
4749
}

0 commit comments

Comments
 (0)