From afe4536a6597ae896b4e59d574b833833707d9ed Mon Sep 17 00:00:00 2001 From: JamesChenX Date: Sat, 8 Jun 2024 12:58:33 +0800 Subject: [PATCH] Rename base classes from `Common*` to `Base*` to follow the consistent naming convention --- .../infra/logging/ApiLoggingContext.java | 4 +-- .../gateway/storage/redis/RedisConfig.java | 4 +-- .../admin/web/HttpRequestDispatcher.java | 6 ++-- ...ontext.java => BaseApiLoggingContext.java} | 6 ++-- .../env/aiserving/AdminApiProperties.java | 4 +-- ...s.java => BaseRateLimitingProperties.java} | 2 +- ...operties.java => BaseRedisProperties.java} | 6 ++-- .../AdminApiRateLimitingProperties.java | 4 +-- ...rties.java => BaseAdminApiProperties.java} | 4 +-- ...va => BaseClientApiLoggingProperties.java} | 2 +- .../env/gateway/AdminApiProperties.java | 6 ++-- .../clientapi/ClientApiLoggingProperties.java | 4 +-- .../ClientApiRateLimitingProperties.java | 4 +-- .../gateway/redis/TurmsRedisProperties.java | 4 +-- .../env/adminapi/AdminApiProperties.java | 4 +-- .../clientapi/ClientApiLoggingProperties.java | 4 +-- .../env/redis/TurmsRedisProperties.java | 4 +-- .../infra/throttle/TokenBucketContext.java | 6 ++-- ...nRedisConfig.java => BaseRedisConfig.java} | 27 ++++++--------- .../codec/context/RedisCodecContext.java | 14 ++++---- .../codec/context/RedisCodecContextPool.java | 34 +++++++------------ .../blocklist/service/BlocklistServiceIT.java | 8 +++-- .../infra/logging/ApiLoggingContext.java | 4 +-- .../service/storage/redis/RedisConfig.java | 9 ++--- 24 files changed, 81 insertions(+), 93 deletions(-) rename turms-server-common/src/main/java/im/turms/server/common/infra/logging/{CommonApiLoggingContext.java => BaseApiLoggingContext.java} (97%) rename turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/{CommonRateLimitingProperties.java => BaseRateLimitingProperties.java} (97%) rename turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/{CommonRedisProperties.java => BaseRedisProperties.java} (92%) rename turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/{CommonAdminApiProperties.java => BaseAdminApiProperties.java} (97%) rename turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/clientapi/{CommonClientApiLoggingProperties.java => BaseClientApiLoggingProperties.java} (98%) rename turms-server-common/src/main/java/im/turms/server/common/storage/redis/{CommonRedisConfig.java => BaseRedisConfig.java} (85%) diff --git a/turms-gateway/src/main/java/im/turms/gateway/infra/logging/ApiLoggingContext.java b/turms-gateway/src/main/java/im/turms/gateway/infra/logging/ApiLoggingContext.java index 0eaef7593c..f620783106 100644 --- a/turms-gateway/src/main/java/im/turms/gateway/infra/logging/ApiLoggingContext.java +++ b/turms-gateway/src/main/java/im/turms/gateway/infra/logging/ApiLoggingContext.java @@ -22,7 +22,7 @@ import org.springframework.context.annotation.Configuration; import im.turms.server.common.access.client.dto.request.TurmsRequest; -import im.turms.server.common.infra.logging.CommonApiLoggingContext; +import im.turms.server.common.infra.logging.BaseApiLoggingContext; import im.turms.server.common.infra.property.TurmsPropertiesManager; import im.turms.server.common.infra.property.env.gateway.clientapi.ClientApiLoggingProperties; import im.turms.server.common.infra.property.env.service.env.clientapi.property.LoggingRequestProperties; @@ -31,7 +31,7 @@ * @author James Chen */ @Configuration -public class ApiLoggingContext extends CommonApiLoggingContext { +public class ApiLoggingContext extends BaseApiLoggingContext { private final Map typeToSupportedLoggingRequestProperties; private final Map typeToSupportedLoggingNotificationsProperties; diff --git a/turms-gateway/src/main/java/im/turms/gateway/storage/redis/RedisConfig.java b/turms-gateway/src/main/java/im/turms/gateway/storage/redis/RedisConfig.java index 87aaca6381..7c15121cbc 100644 --- a/turms-gateway/src/main/java/im/turms/gateway/storage/redis/RedisConfig.java +++ b/turms-gateway/src/main/java/im/turms/gateway/storage/redis/RedisConfig.java @@ -21,13 +21,13 @@ import im.turms.server.common.infra.context.TurmsApplicationContext; import im.turms.server.common.infra.property.TurmsPropertiesManager; -import im.turms.server.common.storage.redis.CommonRedisConfig; +import im.turms.server.common.storage.redis.BaseRedisConfig; /** * @author James Chen */ @Configuration -public class RedisConfig extends CommonRedisConfig { +public class RedisConfig extends BaseRedisConfig { protected RedisConfig( TurmsApplicationContext context, diff --git a/turms-server-common/src/main/java/im/turms/server/common/access/admin/web/HttpRequestDispatcher.java b/turms-server-common/src/main/java/im/turms/server/common/access/admin/web/HttpRequestDispatcher.java index 304d22a328..a058883a98 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/access/admin/web/HttpRequestDispatcher.java +++ b/turms-server-common/src/main/java/im/turms/server/common/access/admin/web/HttpRequestDispatcher.java @@ -78,7 +78,7 @@ import im.turms.server.common.infra.property.TurmsProperties; import im.turms.server.common.infra.property.TurmsPropertiesManager; import im.turms.server.common.infra.property.env.common.adminapi.AdminHttpProperties; -import im.turms.server.common.infra.property.env.common.adminapi.CommonAdminApiProperties; +import im.turms.server.common.infra.property.env.common.adminapi.BaseAdminApiProperties; import im.turms.server.common.infra.time.DurationConst; import im.turms.server.common.infra.tracing.TracingCloseableContext; import im.turms.server.common.infra.tracing.TracingContext; @@ -143,7 +143,7 @@ public HttpRequestDispatcher( authenticator = new HttpRequestAuthenticator(adminService); TurmsProperties properties = propertiesManager.getLocalProperties(); - CommonAdminApiProperties apiProperties = switch (node.getNodeType()) { + BaseAdminApiProperties apiProperties = switch (node.getNodeType()) { case AI_SERVING -> properties.getAiServing() .getAdminApi(); case GATEWAY -> properties.getGateway() @@ -190,7 +190,7 @@ public HttpRequestDispatcher( // region Properties private void updateGlobalProperties(TurmsProperties properties) { NodeType nodeType = node.getNodeType(); - CommonAdminApiProperties apiProperties = switch (nodeType) { + BaseAdminApiProperties apiProperties = switch (nodeType) { case AI_SERVING -> properties.getAiServing() .getAdminApi(); case GATEWAY -> properties.getGateway() diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/logging/CommonApiLoggingContext.java b/turms-server-common/src/main/java/im/turms/server/common/infra/logging/BaseApiLoggingContext.java similarity index 97% rename from turms-server-common/src/main/java/im/turms/server/common/infra/logging/CommonApiLoggingContext.java rename to turms-server-common/src/main/java/im/turms/server/common/infra/logging/BaseApiLoggingContext.java index dd672ffdb5..5212015cc1 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/logging/CommonApiLoggingContext.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/logging/BaseApiLoggingContext.java @@ -32,7 +32,9 @@ /** * @author James Chen */ -public abstract class CommonApiLoggingContext { +public abstract class BaseApiLoggingContext { + + public abstract boolean shouldLogNotification(TurmsRequest.KindCase requestType); protected Map getSupportedLoggingRequestProperties( Set includedCategories, @@ -108,4 +110,4 @@ private Set getRequestProperties( return loggingRequests; } -} +} \ No newline at end of file diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/aiserving/AdminApiProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/aiserving/AdminApiProperties.java index 81507f46e8..76666dc2d1 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/aiserving/AdminApiProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/aiserving/AdminApiProperties.java @@ -20,14 +20,14 @@ import lombok.Builder; import lombok.Data; -import im.turms.server.common.infra.property.env.common.adminapi.CommonAdminApiProperties; +import im.turms.server.common.infra.property.env.common.adminapi.BaseAdminApiProperties; /** * @author James Chen */ @Builder(toBuilder = true) @Data -public class AdminApiProperties extends CommonAdminApiProperties { +public class AdminApiProperties extends BaseAdminApiProperties { public AdminApiProperties() { http.setPort(5510); diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/CommonRateLimitingProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/BaseRateLimitingProperties.java similarity index 97% rename from turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/CommonRateLimitingProperties.java rename to turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/BaseRateLimitingProperties.java index 4fbad0d499..63e20eb853 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/CommonRateLimitingProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/BaseRateLimitingProperties.java @@ -33,7 +33,7 @@ @AllArgsConstructor @Data @NoArgsConstructor -public abstract class CommonRateLimitingProperties { +public abstract class BaseRateLimitingProperties { @Description("The maximum number of tokens that the bucket can hold") @GlobalProperty diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/CommonRedisProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/BaseRedisProperties.java similarity index 92% rename from turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/CommonRedisProperties.java rename to turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/BaseRedisProperties.java index dff17e95f2..664d25dae1 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/CommonRedisProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/BaseRedisProperties.java @@ -18,9 +18,9 @@ package im.turms.server.common.infra.property.env.common; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; import org.springframework.boot.context.properties.NestedConfigurationProperty; import im.turms.server.common.storage.redis.RedisProperties; @@ -30,10 +30,10 @@ * @author James Chen */ @AllArgsConstructor -@Builder(toBuilder = true) @Data @NoArgsConstructor -public class CommonRedisProperties { +@SuperBuilder(toBuilder = true) +public abstract class BaseRedisProperties { @NestedConfigurationProperty private transient RedisProperties session = new RedisProperties(); diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/AdminApiRateLimitingProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/AdminApiRateLimitingProperties.java index 4a43673cbc..200fe4bc6c 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/AdminApiRateLimitingProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/AdminApiRateLimitingProperties.java @@ -17,12 +17,12 @@ package im.turms.server.common.infra.property.env.common.adminapi; -import im.turms.server.common.infra.property.env.common.CommonRateLimitingProperties; +import im.turms.server.common.infra.property.env.common.BaseRateLimitingProperties; /** * @author James Chen */ -public class AdminApiRateLimitingProperties extends CommonRateLimitingProperties { +public class AdminApiRateLimitingProperties extends BaseRateLimitingProperties { public AdminApiRateLimitingProperties() { setCapacity(50); diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/CommonAdminApiProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/BaseAdminApiProperties.java similarity index 97% rename from turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/CommonAdminApiProperties.java rename to turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/BaseAdminApiProperties.java index 396be918e2..258b3f90ba 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/CommonAdminApiProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/adminapi/BaseAdminApiProperties.java @@ -27,7 +27,7 @@ * @author James Chen */ @Data -public abstract class CommonAdminApiProperties { +public abstract class BaseAdminApiProperties { @Description("Whether to enable the APIs for administrators") private boolean enabled = true; @@ -49,4 +49,4 @@ public abstract class CommonAdminApiProperties { @NestedConfigurationProperty private LogProperties log = new LogProperties(); -} +} \ No newline at end of file diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/clientapi/CommonClientApiLoggingProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/clientapi/BaseClientApiLoggingProperties.java similarity index 98% rename from turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/clientapi/CommonClientApiLoggingProperties.java rename to turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/clientapi/BaseClientApiLoggingProperties.java index 120bd19476..151adde34a 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/clientapi/CommonClientApiLoggingProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/common/clientapi/BaseClientApiLoggingProperties.java @@ -33,7 +33,7 @@ * @author James Chen */ @Data -public abstract class CommonClientApiLoggingProperties { +public abstract class BaseClientApiLoggingProperties { private static final String DESC_STRATEGY_TO_GET_INCLUDED_REQUESTS = "Turms will get the requests to log from the union of " diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/AdminApiProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/AdminApiProperties.java index 84e198b3ad..497c0738ed 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/AdminApiProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/AdminApiProperties.java @@ -20,17 +20,17 @@ import lombok.Builder; import lombok.Data; -import im.turms.server.common.infra.property.env.common.adminapi.CommonAdminApiProperties; +import im.turms.server.common.infra.property.env.common.adminapi.BaseAdminApiProperties; /** * @author James Chen */ @Builder(toBuilder = true) @Data -public class AdminApiProperties extends CommonAdminApiProperties { +public class AdminApiProperties extends BaseAdminApiProperties { public AdminApiProperties() { http.setPort(9510); } -} +} \ No newline at end of file diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/clientapi/ClientApiLoggingProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/clientapi/ClientApiLoggingProperties.java index 11485730e0..c73418e44b 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/clientapi/ClientApiLoggingProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/clientapi/ClientApiLoggingProperties.java @@ -23,7 +23,7 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import im.turms.server.common.infra.property.env.common.clientapi.CommonClientApiLoggingProperties; +import im.turms.server.common.infra.property.env.common.clientapi.BaseClientApiLoggingProperties; /** * @author James Chen @@ -33,7 +33,7 @@ @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor -public class ClientApiLoggingProperties extends CommonClientApiLoggingProperties { +public class ClientApiLoggingProperties extends BaseClientApiLoggingProperties { private float heartbeatSampleRate; diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/clientapi/ClientApiRateLimitingProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/clientapi/ClientApiRateLimitingProperties.java index 20ac78c7bf..f3efa64bf3 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/clientapi/ClientApiRateLimitingProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/clientapi/ClientApiRateLimitingProperties.java @@ -19,11 +19,11 @@ import lombok.NoArgsConstructor; -import im.turms.server.common.infra.property.env.common.CommonRateLimitingProperties; +import im.turms.server.common.infra.property.env.common.BaseRateLimitingProperties; /** * @author James Chen */ @NoArgsConstructor -public class ClientApiRateLimitingProperties extends CommonRateLimitingProperties { +public class ClientApiRateLimitingProperties extends BaseRateLimitingProperties { } \ No newline at end of file diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/redis/TurmsRedisProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/redis/TurmsRedisProperties.java index fcf3f4e0d4..bcf489f786 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/redis/TurmsRedisProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/gateway/redis/TurmsRedisProperties.java @@ -21,7 +21,7 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import im.turms.server.common.infra.property.env.common.CommonRedisProperties; +import im.turms.server.common.infra.property.env.common.BaseRedisProperties; /** * @author James Chen @@ -29,5 +29,5 @@ @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor -public class TurmsRedisProperties extends CommonRedisProperties { +public class TurmsRedisProperties extends BaseRedisProperties { } \ No newline at end of file diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/adminapi/AdminApiProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/adminapi/AdminApiProperties.java index 3e02d11bf1..f2005c633c 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/adminapi/AdminApiProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/adminapi/AdminApiProperties.java @@ -23,7 +23,7 @@ import lombok.Builder; import lombok.Data; -import im.turms.server.common.infra.property.env.common.adminapi.CommonAdminApiProperties; +import im.turms.server.common.infra.property.env.common.adminapi.BaseAdminApiProperties; import im.turms.server.common.infra.property.metadata.Description; import im.turms.server.common.infra.property.metadata.GlobalProperty; import im.turms.server.common.infra.property.metadata.MutableProperty; @@ -34,7 +34,7 @@ @AllArgsConstructor @Builder(toBuilder = true) @Data -public class AdminApiProperties extends CommonAdminApiProperties { +public class AdminApiProperties extends BaseAdminApiProperties { @Description("Whether to allow administrators to delete data without any filter. " + "Better false to prevent administrators from deleting all data by accident") diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/clientapi/ClientApiLoggingProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/clientapi/ClientApiLoggingProperties.java index cf95de4971..8b9c7402a5 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/clientapi/ClientApiLoggingProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/clientapi/ClientApiLoggingProperties.java @@ -21,7 +21,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; -import im.turms.server.common.infra.property.env.common.clientapi.CommonClientApiLoggingProperties; +import im.turms.server.common.infra.property.env.common.clientapi.BaseClientApiLoggingProperties; /** * @author James Chen @@ -29,5 +29,5 @@ @Builder(toBuilder = true) @Data @EqualsAndHashCode(callSuper = true) -public class ClientApiLoggingProperties extends CommonClientApiLoggingProperties { +public class ClientApiLoggingProperties extends BaseClientApiLoggingProperties { } \ No newline at end of file diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/redis/TurmsRedisProperties.java b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/redis/TurmsRedisProperties.java index cd26564d9f..47efa0cf46 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/redis/TurmsRedisProperties.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/property/env/service/env/redis/TurmsRedisProperties.java @@ -23,7 +23,7 @@ import lombok.NoArgsConstructor; import org.springframework.boot.context.properties.NestedConfigurationProperty; -import im.turms.server.common.infra.property.env.common.CommonRedisProperties; +import im.turms.server.common.infra.property.env.common.BaseRedisProperties; import im.turms.server.common.storage.redis.RedisProperties; /** @@ -33,7 +33,7 @@ @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor -public class TurmsRedisProperties extends CommonRedisProperties { +public class TurmsRedisProperties extends BaseRedisProperties { @NestedConfigurationProperty private RedisProperties sequenceId = new RedisProperties(); diff --git a/turms-server-common/src/main/java/im/turms/server/common/infra/throttle/TokenBucketContext.java b/turms-server-common/src/main/java/im/turms/server/common/infra/throttle/TokenBucketContext.java index 94a3c45416..ab1b42d205 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/infra/throttle/TokenBucketContext.java +++ b/turms-server-common/src/main/java/im/turms/server/common/infra/throttle/TokenBucketContext.java @@ -20,7 +20,7 @@ import lombok.Data; import lombok.NoArgsConstructor; -import im.turms.server.common.infra.property.env.common.CommonRateLimitingProperties; +import im.turms.server.common.infra.property.env.common.BaseRateLimitingProperties; /** * @author James Chen @@ -33,11 +33,11 @@ public class TokenBucketContext { int refillIntervalMillis; int initialTokens; - public TokenBucketContext(CommonRateLimitingProperties properties) { + public TokenBucketContext(BaseRateLimitingProperties properties) { updateRequestTokenBucket(properties); } - public void updateRequestTokenBucket(CommonRateLimitingProperties properties) { + public void updateRequestTokenBucket(BaseRateLimitingProperties properties) { capacity = properties.getCapacity(); initialTokens = properties.getInitialTokens(); tokensPerPeriod = properties.getTokensPerPeriod(); diff --git a/turms-server-common/src/main/java/im/turms/server/common/storage/redis/CommonRedisConfig.java b/turms-server-common/src/main/java/im/turms/server/common/storage/redis/BaseRedisConfig.java similarity index 85% rename from turms-server-common/src/main/java/im/turms/server/common/storage/redis/CommonRedisConfig.java rename to turms-server-common/src/main/java/im/turms/server/common/storage/redis/BaseRedisConfig.java index 2c72441515..ef7926bc8b 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/storage/redis/CommonRedisConfig.java +++ b/turms-server-common/src/main/java/im/turms/server/common/storage/redis/BaseRedisConfig.java @@ -26,7 +26,7 @@ import im.turms.server.common.infra.collection.CollectionUtil; import im.turms.server.common.infra.context.JobShutdownOrder; import im.turms.server.common.infra.context.TurmsApplicationContext; -import im.turms.server.common.infra.property.env.common.CommonRedisProperties; +import im.turms.server.common.infra.property.env.common.BaseRedisProperties; import im.turms.server.common.storage.redis.codec.context.RedisCodecContext; import im.turms.server.common.storage.redis.codec.context.RedisCodecContextPool; @@ -37,7 +37,7 @@ * @see org.springframework.boot.autoconfigure.data.redis.RedisConnectionConfiguration * @see org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration */ -public abstract class CommonRedisConfig { +public abstract class BaseRedisConfig { private final TurmsRedisClientManager sessionRedisClientManager; private final TurmsRedisClientManager locationRedisClientManager; @@ -48,9 +48,9 @@ public abstract class CommonRedisConfig { private final List registeredClientManagers = new LinkedList<>(); private final List registeredClients = new LinkedList<>(); - protected CommonRedisConfig( + protected BaseRedisConfig( TurmsApplicationContext context, - CommonRedisProperties redisProperties, + BaseRedisProperties redisProperties, boolean treatUserIdAndDeviceTypeAsUniqueUser) { sessionRedisClientManager = newSessionRedisClientManager(redisProperties.getSession()); locationRedisClientManager = newLocationRedisClientManager(redisProperties.getLocation(), @@ -64,13 +64,14 @@ protected CommonRedisConfig( context.addShutdownHook(JobShutdownOrder.CLOSE_REDIS_CONNECTIONS, this::destroy); } - public static TurmsRedisClientManager newSessionRedisClientManager(RedisProperties properties) { + private static TurmsRedisClientManager newSessionRedisClientManager( + RedisProperties properties) { return new TurmsRedisClientManager( properties, RedisCodecContextPool.USER_SESSIONS_STATUS_CODEC_CONTEXT); } - public static TurmsRedisClientManager newLocationRedisClientManager( + private static TurmsRedisClientManager newLocationRedisClientManager( RedisProperties properties, boolean treatUserIdAndDeviceTypeAsUniqueUser) { RedisCodecContext codecContext = treatUserIdAndDeviceTypeAsUniqueUser @@ -79,18 +80,12 @@ public static TurmsRedisClientManager newLocationRedisClientManager( return new TurmsRedisClientManager(properties, codecContext); } - public static TurmsRedisClient newIpBlocklistRedisClient(String uri) { - return new TurmsRedisClient( - uri, - RedisCodecContext.builder() - .build()); + private TurmsRedisClient newIpBlocklistRedisClient(String uri) { + return new TurmsRedisClient(uri, RedisCodecContext.DEFAULT); } - public static TurmsRedisClient newUserIdBlocklistRedisClient(String uri) { - return new TurmsRedisClient( - uri, - RedisCodecContext.builder() - .build()); + private TurmsRedisClient newUserIdBlocklistRedisClient(String uri) { + return new TurmsRedisClient(uri, RedisCodecContext.DEFAULT); } public void registerClientManagers(List clientManagers) { diff --git a/turms-server-common/src/main/java/im/turms/server/common/storage/redis/codec/context/RedisCodecContext.java b/turms-server-common/src/main/java/im/turms/server/common/storage/redis/codec/context/RedisCodecContext.java index bb9da3f4b1..add6bfad2a 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/storage/redis/codec/context/RedisCodecContext.java +++ b/turms-server-common/src/main/java/im/turms/server/common/storage/redis/codec/context/RedisCodecContext.java @@ -21,7 +21,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.RefCntCorrectorByteBuf; -import lombok.Builder; import lombok.Data; import im.turms.server.common.infra.netty.ByteBufUtil; @@ -32,15 +31,16 @@ * @author James Chen */ @Data -@Builder public class RedisCodecContext { - private TurmsRedisCodec hashKeyCodec; - private TurmsRedisCodec hashFieldCodec; - private TurmsRedisCodec hashValueCodec; + public static final RedisCodecContext DEFAULT = + new RedisCodecContext(null, null, null, null, null); - private TurmsRedisCodec geoKeyCodec; - private TurmsRedisCodec geoMemberCodec; + private final TurmsRedisCodec hashKeyCodec; + private final TurmsRedisCodec hashFieldCodec; + private final TurmsRedisCodec hashValueCodec; + private final TurmsRedisCodec geoKeyCodec; + private final TurmsRedisCodec geoMemberCodec; // Hashes diff --git a/turms-server-common/src/main/java/im/turms/server/common/storage/redis/codec/context/RedisCodecContextPool.java b/turms-server-common/src/main/java/im/turms/server/common/storage/redis/codec/context/RedisCodecContextPool.java index ababb9dd33..b165fb0983 100644 --- a/turms-server-common/src/main/java/im/turms/server/common/storage/redis/codec/context/RedisCodecContextPool.java +++ b/turms-server-common/src/main/java/im/turms/server/common/storage/redis/codec/context/RedisCodecContextPool.java @@ -31,24 +31,16 @@ public final class RedisCodecContextPool { private RedisCodecContextPool() { } - public static final RedisCodecContext GEO_USER_SESSION_ID_CODEC_CONTEXT; - public static final RedisCodecContext GEO_USER_ID_CODEC_CONTEXT; - public static final RedisCodecContext USER_SESSIONS_STATUS_CODEC_CONTEXT; - - static { - GEO_USER_SESSION_ID_CODEC_CONTEXT = RedisCodecContext.builder() - .geoMemberCodec(new GeoUserSessionIdCodec()) - .build(); - - GEO_USER_ID_CODEC_CONTEXT = RedisCodecContext.builder() - .geoMemberCodec(new GeoUserIdCodec()) - .build(); - - USER_SESSIONS_STATUS_CODEC_CONTEXT = RedisCodecContext.builder() - .hashKeyCodec(new SessionKeyCodec()) - .hashFieldCodec(new SessionHashFieldCodec()) - .hashValueCodec(new SessionHashValueCodec()) - .build(); - } - -} + public static final RedisCodecContext GEO_USER_SESSION_ID_CODEC_CONTEXT = + new RedisCodecContext(null, null, null, null, new GeoUserSessionIdCodec()); + public static final RedisCodecContext GEO_USER_ID_CODEC_CONTEXT = + new RedisCodecContext(null, null, null, null, new GeoUserIdCodec()); + public static final RedisCodecContext USER_SESSIONS_STATUS_CODEC_CONTEXT = + new RedisCodecContext( + new SessionKeyCodec(), + new SessionHashFieldCodec(), + new SessionHashValueCodec(), + null, + null); + +} \ No newline at end of file diff --git a/turms-server-common/src/test/java/integration/im/turms/server/common/domain/blocklist/service/BlocklistServiceIT.java b/turms-server-common/src/test/java/integration/im/turms/server/common/domain/blocklist/service/BlocklistServiceIT.java index 6ea1e54cf1..74c5efa272 100644 --- a/turms-server-common/src/test/java/integration/im/turms/server/common/domain/blocklist/service/BlocklistServiceIT.java +++ b/turms-server-common/src/test/java/integration/im/turms/server/common/domain/blocklist/service/BlocklistServiceIT.java @@ -34,7 +34,8 @@ import im.turms.server.common.infra.property.env.common.security.BlocklistProperties; import im.turms.server.common.infra.property.env.common.security.SecurityProperties; import im.turms.server.common.infra.task.TaskManager; -import im.turms.server.common.storage.redis.CommonRedisConfig; +import im.turms.server.common.storage.redis.TurmsRedisClient; +import im.turms.server.common.storage.redis.codec.context.RedisCodecContext; import im.turms.server.common.testing.BaseIntegrationTest; import static org.assertj.core.api.Assertions.assertThat; @@ -301,12 +302,13 @@ private static BlocklistService newBlocklistService(int maxLogSize) { String uri = testEnvironmentManager.getRedisUri(); BlocklistService.maxLogQueueSize = maxLogSize; + TurmsRedisClient redisClient = new TurmsRedisClient(uri, RedisCodecContext.DEFAULT); return new BlocklistService( node, new TaskManager(), mock(TurmsApplicationContext.class), - CommonRedisConfig.newIpBlocklistRedisClient(uri), - CommonRedisConfig.newUserIdBlocklistRedisClient(uri), + redisClient, + redisClient, propertiesManager, null); } diff --git a/turms-service/src/main/java/im/turms/service/infra/logging/ApiLoggingContext.java b/turms-service/src/main/java/im/turms/service/infra/logging/ApiLoggingContext.java index 3217eba47a..b3ed090836 100644 --- a/turms-service/src/main/java/im/turms/service/infra/logging/ApiLoggingContext.java +++ b/turms-service/src/main/java/im/turms/service/infra/logging/ApiLoggingContext.java @@ -22,7 +22,7 @@ import org.springframework.context.annotation.Configuration; import im.turms.server.common.access.client.dto.request.TurmsRequest; -import im.turms.server.common.infra.logging.CommonApiLoggingContext; +import im.turms.server.common.infra.logging.BaseApiLoggingContext; import im.turms.server.common.infra.property.TurmsPropertiesManager; import im.turms.server.common.infra.property.env.service.env.clientapi.ClientApiLoggingProperties; import im.turms.server.common.infra.property.env.service.env.clientapi.property.LoggingRequestProperties; @@ -31,7 +31,7 @@ * @author James Chen */ @Configuration -public class ApiLoggingContext extends CommonApiLoggingContext { +public class ApiLoggingContext extends BaseApiLoggingContext { private final Map typeToSupportedLoggingRequestProperties; private final Map typeToSupportedLoggingNotificationProperties; diff --git a/turms-service/src/main/java/im/turms/service/storage/redis/RedisConfig.java b/turms-service/src/main/java/im/turms/service/storage/redis/RedisConfig.java index b55a5d7cd4..adac92af82 100644 --- a/turms-service/src/main/java/im/turms/service/storage/redis/RedisConfig.java +++ b/turms-service/src/main/java/im/turms/service/storage/redis/RedisConfig.java @@ -26,7 +26,7 @@ import im.turms.server.common.infra.property.TurmsPropertiesManager; import im.turms.server.common.infra.property.env.service.ServiceProperties; import im.turms.server.common.infra.property.env.service.business.message.SequenceIdProperties; -import im.turms.server.common.storage.redis.CommonRedisConfig; +import im.turms.server.common.storage.redis.BaseRedisConfig; import im.turms.server.common.storage.redis.RedisProperties; import im.turms.server.common.storage.redis.TurmsRedisClientManager; import im.turms.server.common.storage.redis.codec.context.RedisCodecContext; @@ -35,7 +35,7 @@ * @author James Chen */ @Configuration -public class RedisConfig extends CommonRedisConfig { +public class RedisConfig extends BaseRedisConfig { private final TurmsRedisClientManager sequenceIdRedisClientManager; @@ -65,10 +65,7 @@ protected RedisConfig( public static TurmsRedisClientManager newSequenceIdRedisClientManager( RedisProperties properties) { - return new TurmsRedisClientManager( - properties, - RedisCodecContext.builder() - .build()); + return new TurmsRedisClientManager(properties, RedisCodecContext.DEFAULT); } @Bean