Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

## 项目概述

springboot-framework 是一个基于 Spring Boot 3.3.5(Java 17)的多模块企业级开发框架,由 CodingApi 团队维护。核心定位是为领域驱动设计(DDD)与事件风暴提供开箱即用的基础设施,当前版本为 `3.4.54`。
springboot-framework 是一个基于 Spring Boot 3.3.5(Java 17)的多模块企业级开发框架,由 CodingApi 团队维护。核心定位是为领域驱动设计(DDD)与事件风暴提供开箱即用的基础设施,当前版本为 `3.4.55`。

**回复语言**:请使用中文进行回答。

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-cmd-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-cmd-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/example-domain-leave/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-domain</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/example-domain-user/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-domain</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion example/example-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
</parent>

<artifactId>example-interface</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion example/example-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.54</version>
<version>3.4.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.3.5</version>
<version>3.4.55</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>springboot-example</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>

<name>springboot-example</name>
<description>springboot-example project for Spring Boot</description>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>

<url>https://github.com/codingapi/springboot-framewrok</url>
<name>springboot-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-authorization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
</parent>

<name>springboot-starter-data-authorization</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.54</version>
<version>3.4.55</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.54</version>
<version>3.4.55</version>
</parent>

<name>springboot-starter-flow</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-script/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.54</version>
<version>3.4.55</version>
</parent>

<name>springboot-starter-script</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
import com.codingapi.springboot.script.repository.TempGroovyScriptRepositoryContext;
import lombok.Getter;

import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
* 临时脚本数据上下文管理对象
Expand All @@ -15,41 +21,58 @@ public class TempGroovyScriptContext {
@Getter
private final static TempGroovyScriptContext instance = new TempGroovyScriptContext();

/**
* 共享的清理调度线程(daemon)
* 所有临时脚本共用一个调度线程,避免每个脚本创建原生线程导致线程泄漏
*/
private final static ScheduledExecutorService SCHEDULER = Executors.newSingleThreadScheduledExecutor(r -> {
Thread thread = new Thread(r, "temp-groovy-script-clear");
thread.setDaemon(true);
return thread;
});

private final Map<String, ClearJob> cache;

private TempGroovyScriptContext() {
this.cache = new HashMap<>();
this.cache = new ConcurrentHashMap<>();
}

private static class ClearJob {

@Getter
private final TempGroovyScript tempGroovyScript;

private final Timer timer;
private final ScheduledFuture<?> future;

public ClearJob(TempGroovyScript groovyScript) {
this.tempGroovyScript = groovyScript;
this.timer = new Timer();
this.initTimer();
// clearTime 为绝对到期时间戳,需换算为相对延迟
long delay = groovyScript.getClearTime() - System.currentTimeMillis();
this.future = SCHEDULER.schedule(this::expire, delay, TimeUnit.MILLISECONDS);
}

public GroovyScript getGroovyScript() {
return this.tempGroovyScript.getGroovyScript();
}

private void initTimer() {
this.timer.schedule(new TimerTask() {
@Override
public void run() {
TempGroovyScriptContext.getInstance().remove(getKey());
}
}, tempGroovyScript.getClearTime());
}

public String getKey() {
return tempGroovyScript.getKey();
}

/**
* 到期清理
* 仅当缓存中仍是当前任务时才删除,避免过期任务误删已被刷新的脚本
*/
private void expire() {
TempGroovyScriptContext.getInstance().removeIfCurrent(getKey(), this);
}

/**
* 取消定时清理任务
*/
private void cancel() {
this.future.cancel(false);
}
}

/**
Expand All @@ -60,7 +83,17 @@ public String getKey() {
public void save(GroovyScript script) {
if (script != null) {
long tempValidTime = PropertiesContext.getInstance().getTempValidTime();
this.cache.put(script.getKey(), new ClearJob(new TempGroovyScript(script, tempValidTime + System.currentTimeMillis())));
this.put(script.getKey(), new ClearJob(new TempGroovyScript(script, tempValidTime + System.currentTimeMillis())));
}
}

/**
* 写入缓存,覆盖时取消旧任务的定时清理
*/
private void put(String key, ClearJob job) {
ClearJob previous = this.cache.put(key, job);
if (previous != null) {
previous.cancel();
}
}

Expand All @@ -73,7 +106,7 @@ public void loadAll(List<TempGroovyScript> groovyScripts) {
if (groovyScript.isExpired()) {
this.remove(groovyScript.getKey());
} else {
this.cache.put(groovyScript.getKey(), new ClearJob(groovyScript));
this.put(groovyScript.getKey(), new ClearJob(groovyScript));
}
}
}
Expand All @@ -93,10 +126,23 @@ public List<TempGroovyScript> findAll() {
* @param key 脚本key
*/
public void remove(String key) {
this.cache.remove(key);
ClearJob job = this.cache.remove(key);
if (job != null) {
job.cancel();
}
TempGroovyScriptRepositoryContext.getInstance().delete(key);
}

/**
* 仅当缓存中的任务仍为当前任务时删除,防止过期任务误删已被刷新的脚本。
* 使用 ConcurrentHashMap.remove(key, value) 原子判断 + 删除,避免 check-then-act 竞态
*/
private void removeIfCurrent(String key, ClearJob job) {
if (this.cache.remove(key, job)) {
job.cancel();
TempGroovyScriptRepositoryContext.getInstance().delete(key);
}
}

/**
* 脚本总数量
Expand All @@ -118,7 +164,11 @@ public GroovyScript getGroovyScript(String key) {
if (job == null) {
TempGroovyScript groovyScript = TempGroovyScriptRepositoryContext.getInstance().get(key);
if (groovyScript != null) {
this.cache.put(key, new ClearJob(groovyScript));
if (groovyScript.isExpired()) {
this.remove(key);
return null;
}
this.put(key, new ClearJob(groovyScript));
return groovyScript.getGroovyScript();
}
return null;
Expand All @@ -131,6 +181,9 @@ public GroovyScript getGroovyScript(String key) {
* 清空脚本数据
*/
public void clear() {
for (ClearJob job : this.cache.values()) {
job.cancel();
}
this.cache.clear();
}
}
Loading