diff --git a/net/src/main/java/com/zfoo/net/util/security/AesUtils.java b/net/src/main/java/com/zfoo/net/util/security/AesUtils.java index 369f07c7..7bf10a0c 100644 --- a/net/src/main/java/com/zfoo/net/util/security/AesUtils.java +++ b/net/src/main/java/com/zfoo/net/util/security/AesUtils.java @@ -13,16 +13,14 @@ package com.zfoo.net.util.security; +import com.zfoo.protocol.util.FastThreadLocalAdapter; import com.zfoo.protocol.util.StringUtils; -import io.netty.util.concurrent.FastThreadLocal; import javax.crypto.Cipher; -import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; -import java.security.InvalidKeyException; import java.security.Key; -import java.security.NoSuchAlgorithmException; import java.util.Base64; +import java.util.function.Supplier; /** * AES加密和解密 @@ -53,23 +51,31 @@ public abstract class AesUtils { } } - private static final FastThreadLocal LOCAL_ENCRYPT_CIPHER = new FastThreadLocal() { + private static final FastThreadLocalAdapter LOCAL_ENCRYPT_CIPHER = new FastThreadLocalAdapter<>(new Supplier<>() { @Override - protected Cipher initialValue() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { - var cipher = Cipher.getInstance(ALGORITHM_STR); - cipher.init(Cipher.ENCRYPT_MODE, KEY); - return cipher; + public Cipher get() { + try { + Cipher cipher = Cipher.getInstance(ALGORITHM_STR); + cipher.init(Cipher.ENCRYPT_MODE, KEY); + return cipher; + } catch (Exception e) { + throw new RuntimeException(e); + } } - }; + }); - private static final FastThreadLocal LOCAL_DECRYPT_CIPHER = new FastThreadLocal() { + private static final FastThreadLocalAdapter LOCAL_DECRYPT_CIPHER = new FastThreadLocalAdapter(new Supplier() { @Override - protected Cipher initialValue() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { - var cipher = Cipher.getInstance(ALGORITHM_STR); - cipher.init(Cipher.DECRYPT_MODE, KEY); - return cipher; + public Cipher get() { + try { + var cipher = Cipher.getInstance(ALGORITHM_STR); + cipher.init(Cipher.DECRYPT_MODE, KEY); + return cipher; + } catch (Exception e) { + throw new RuntimeException(e); + } } - }; + }); /** diff --git a/scheduler/src/main/java/com/zfoo/scheduler/util/TimeUtils.java b/scheduler/src/main/java/com/zfoo/scheduler/util/TimeUtils.java index ee5d317a..1bf24e9a 100644 --- a/scheduler/src/main/java/com/zfoo/scheduler/util/TimeUtils.java +++ b/scheduler/src/main/java/com/zfoo/scheduler/util/TimeUtils.java @@ -13,8 +13,8 @@ package com.zfoo.scheduler.util; +import com.zfoo.protocol.util.FastThreadLocalAdapter; import com.zfoo.scheduler.manager.SchedulerBus; -import io.netty.util.concurrent.FastThreadLocal; import org.springframework.scheduling.support.CronExpression; import java.text.ParseException; @@ -55,26 +55,11 @@ public abstract class TimeUtils { // 统一的时间格式模板 public static final String DATE_FORMAT_TEMPLATE_FOR_DAY = "yyyy-MM-dd"; - private static final FastThreadLocal DATE_FORMAT = new FastThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat(DATE_FORMAT_TEMPLATE); - } - }; + private static final FastThreadLocalAdapter DATE_FORMAT = new FastThreadLocalAdapter<>(() -> new SimpleDateFormat(DATE_FORMAT_TEMPLATE)); - private static final FastThreadLocal SIMPLE_DATE_FORMAT = new FastThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat(SIMPLE_DATE_FORMAT_TEMPLATE); - } - }; + private static final FastThreadLocalAdapter SIMPLE_DATE_FORMAT = new FastThreadLocalAdapter<>(() -> new SimpleDateFormat(SIMPLE_DATE_FORMAT_TEMPLATE)); - private static final FastThreadLocal DATE_FORMAT_FOR_DAY = new FastThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat(DATE_FORMAT_TEMPLATE_FOR_DAY); - } - }; + private static final FastThreadLocalAdapter DATE_FORMAT_FOR_DAY = new FastThreadLocalAdapter<>(() -> new SimpleDateFormat(DATE_FORMAT_TEMPLATE_FOR_DAY)); static { currentTimeMillis();