Skip to content

Commit 9181447

Browse files
committed
init
1 parent 430e073 commit 9181447

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.noear</groupId>
9+
<artifactId>solon-parent</artifactId>
10+
<version>3.8.0-M3</version>
11+
<relativePath />
12+
</parent>
13+
14+
<artifactId>solon-for-jdk21</artifactId>
15+
<name>${project.artifactId}</name>
16+
<packaging>jar</packaging>
17+
18+
<properties>
19+
<java.version>25</java.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.noear</groupId>
25+
<artifactId>solon</artifactId>
26+
</dependency>
27+
28+
29+
<dependency>
30+
<groupId>org.noear</groupId>
31+
<artifactId>solon-test</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
</dependencies>
35+
36+
</project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.noear.solon.util;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.lang.ScopedValue;
7+
import java.util.function.Supplier;
8+
9+
public class ScopeLocalJdk25<T> implements ScopeLocal<T> {
10+
private static final Logger log = LoggerFactory.getLogger(ScopeLocalJdk25.class);
11+
private final ScopedValue<T> ref = ScopedValue.newInstance();
12+
13+
public ScopeLocalJdk25() {
14+
15+
}
16+
17+
public ScopeLocalJdk25(Class<?> applyFor) {
18+
19+
}
20+
21+
@Override
22+
public T get() {
23+
return ref.get();
24+
}
25+
26+
@Override
27+
public void with(T value, Runnable runnable) {
28+
ref.where(ref, value).run(runnable);
29+
}
30+
31+
@Override
32+
public <R> R with(T value, Supplier<R> callable) {
33+
return ref.where(ref, value).call(callable::get);
34+
}
35+
36+
@Override
37+
public <X extends Throwable> void withOrThrow(T value, RunnableTx<X> runnable) throws X {
38+
ref.where(ref, value).call(() -> {
39+
runnable.run();
40+
return null;
41+
});
42+
}
43+
44+
@Override
45+
public <R, X extends Throwable> R withOrThrow(T value, CallableTx<? extends R, X> callable) throws X {
46+
return ref.where(ref, value).call(callable::call);
47+
}
48+
49+
@Override
50+
public ScopeLocal<T> set(T value) {
51+
log.error("ScopeLocal.set is invalid, please use ScopeLocal.with");
52+
return null;
53+
}
54+
55+
@Override
56+
public void remove() {
57+
log.error("ScopeLocal.remove is invalid, please use ScopeLocal.with");
58+
}
59+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package demo;
2+
3+
import org.noear.solon.Solon;
4+
import org.noear.solon.util.ScopeLocalJdk25;
5+
6+
/**
7+
*
8+
* @author noear 2025/12/18 created
9+
*
10+
*/
11+
public class ScopeLocalDemo {
12+
public static void main(String[] args) {
13+
Solon.start(ScopeLocalDemo.class, args, app->{
14+
app.factories().scopeLocalFactory(ScopeLocalJdk25::new);
15+
});
16+
}
17+
}

0 commit comments

Comments
 (0)