Skip to content

Commit

Permalink
Trivial code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChenX committed Jun 29, 2024
1 parent 5ca175c commit 29f93f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public class BlocklistServiceManager<T extends Comparable<T>> {
private static final long UNINITIALIZED_TIMESTAMP = -1;
private static final int UNINITIALIZED_LOG_ID = -1;

private final RedisScript blockClientsScript;
private final RedisScript unblockClientsScript;
private final RedisScript getBlockedClientsScript;
private final RedisScript evictAllBlockedClients;
private final RedisScript evictExpiredBlockedClients;
private final RedisScript getBlocklistLogsScript;
private final RedisScript<List<Object>> blockClientsScript;
private final RedisScript<List<Object>> unblockClientsScript;
private final RedisScript<List<Object>> getBlockedClientsScript;
private final RedisScript<Boolean> evictAllBlockedClients;
private final RedisScript<Boolean> evictExpiredBlockedClients;
private final RedisScript<List<Object>> getBlocklistLogsScript;

private final Node node;
private final TurmsRedisClient redisClient;
Expand Down Expand Up @@ -138,12 +138,12 @@ public BlocklistServiceManager(
Node node,
TurmsRedisClient redisClient,
ScheduledThreadPoolExecutor threadPoolExecutor,
RedisScript blockClientsScript,
RedisScript unblockClientsScript,
RedisScript getBlockedClientsScript,
RedisScript evictAllBlockedClients,
RedisScript evictExpiredBlockedClients,
RedisScript getBlocklistLogsScript,
RedisScript<List<Object>> blockClientsScript,
RedisScript<List<Object>> unblockClientsScript,
RedisScript<List<Object>> getBlockedClientsScript,
RedisScript<Boolean> evictAllBlockedClients,
RedisScript<Boolean> evictExpiredBlockedClients,
RedisScript<List<Object>> getBlocklistLogsScript,
Consumer<T> onTargetBlocked) {
this.node = node;
this.redisClient = redisClient;
Expand Down Expand Up @@ -262,7 +262,8 @@ private void removeLocalBlockedClient(T targetId) {
public Mono<Void> unblockAll() {
blockedClientIdToBlockEndTimeMillis.clear();
blockedClientSkipList.clear();
return redisClient.eval(evictAllBlockedClients, getBlocklistKey());
return redisClient.eval(evictAllBlockedClients, getBlocklistKey())
.then();
}

private void evictLocalExpiredBlockedClients() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,24 @@ public BlocklistService(

Map<String, Object> params = Map.of("MAX_LOG_QUEUE_SIZE", maxLogQueueSize);

RedisScript blockClientsScript =
RedisScript<List<Object>> blockClientsScript =
RedisScript.get(new ClassPathResource("redis/blocklist/block_clients.lua"),
ScriptOutputType.MULTI,
params);
RedisScript unblockClientsScript =
RedisScript<List<Object>> unblockClientsScript =
RedisScript.get(new ClassPathResource("redis/blocklist/unblock_clients.lua"),
ScriptOutputType.MULTI,
params);
RedisScript getBlockedClientsScript =
RedisScript<List<Object>> getBlockedClientsScript =
RedisScript.get(new ClassPathResource("redis/blocklist/get_blocked_clients.lua"),
ScriptOutputType.MULTI);
RedisScript evictAllBlockedClients = RedisScript.get(
RedisScript<Boolean> evictAllBlockedClients = RedisScript.get(
new ClassPathResource("redis/blocklist/evict_all_blocked_clients.lua"),
ScriptOutputType.BOOLEAN);
RedisScript evictExpiredBlockedClients = RedisScript.get(
RedisScript<Boolean> evictExpiredBlockedClients = RedisScript.get(
new ClassPathResource("redis/blocklist/evict_expired_blocked_clients.lua"),
ScriptOutputType.BOOLEAN);
RedisScript getBlocklistLogsScript =
RedisScript<List<Object>> getBlocklistLogsScript =
RedisScript.get(new ClassPathResource("redis/blocklist/get_blocklist_logs.lua"),
ScriptOutputType.MULTI,
params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import im.turms.server.common.infra.property.env.service.business.common.setting.CustomSettingProperties;
import im.turms.server.common.infra.property.env.service.business.common.setting.CustomSettingStringValueProperties;
import im.turms.server.common.infra.property.env.service.business.common.setting.CustomSettingValueProperties;
import im.turms.service.infra.locale.LocaleUtils;
import im.turms.service.infra.locale.LocaleUtil;

/**
* @author James Chen
Expand Down Expand Up @@ -261,7 +261,7 @@ private Object parseValue(
};
case LANGUAGE -> {
String languageId = value.getStringValue();
if (!LocaleUtils.isAvailableLanguage(languageId)) {
if (!LocaleUtil.isAvailableLanguage(languageId)) {
throw ResponseException.get(ResponseStatusCode.ILLEGAL_ARGUMENT,
"The value of the setting \""
+ sourceName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
/**
* @author James Chen
*/
public final class LocaleUtils {
public final class LocaleUtil {

private static final Map<String, Locale> ID_TO_LOCALE;

static {
Map<String, Locale> idToLocale = new HashMap<>(2048);
// Use "availableLocales()" to avoid unnecessary copy.
// Use "availableLocales()" instead of "getAvailableLocales()" to avoid unnecessary copy.
Locale.availableLocales()
.forEach(locale -> idToLocale.put(locale.toLanguageTag(), locale));
ID_TO_LOCALE = Map.copyOf(idToLocale);
}

private LocaleUtils() {
private LocaleUtil() {
}

public static boolean isAvailableLanguage(String languageId) {
Expand Down

0 comments on commit 29f93f7

Please sign in to comment.