Skip to content

Commit

Permalink
Rename base classes from Common* to Base* to follow the consisten…
Browse files Browse the repository at this point in the history
…t naming convention
  • Loading branch information
JamesChenX committed Jun 10, 2024
1 parent d32659a commit afe4536
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +31,7 @@
* @author James Chen
*/
@Configuration
public class ApiLoggingContext extends CommonApiLoggingContext {
public class ApiLoggingContext extends BaseApiLoggingContext {

private final Map<TurmsRequest.KindCase, LoggingRequestProperties> typeToSupportedLoggingRequestProperties;
private final Map<TurmsRequest.KindCase, LoggingRequestProperties> typeToSupportedLoggingNotificationsProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
/**
* @author James Chen
*/
public abstract class CommonApiLoggingContext {
public abstract class BaseApiLoggingContext {

public abstract boolean shouldLogNotification(TurmsRequest.KindCase requestType);

protected Map<TurmsRequest.KindCase, LoggingRequestProperties> getSupportedLoggingRequestProperties(
Set<LoggingCategoryProperties> includedCategories,
Expand Down Expand Up @@ -108,4 +110,4 @@ private Set<LoggingRequestProperties> getRequestProperties(
return loggingRequests;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,4 +49,4 @@ public abstract class CommonAdminApiProperties {
@NestedConfigurationProperty
private LogProperties log = new LogProperties();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +33,7 @@
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class ClientApiLoggingProperties extends CommonClientApiLoggingProperties {
public class ClientApiLoggingProperties extends BaseClientApiLoggingProperties {

private float heartbeatSampleRate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
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
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class TurmsRedisProperties extends CommonRedisProperties {
public class TurmsRedisProperties extends BaseRedisProperties {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
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
*/
@Builder(toBuilder = true)
@Data
@EqualsAndHashCode(callSuper = true)
public class ClientApiLoggingProperties extends CommonClientApiLoggingProperties {
public class ClientApiLoggingProperties extends BaseClientApiLoggingProperties {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -48,9 +48,9 @@ public abstract class CommonRedisConfig {
private final List<TurmsRedisClientManager> registeredClientManagers = new LinkedList<>();
private final List<TurmsRedisClient> registeredClients = new LinkedList<>();

protected CommonRedisConfig(
protected BaseRedisConfig(
TurmsApplicationContext context,
CommonRedisProperties redisProperties,
BaseRedisProperties redisProperties,
boolean treatUserIdAndDeviceTypeAsUniqueUser) {
sessionRedisClientManager = newSessionRedisClientManager(redisProperties.getSession());
locationRedisClientManager = newLocationRedisClientManager(redisProperties.getLocation(),
Expand All @@ -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
Expand All @@ -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<TurmsRedisClientManager> clientManagers) {
Expand Down
Loading

0 comments on commit afe4536

Please sign in to comment.