fix: ip获取异常导致的实例运行异常.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.serliunx.ddns.constant;
|
package com.serliunx.ddns.constant;
|
||||||
|
|
||||||
|
import com.serliunx.ddns.support.ipprovider.IcanhazipProvider;
|
||||||
import com.serliunx.ddns.support.ipprovider.IpApiProvider;
|
import com.serliunx.ddns.support.ipprovider.IpApiProvider;
|
||||||
import com.serliunx.ddns.support.ipprovider.Provider;
|
import com.serliunx.ddns.support.ipprovider.Provider;
|
||||||
|
|
||||||
@@ -18,6 +19,11 @@ public enum IpProviderType {
|
|||||||
*/
|
*/
|
||||||
IP_API(new IpApiProvider()),
|
IP_API(new IpApiProvider()),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ip数据提供商 <a href="https://icanhazip.com/">icanhazip</a>
|
||||||
|
*/
|
||||||
|
I_CAN_HAZ_IP(new IcanhazipProvider()),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Provider provider;
|
private final Provider provider;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import com.serliunx.ddns.core.context.MultipleSourceInstanceContext;
|
|||||||
import com.serliunx.ddns.core.instance.Instance;
|
import com.serliunx.ddns.core.instance.Instance;
|
||||||
import com.serliunx.ddns.support.ipprovider.Provider;
|
import com.serliunx.ddns.support.ipprovider.Provider;
|
||||||
import com.serliunx.ddns.support.ipprovider.ScheduledProvider;
|
import com.serliunx.ddns.support.ipprovider.ScheduledProvider;
|
||||||
import com.serliunx.ddns.support.thread.TaskThreadFactory;
|
import com.serliunx.ddns.support.thread.ThreadFactoryBuilder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -166,7 +166,8 @@ public final class SystemInitializer implements Refreshable, Clearable {
|
|||||||
|
|
||||||
private void initThreadPool(int coreSize) {
|
private void initThreadPool(int coreSize) {
|
||||||
Assert.isLargerThan(coreSize, 1);
|
Assert.isLargerThan(coreSize, 1);
|
||||||
scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(coreSize, new TaskThreadFactory());
|
scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(coreSize, ThreadFactoryBuilder.builder()
|
||||||
|
.ofNamePattern("ddns-task-%s"));
|
||||||
|
|
||||||
// 初始化一个线程保活
|
// 初始化一个线程保活
|
||||||
scheduledThreadPoolExecutor.submit(() -> {});
|
scheduledThreadPoolExecutor.submit(() -> {});
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class ScheduledProvider extends AbstractProvider {
|
|||||||
internalCache = internalProvider.get();
|
internalCache = internalProvider.get();
|
||||||
|
|
||||||
if (valueConsumer != null) {
|
if (valueConsumer != null) {
|
||||||
valueConsumer.accept(cache);
|
valueConsumer.accept(internalCache);
|
||||||
}
|
}
|
||||||
}, 0, timePeriod, TimeUnit.SECONDS);
|
}, 0, timePeriod, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.serliunx.ddns.support.thread;
|
|
||||||
|
|
||||||
import com.serliunx.ddns.support.Assert;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 简易的实例活动相关的线程工厂, 仅仅定义了线程的名称规则.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
|
||||||
* @version 1.0.0
|
|
||||||
* @since 2024/5/15
|
|
||||||
*/
|
|
||||||
public class TaskThreadFactory implements ThreadFactory {
|
|
||||||
|
|
||||||
private final AtomicInteger count = new AtomicInteger(0);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Thread newThread(@NotNull Runnable r) {
|
|
||||||
Assert.notNull(r);
|
|
||||||
return new Thread(r, String.format(getNamePattern(), count.getAndIncrement()));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getNamePattern() {
|
|
||||||
return "ddns-task-%s";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.serliunx.ddns.support.thread;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同 {@link TaskThreadFactory}, 暂未使用.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
|
||||||
* @version 1.0.0
|
|
||||||
* @since 2024/5/15
|
|
||||||
*/
|
|
||||||
public class UtilThreadFactory extends TaskThreadFactory {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getNamePattern() {
|
|
||||||
return "ddns-util-%s";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user