diff --git a/eden-components/eden-commons/src/main/java/org/ylzl/eden/commons/io/FileUtils.java b/eden-components/eden-commons/src/main/java/org/ylzl/eden/commons/io/FileUtils.java
index 219c4db9..9ca3dad6 100644
--- a/eden-components/eden-commons/src/main/java/org/ylzl/eden/commons/io/FileUtils.java
+++ b/eden-components/eden-commons/src/main/java/org/ylzl/eden/commons/io/FileUtils.java
@@ -55,10 +55,6 @@ public static boolean checkAndMkdirs(@NonNull File file) {
return true;
}
- public static void delete(File file) throws IOException {
- java.nio.file.Files.delete(Paths.get(file.getAbsolutePath()));
- }
-
public static void deleteIfExists(File file) throws IOException {
java.nio.file.Files.deleteIfExists(Paths.get(file.getAbsolutePath()));
}
diff --git a/eden-components/eden-dependencies/pom.xml b/eden-components/eden-dependencies/pom.xml
index 597fbab6..ab9dc874 100644
--- a/eden-components/eden-dependencies/pom.xml
+++ b/eden-components/eden-dependencies/pom.xml
@@ -68,17 +68,17 @@
3.3.0
3.26.0-GA
3.9
- 4.4
- 1.10.0
+ 4.5.0-M2
+ 1.12.0
1.9.4
- 1.10
+ 1.17.0
3.2.2
1.5
- 2.7
- 1.2
+ 2.16.1
+ 1.3.3
3.6.1
- 3.9.0
- 1.4
+ 3.11.1
+ 1.8.0
2.14.1
2.0.22
2.0.22
diff --git a/eden-components/eden-solutions/eden-distributed-uid/src/main/java/org/ylzl/eden/distributed/uid/integration/leaf/LeafSegmentGenerator.java b/eden-components/eden-solutions/eden-distributed-uid/src/main/java/org/ylzl/eden/distributed/uid/integration/leaf/LeafSegmentGenerator.java
index 6f0fae80..85a73ca7 100644
--- a/eden-components/eden-solutions/eden-distributed-uid/src/main/java/org/ylzl/eden/distributed/uid/integration/leaf/LeafSegmentGenerator.java
+++ b/eden-components/eden-solutions/eden-distributed-uid/src/main/java/org/ylzl/eden/distributed/uid/integration/leaf/LeafSegmentGenerator.java
@@ -135,7 +135,7 @@ private SpringLiquibase buildLiquibase(DataSource dataSource) {
}
private void updateCacheFromDb() {
- log.info("Update cache from db");
+ log.debug("Update cache from db");
try {
List dbTags = leafAllocDAO.getAllTags();
if (dbTags == null || dbTags.isEmpty()) {
@@ -155,7 +155,7 @@ private void updateCacheFromDb() {
segment.setMax(0);
segment.setStep(0);
cache.put(tag, buffer);
- log.debug("Add tag {} from db to IdCache, SegmentBuffer {}", tag, buffer);
+ log.debug("Add tag {} from db to IdCache", tag);
}
for (String tag : dbTags) {
removeTagsSet.remove(tag);
diff --git a/eden-components/eden-spring-boot-starters/eden-arthas-spring-boot-starter/src/main/java/org/ylzl/eden/arthas/spring/boot/autoconfigure/ArthasAutoConfiguration.java b/eden-components/eden-spring-boot-starters/eden-arthas-spring-boot-starter/src/main/java/org/ylzl/eden/arthas/spring/boot/autoconfigure/ArthasAutoConfiguration.java
index 0f5ea9db..87b62340 100644
--- a/eden-components/eden-spring-boot-starters/eden-arthas-spring-boot-starter/src/main/java/org/ylzl/eden/arthas/spring/boot/autoconfigure/ArthasAutoConfiguration.java
+++ b/eden-components/eden-spring-boot-starters/eden-arthas-spring-boot-starter/src/main/java/org/ylzl/eden/arthas/spring/boot/autoconfigure/ArthasAutoConfiguration.java
@@ -20,8 +20,10 @@
import com.alibaba.arthas.spring.ArthasProperties;
import com.alibaba.arthas.spring.StringUtils;
import com.taobao.arthas.agent.attach.ArthasAgent;
+import com.taobao.arthas.agent.attach.AttachArthasClassloader;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import net.bytebuddy.agent.ByteBuddyAgent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -37,8 +39,16 @@
import org.ylzl.eden.arthas.spring.boot.env.SpringArthasProperties;
import org.ylzl.eden.spring.framework.bootstrap.constant.SpringProperties;
-import java.util.HashMap;
-import java.util.Map;
+import java.io.File;
+import java.lang.instrument.Instrumentation;
+import java.net.URL;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Arthas 自动装配
@@ -66,6 +76,20 @@ public class ArthasAutoConfiguration {
private static final String ARTHAS_AGENT_START_SUCCESS = "Arthas agent start success";
+ private static final int TEMP_DIR_ATTEMPTS = 10000;
+
+ private static final Pattern ARTHAS_DIR_PATTERN = Pattern.compile("^arthas-(\\d{13})-.*$");
+
+ private static final String ARTHAS_BIN_ZIP = "arthas-bin.zip";
+
+ private static final String ARTHAS_CORE_JAR = "arthas-core.jar";
+
+ private static final String ARTHAS_BOOTSTRAP = "com.taobao.arthas.core.server.ArthasBootstrap";
+
+ private static final String GET_INSTANCE = "getInstance";
+
+ private static final String DESTROY = "destroy";
+
private final ApplicationContext applicationContext;
private final Environment environment;
@@ -83,10 +107,10 @@ public ArthasEnvironmentChangeListener arthasEnvironmentChangeListener(
@Bean
public ArthasAgent arthasAgent(@Autowired @Qualifier(ARTHAS_CONFIG_MAP) Map arthasConfigMap) {
arthasConfigMap = StringUtils.removeDashKey(arthasConfigMap);
- return initArthasAgent(arthasConfigMap, environment, arthasProperties);
+ return init(arthasConfigMap, environment, arthasProperties);
}
- public static ArthasAgent initArthasAgent(Map arthasConfigMap, Environment environment,
+ public static ArthasAgent init(Map arthasConfigMap, Environment environment,
ArthasProperties arthasProperties) {
ArthasProperties.updateArthasConfigMapDefaultValue(arthasConfigMap);
@@ -107,4 +131,80 @@ public static ArthasAgent initArthasAgent(Map arthasConfigMap, E
log.info(ARTHAS_AGENT_START_SUCCESS);
return arthasAgent;
}
+
+ public static void destroy(Map arthasConfigMap,
+ ArthasProperties arthasProperties) {
+ String arthasHome = arthasProperties.getHome();
+ try {
+ Instrumentation instrumentation = ByteBuddyAgent.install();
+
+ if (arthasHome == null || arthasHome.trim().isEmpty()) {
+ ClassLoader classLoader = ArthasAgent.class.getClassLoader();
+ URL coreJarUrl = classLoader.getResource(ARTHAS_BIN_ZIP);
+ if (coreJarUrl != null) {
+ File tempArthasDir = findTempDir();
+ arthasHome = tempArthasDir.getAbsolutePath();
+ } else {
+ throw new IllegalArgumentException("can not getResources arthas-bin.zip from classloader: "
+ + classLoader);
+ }
+ }
+ File arthasCoreJarFile = new File(arthasHome, ARTHAS_CORE_JAR);
+ if (!arthasCoreJarFile.exists()) {
+ throw new IllegalArgumentException("can not find arthas-core.jar under arthasHome: {}" + arthasHome);
+ }
+ AttachArthasClassloader arthasClassLoader = new AttachArthasClassloader(
+ new URL[] { arthasCoreJarFile.toURI().toURL() });
+ Class> bootstrapClass = arthasClassLoader.loadClass(ARTHAS_BOOTSTRAP);
+
+ Object bootstrap = bootstrapClass.getMethod(GET_INSTANCE, Instrumentation.class, Map.class)
+ .invoke(null, instrumentation, arthasConfigMap);
+ bootstrapClass.getMethod(DESTROY).invoke(bootstrap);
+ } catch (Throwable e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+
+ private static List listArthasDirs(File baseDir) {
+ return Stream.of(baseDir.listFiles((dir, name) -> ARTHAS_DIR_PATTERN.matcher(name).matches()))
+ .collect(Collectors.toList());
+ }
+
+ private static Date extractTimestamp(File dir) {
+ Matcher matcher = ARTHAS_DIR_PATTERN.matcher(dir.getName());
+ if (matcher.matches()) {
+ String timestampStr = matcher.group(1);
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+ try {
+ return sdf.parse(timestampStr);
+ } catch (ParseException e) {
+ throw new IllegalArgumentException("Invalid timestamp format in directory name: " + dir.getName(), e);
+ }
+ }
+ return null;
+ }
+
+ private static File findLatestArthasDir(File baseDir) {
+ List dirs = listArthasDirs(baseDir);
+ if (!dirs.isEmpty()) {
+ return dirs.stream()
+ .max(Comparator.comparing(ArthasAutoConfiguration::extractTimestamp))
+ .orElse(null);
+ }
+ return null;
+ }
+
+ public static File findTempDir() {
+ File baseDir = new File(System.getProperty("java.io.tmpdir"));
+ String baseName = "arthas-" + System.currentTimeMillis() + "-";
+
+ // 尝试查找时间戳最大的以 "arthas-" 开头的目录
+ File latestDir = findLatestArthasDir(baseDir);
+ if (latestDir != null) {
+ return latestDir;
+ }
+
+ throw new IllegalStateException("Failed to find directory within " + TEMP_DIR_ATTEMPTS
+ + " attempts (tried " + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')');
+ }
}
diff --git a/eden-components/eden-spring-boot-starters/eden-arthas-spring-boot-starter/src/main/java/org/ylzl/eden/arthas/spring/boot/autoconfigure/ArthasEnvironmentChangeListener.java b/eden-components/eden-spring-boot-starters/eden-arthas-spring-boot-starter/src/main/java/org/ylzl/eden/arthas/spring/boot/autoconfigure/ArthasEnvironmentChangeListener.java
index 3683b1af..97a54c9e 100644
--- a/eden-components/eden-spring-boot-starters/eden-arthas-spring-boot-starter/src/main/java/org/ylzl/eden/arthas/spring/boot/autoconfigure/ArthasEnvironmentChangeListener.java
+++ b/eden-components/eden-spring-boot-starters/eden-arthas-spring-boot-starter/src/main/java/org/ylzl/eden/arthas/spring/boot/autoconfigure/ArthasEnvironmentChangeListener.java
@@ -46,11 +46,11 @@ public class ArthasEnvironmentChangeListener implements ApplicationListener