diff --git a/backend/app/src/main/java/io/metersphere/listener/AppStartListener.java b/backend/app/src/main/java/io/metersphere/listener/AppStartListener.java index 8013056a12..f59a8f7035 100644 --- a/backend/app/src/main/java/io/metersphere/listener/AppStartListener.java +++ b/backend/app/src/main/java/io/metersphere/listener/AppStartListener.java @@ -9,6 +9,7 @@ import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.service.BaseScheduleService; import io.metersphere.system.service.PluginLoadService; +import io.metersphere.system.uid.impl.DefaultUidGenerator; import io.minio.MinioClient; import jakarta.annotation.Resource; import org.springframework.boot.ApplicationArguments; @@ -26,9 +27,13 @@ public class AppStartListener implements ApplicationRunner { @Resource private BaseScheduleService baseScheduleService; + @Resource + private DefaultUidGenerator defaultUidGenerator; + @Override public void run(ApplicationArguments args) throws Exception { LogUtils.info("================= 应用启动 ================="); + defaultUidGenerator.afterPropertiesSet(); // 初始化MinIO配置 ((MinioRepository) FileCenter.getRepository(StorageType.MINIO)).init(minioClient); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/uid/IDGenerator.java b/backend/services/system-setting/src/main/java/io/metersphere/system/uid/IDGenerator.java index 20e576b9ae..f25901ef35 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/uid/IDGenerator.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/uid/IDGenerator.java @@ -1,13 +1,13 @@ package io.metersphere.system.uid; -import io.metersphere.system.uid.impl.CachedUidGenerator; import io.metersphere.sdk.util.CommonBeanFactory; +import io.metersphere.system.uid.impl.DefaultUidGenerator; public class IDGenerator { - private static final CachedUidGenerator DEFAULT_UID_GENERATOR; + private static final DefaultUidGenerator DEFAULT_UID_GENERATOR; static { - DEFAULT_UID_GENERATOR = CommonBeanFactory.getBean(CachedUidGenerator.class); + DEFAULT_UID_GENERATOR = CommonBeanFactory.getBean(DefaultUidGenerator.class); } /** diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/uid/impl/CachedUidGenerator.java b/backend/services/system-setting/src/main/java/io/metersphere/system/uid/impl/CachedUidGenerator.java deleted file mode 100644 index 1c1f4e2771..0000000000 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/uid/impl/CachedUidGenerator.java +++ /dev/null @@ -1,147 +0,0 @@ - -package io.metersphere.system.uid.impl; - -import io.metersphere.sdk.exception.MSException; -import io.metersphere.system.uid.BitsAllocator; -import io.metersphere.system.uid.buffer.BufferPaddingExecutor; -import io.metersphere.system.uid.buffer.RejectedPutBufferHandler; -import io.metersphere.system.uid.buffer.RejectedTakeBufferHandler; -import io.metersphere.system.uid.buffer.RingBuffer; -import io.metersphere.sdk.util.LogUtils; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.List; - -/** - * from {@link DefaultUidGenerator}, based on a lock free {@link RingBuffer}
- */
-@Service
-public class CachedUidGenerator extends DefaultUidGenerator implements DisposableBean, InitializingBean {
- private static final int DEFAULT_BOOST_POWER = 3;
-
- /**
- * Spring properties
- */
- private int boostPower = DEFAULT_BOOST_POWER;
- private Long scheduleInterval;
-
- private RejectedPutBufferHandler rejectedPutBufferHandler;
- private RejectedTakeBufferHandler rejectedTakeBufferHandler;
-
- /**
- * RingBuffer
- */
- private RingBuffer ringBuffer;
- private BufferPaddingExecutor bufferPaddingExecutor;
-
- @Override
- public void afterPropertiesSet() {
- // initialize workerId & bitsAllocator
- super.afterPropertiesSet();
-
- // initialize RingBuffer & RingBufferPaddingExecutor
- this.initRingBuffer();
- LogUtils.info("Initialized RingBuffer successfully.");
- }
-
- @Override
- public long getUID() {
- try {
- return ringBuffer.take();
- } catch (Exception e) {
- LogUtils.error("Generate unique id exception. ", e);
- throw new MSException(e);
- }
- }
-
- @Override
- public String parseUID(long uid) {
- return super.parseUID(uid);
- }
-
- @Override
- public void destroy() throws Exception {
- bufferPaddingExecutor.shutdown();
- }
-
- /**
- * Get the UIDs in the same specified second under the max sequence
- * * @return UID list, size of {@link BitsAllocator#getMaxSequence()} + 1
- */
- protected List