Skip to content

Commit

Permalink
[ISSUE dromara#531] add DtpException for missing jackson-datatype-jsr…
Browse files Browse the repository at this point in the history
…310 dependency
  • Loading branch information
KamToHung committed Feb 23, 2025
1 parent 4b9fe75 commit 7fe3c3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.extern.slf4j.Slf4j;
import org.dromara.dynamictp.common.ex.DtpException;

import java.io.IOException;
import java.lang.reflect.Type;
Expand All @@ -44,7 +45,11 @@
public class JacksonParser extends AbstractJsonParser {

private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

private static final String PACKAGE_NAME = "com.fasterxml.jackson.databind.ObjectMapper";

private static final String JAVA_TIME_MODULE_CLASS_NAME = "com.fasterxml.jackson.datatype.jsr310.JavaTimeModule";

private volatile ObjectMapper mapper;

@Override
Expand Down Expand Up @@ -79,7 +84,11 @@ private ObjectMapper getMapper() {
}

protected ObjectMapper createMapper() {
// 只提供最简单的方案
try {
Class.forName(JAVA_TIME_MODULE_CLASS_NAME);
} catch (ClassNotFoundException e) {
throw new DtpException("Please add jackson-datatype-jsr310 dependency");
}
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@
class ScheduledDtpExecutorTest {

@Test
void schedule() {
void schedule() throws InterruptedException {
ScheduledDtpExecutor dtpExecutor12 = (ScheduledDtpExecutor) DtpRegistry.getExecutor("dtpExecutor12");
System.out.println(dtpExecutor12.getClass());
dtpExecutor12.scheduleAtFixedRate(() -> {
System.out.println(Thread.currentThread().getName() + "进来了," +
"当前时间是 " + LocalDateTime.now());
}, 10, 5, TimeUnit.SECONDS);
dtpExecutor12.shutdownNow();
// dtpExecutor12.shutdownNow();
TimeUnit.SECONDS.sleep(10000);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ dynamictp:
preStartAllCoreThreads: false # 是否预热所有核心线程,默认false
runTimeout: 200 # 任务执行超时阈值,目前只做告警用,单位(ms)
queueTimeout: 100 # 任务在队列等待超时阈值,目前只做告警用,单位(ms)
taskWrapperNames: ["ttl"] # 任务包装器名称,集成TaskWrapper接口
taskWrapperNames: ["ttl", "mdc"] # 任务包装器名称,集成TaskWrapper接口
notifyItems: # 报警项,不配置自动会按默认值配置(变更通知、容量报警、活性报警、拒绝报警、任务超时报警)
- type: capacity # 报警项类型,查看源码 NotifyTypeEnum枚举类
enabled: true
Expand Down

0 comments on commit 7fe3c3e

Please sign in to comment.