提交 1dcc538e 编写于 作者: W whohim

revert to chore( #512 ): Unified naming

上级 421b92bc
......@@ -83,11 +83,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
......
package com.codingapi.txlcn.tc.config;
import com.codingapi.txlcn.protocol.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import javax.annotation.PostConstruct;
@Configuration
public class TcConfigConfiguration {
@Autowired
private RedisTemplate redisTemplate;
@PostConstruct
public void init() {
initRedisTemplate();
}
@SuppressWarnings({"unchecked", "rawtypes"})
private void initRedisTemplate() {
RedisSerializer stringSerializer = redisTemplate.getStringSerializer();
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(stringSerializer);
}
@Bean
@ConfigurationProperties(prefix = "txlcn.tc")
public TxConfig txConfig(Config config) {
return new TxConfig(config, redisTemplate);
return new TxConfig(config);
}
......
......@@ -3,22 +3,17 @@ package com.codingapi.txlcn.tc.config;
import com.codingapi.txlcn.protocol.config.Config;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Tx config properties
*/
@SuppressWarnings("rawtypes")
@Data
@Slf4j
public class TxConfig {
......@@ -58,20 +53,10 @@ public class TxConfig {
*/
private Config protocol;
@Autowired
private RedisTemplate redisTemplate;
private static final String SNOWFLAKE_REDIS_KEY = "SnowflakeRedisKey*";
public TxConfig(Config protocol) {
this.protocol = protocol;
}
public TxConfig(Config protocol, RedisTemplate redisTemplate) {
this.protocol = protocol;
this.redisTemplate = redisTemplate;
}
/**
* address to InetSocketAddress
*
......@@ -89,15 +74,13 @@ public class TxConfig {
return null;
}
@SuppressWarnings("unchecked")
public List<InetSocketAddress> txManagerAddresses() {
List<InetSocketAddress> addresses = new ArrayList<>();
Set tmKeys = redisTemplate.keys(SNOWFLAKE_REDIS_KEY);
if (!CollectionUtils.isEmpty(tmKeys)) {
tmKeys.forEach(
tmKey -> Optional.ofNullable(addressFormat(String.valueOf(redisTemplate.opsForValue().get(tmKey))))
.ifPresent(addresses::add)
);
if (tms != null) {
for (String item : tms) {
Optional<InetSocketAddress> optional = Optional.ofNullable(addressFormat(item));
optional.ifPresent(addresses::add);
}
}
return addresses;
}
......
......@@ -12,11 +12,11 @@ import lombok.extern.slf4j.Slf4j;
* @date Create in 2020-8-15 22:55:46
*/
@Slf4j
public class SnowFlakeInfo implements SnowFlakeStep {
public class SnowflakeInfo implements SnowflakeStep {
private TxManagerReporter txManagerReporter;
public SnowFlakeInfo(TxManagerReporter txManagerReporter) {
public SnowflakeInfo(TxManagerReporter txManagerReporter) {
this.txManagerReporter = txManagerReporter;
}
......
......@@ -6,7 +6,7 @@ package com.codingapi.txlcn.tc.id;
* @description
* @date Create in 2020-8-15 22:53:57
*/
public interface SnowFlakeStep {
public interface SnowflakeStep {
/**
* 去 TM 取得 groupId 及 logId
*/
......
......@@ -6,17 +6,16 @@ import org.springframework.stereotype.Component;
/**
* @author WhomHim
* @description 用于每天刷新 redis 里数据的过期时间
* @description
* @date Create in 2020-8-17 22:34:28
*/
@Component
public class SnowflakeSchedule {
@Autowired
private SnowflakeInitiator snowflakeInitiator;
@Scheduled(fixedDelay = 1000 * 60 * 60 * 23)
private void snowflakeInitiatorResetExpire() {
private void snowflakeInitiator_ResetExpire() {
snowflakeInitiator.resetExpire();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册