From 5f44393f0027a1b708b9a014cf9ce141fd13a0ac Mon Sep 17 00:00:00 2001 From: seakider Date: Tue, 13 Aug 2024 23:19:40 +0800 Subject: [PATCH 1/2] Improvement - quarkus should make an attempt to read config file using Thread's ContextClassLoader use try-with-resources Statement Signed-off-by: seakider --- .../runtime/RedissonClientProducer.java | 29 +++++++++---------- .../runtime/RedissonClientProducer.java | 27 ++++++++--------- .../runtime/RedissonClientProducer.java | 27 ++++++++--------- 3 files changed, 37 insertions(+), 46 deletions(-) diff --git a/redisson-quarkus/redisson-quarkus-16/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java b/redisson-quarkus/redisson-quarkus-16/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java index 80d325b4e..a56f20c9e 100644 --- a/redisson-quarkus/redisson-quarkus-16/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java +++ b/redisson-quarkus/redisson-quarkus-16/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java @@ -34,7 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.time.Duration; -import java.util.*; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -57,27 +57,24 @@ public class RedissonClientProducer { @Singleton @DefaultBean public RedissonClient create() throws IOException { - InputStream configStream; + String config = null; Optional configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class); - if (configFile.isPresent()) { - configStream = getClass().getResourceAsStream(configFile.get()); - if (configStream == null) { - configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile.get()); + String configFileName = configFile.orElse("redisson.yaml"); + try (InputStream configStream = Optional.ofNullable(getClass().getResourceAsStream(configFileName)) + .orElse(Thread.currentThread().getContextClassLoader().getResourceAsStream(configFileName)) + ) { + if (configStream != null) { + byte[] array = new byte[configStream.available()]; + if (configStream.read(array) != -1) { + config = new String(array, StandardCharsets.UTF_8); + } } - } else { - configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml"); } - String config; - if (configStream != null) { - byte[] array = new byte[configStream.available()]; - configStream.read(array); - config = new String(array, StandardCharsets.UTF_8); - } else { + if (config == null) { Stream s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false); - String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { + config = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { return ConfigProvider.getConfig().getValue(prop, String.class); }, false); - config = yaml; } ConfigSupport support = new ConfigSupport() { diff --git a/redisson-quarkus/redisson-quarkus-20/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java b/redisson-quarkus/redisson-quarkus-20/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java index 5cfe5111a..06f315013 100644 --- a/redisson-quarkus/redisson-quarkus-20/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java +++ b/redisson-quarkus/redisson-quarkus-20/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java @@ -57,27 +57,24 @@ public class RedissonClientProducer { @Singleton @DefaultBean public RedissonClient create() throws IOException { - InputStream configStream; + String config = null; Optional configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class); - if (configFile.isPresent()) { - configStream = getClass().getResourceAsStream(configFile.get()); - if (configStream == null) { - configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile.get()); + String configFileName = configFile.orElse("redisson.yaml"); + try (InputStream configStream = Optional.ofNullable(getClass().getResourceAsStream(configFileName)) + .orElse(Thread.currentThread().getContextClassLoader().getResourceAsStream(configFileName)) + ) { + if (configStream != null) { + byte[] array = new byte[configStream.available()]; + if (configStream.read(array) != -1) { + config = new String(array, StandardCharsets.UTF_8); + } } - } else { - configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml"); } - String config; - if (configStream != null) { - byte[] array = new byte[configStream.available()]; - configStream.read(array); - config = new String(array, StandardCharsets.UTF_8); - } else { + if (config == null) { Stream s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false); - String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { + config = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { return ConfigProvider.getConfig().getValue(prop, String.class); }, false); - config = yaml; } ConfigSupport support = new ConfigSupport() { diff --git a/redisson-quarkus/redisson-quarkus-30/cdi/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java b/redisson-quarkus/redisson-quarkus-30/cdi/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java index f42b82e80..53795ae90 100644 --- a/redisson-quarkus/redisson-quarkus-30/cdi/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java +++ b/redisson-quarkus/redisson-quarkus-30/cdi/runtime/src/main/java/io/quarkus/redisson/client/runtime/RedissonClientProducer.java @@ -57,27 +57,24 @@ public class RedissonClientProducer { @Singleton @DefaultBean public RedissonClient create() throws IOException { - InputStream configStream; + String config = null; Optional configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class); - if (configFile.isPresent()) { - configStream = getClass().getResourceAsStream(configFile.get()); - if (configStream == null) { - configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile.get()); + String configFileName = configFile.orElse("redisson.yaml"); + try (InputStream configStream = Optional.ofNullable(getClass().getResourceAsStream(configFileName)) + .orElse(Thread.currentThread().getContextClassLoader().getResourceAsStream(configFileName)) + ) { + if (configStream != null) { + byte[] array = new byte[configStream.available()]; + if (configStream.read(array) != -1) { + config = new String(array, StandardCharsets.UTF_8); + } } - } else { - configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml"); } - String config; - if (configStream != null) { - byte[] array = new byte[configStream.available()]; - configStream.read(array); - config = new String(array, StandardCharsets.UTF_8); - } else { + if (config == null) { Stream s = StreamSupport.stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false); - String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { + config = PropertiesConvertor.toYaml("quarkus.redisson.", s.sorted().collect(Collectors.toList()), prop -> { return ConfigProvider.getConfig().getValue(prop, String.class); }, false); - config = yaml; } ConfigSupport support = new ConfigSupport() { From f40f634ddc4174852e32222da85685b44a457669 Mon Sep 17 00:00:00 2001 From: seakider Date: Wed, 14 Aug 2024 21:40:24 +0800 Subject: [PATCH 2/2] Improvement - quarkus should make an attempt to read config file using Thread's ContextClassLoader remove redundant file Signed-off-by: seakider --- .../runtime/RedissonConfig.class | Bin 556 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 redisson-quarkus/redisson-quarkus-16/runtime/RedissonConfig.class diff --git a/redisson-quarkus/redisson-quarkus-16/runtime/RedissonConfig.class b/redisson-quarkus/redisson-quarkus-16/runtime/RedissonConfig.class deleted file mode 100644 index 40496b184c265cd7f371457eec5c0b60fc702440..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 556 zcmb7BJx>Bb5Pb_ACm#v|+S{Rp8>1bBhQ!8G63@^t$9gUvd$_mD|FSZ%@CW##jB^Kt zCRo_K%zHcYW@qN}>-_`36^`pDqwAyRPHnb-2ClOG`4VshRT>GVQ2+P%R9H6N%J6P2`QZ*jYKjPM&*1fR_v3?7%l^q@)sw}v&*=V zbCqSO=24=gw%j;v)l%~Nt-cw9I@iP0nMhu%+`jw!`8?la6LmBgF8*!K&@S#!EOatk z$jIUZCAt_0X-Ig4)q?pH?fu|2;`BE(2%D6_3l4Z^Z(y%Q$v$C~WT1@$!e$YBXb}g+ JhlC|`z5xLElL7z$