use of org.redisson.config.ReplicatedServersConfig in project LinkAgent by shulieTech.
the class RedissonFactory method getAddr.
public List<String> getAddr(Config config) {
SingleServerConfig singleServerConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SINGLE_SERVER_CONFIG);
ClusterServersConfig clusterServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_CLUSTER_SERVERS_CONFIG);
SentinelServersConfig sentinelServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SENTINEL_SERVERS_CONFIG);
ReplicatedServersConfig replicatedServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_REPLICATED_SERVERS_CONFIG);
MasterSlaveServersConfig masterSlaveServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_MASTER_SLAVE_SERVERS_CONFIG);
if (singleServerConfig != null) {
return RedissonUtils.removePre(singleServerConfig.getAddress());
} else if (clusterServersConfig != null) {
return RedissonUtils.removePre(clusterServersConfig.getNodeAddresses());
} else if (replicatedServersConfig != null) {
return RedissonUtils.removePre(replicatedServersConfig.getNodeAddresses());
} else if (masterSlaveServersConfig != null) {
Set slave = masterSlaveServersConfig.getSlaveAddresses();
List<String> result = new ArrayList(RedissonUtils.removePre(slave));
Object master = masterSlaveServersConfig.getMasterAddress();
result.addAll(RedissonUtils.removePre(master));
return result;
}
return null;
}
use of org.redisson.config.ReplicatedServersConfig in project LinkAgent by shulieTech.
the class RedissonNodesStrategy method getAddress.
public static List getAddress(Config config) {
SingleServerConfig singleServerConfig = null;
try {
singleServerConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SINGLE_SERVER_CONFIG);
} catch (ReflectException e) {
}
ClusterServersConfig clusterServersConfig = null;
try {
clusterServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_CLUSTER_SERVERS_CONFIG);
} catch (ReflectException e) {
}
SentinelServersConfig sentinelServersConfig = null;
try {
sentinelServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SENTINEL_SERVERS_CONFIG);
} catch (ReflectException e) {
}
ReplicatedServersConfig replicatedServersConfig = null;
try {
replicatedServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_REPLICATED_SERVERS_CONFIG);
} catch (ReflectException e) {
}
MasterSlaveServersConfig masterSlaveServersConfig = null;
try {
masterSlaveServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_MASTER_SLAVE_SERVERS_CONFIG);
} catch (ReflectException e) {
}
if (singleServerConfig != null) {
// 在这里返回的address在不同版本可能返回String,可能返回URI在这里做处理
Object address = Reflect.on(singleServerConfig).get("address");
String addressConvert = null;
if (address instanceof URI) {
URI uriConvert = (URI) address;
addressConvert = RedissonUtils.addPre(new StringBuilder().append(uriConvert.getHost()).append(":").append(uriConvert.getPort()).toString());
} else if (address instanceof String) {
addressConvert = (String) address;
}
return RedissonUtils.removePre(addressConvert);
} else if (clusterServersConfig != null) {
return RedissonUtils.removePre(clusterServersConfig.getNodeAddresses());
} else if (sentinelServersConfig != null) {
List<String> result = RedissonUtils.removePre(sentinelServersConfig.getSentinelAddresses());
result.add(sentinelServersConfig.getMasterName());
return result;
} else if (replicatedServersConfig != null) {
return RedissonUtils.removePre(replicatedServersConfig.getNodeAddresses());
} else if (masterSlaveServersConfig != null) {
String master = masterSlaveServersConfig.getMasterAddress();
Set<String> slave = masterSlaveServersConfig.getSlaveAddresses();
List<String> result = new ArrayList(RedissonUtils.removePre(slave));
result.addAll(RedissonUtils.removePre(master));
return result;
}
return null;
}
use of org.redisson.config.ReplicatedServersConfig in project LinkAgent by shulieTech.
the class BaseRedissonTimeSeriesMethodInterceptor method getDatabase.
public int getDatabase(Object target, String methodName, Object[] args) {
Config config = null;
try {
config = manager.getDynamicField(target, RedissonConstants.DYNAMIC_FIELD_CONFIG);
} catch (Throwable e) {
return 0;
}
if (config == null) {
return 0;
}
SentinelServersConfig sentinelServersConfig = getSentinelServersConfig(config);
if (sentinelServersConfig != null) {
int database = sentinelServersConfig.getDatabase();
return database;
}
MasterSlaveServersConfig masterSlaveServersConfig = getMasterSlaveServersConfig(config);
if (masterSlaveServersConfig != null) {
return masterSlaveServersConfig.getDatabase();
}
SingleServerConfig singleServerConfig = getSingleServerConfig(config);
if (singleServerConfig != null) {
return singleServerConfig.getDatabase();
}
ClusterServersConfig clusterServersConfig = getClusterServersConfig(config);
if (clusterServersConfig != null) {
return 0;
}
ReplicatedServersConfig replicatedServersConfig = getReplicatedServersConfig(config);
if (replicatedServersConfig != null) {
return replicatedServersConfig.getDatabase();
}
return 0;
}
use of org.redisson.config.ReplicatedServersConfig in project LinkAgent by shulieTech.
the class BaseRedissonTimeSeriesMethodInterceptor method getHost.
public String getHost(Object target, String methodName, Object[] args) {
Config config = manager.getDynamicField(target, RedissonConstants.DYNAMIC_FIELD_CONFIG);
if (config == null) {
return null;
}
SentinelServersConfig sentinelServersConfig = getSentinelServersConfig(config);
if (sentinelServersConfig != null) {
List list = sentinelServersConfig.getSentinelAddresses();
if (list != null && !list.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Object obj : list) {
if (obj instanceof String) {
String str = (String) obj;
if (StringUtils.isBlank(str)) {
continue;
}
if (StringUtils.indexOf(str, ":") != -1) {
String[] arr = StringUtils.split(str, ':');
builder.append(arr[1]).append(',');
}
} else if (obj instanceof URI) {
builder.append(((URI) obj).getHost()).append(",");
}
}
if (builder.length() > 0) {
builder.deleteCharAt(builder.length() - 1);
}
if (builder.length() > 0) {
return builder.toString();
} else {
return "6379";
}
}
}
MasterSlaveServersConfig masterSlaveServersConfig = getMasterSlaveServersConfig(config);
if (masterSlaveServersConfig != null) {
Object masterAddress = masterSlaveServersConfig.getMasterAddress();
StringBuilder builder = new StringBuilder();
if (String.class.isAssignableFrom(masterAddress.getClass())) {
if (StringUtils.isNotBlank((String) masterAddress)) {
if (StringUtils.indexOf((String) masterAddress, ":") != -1) {
String[] arr = StringUtils.split((String) masterAddress, ':');
builder.append(arr[0]).append(',');
}
}
} else if (URI.class.isAssignableFrom(masterAddress.getClass())) {
builder.append(((URI) masterAddress).getHost()).append(',');
}
Set set = masterSlaveServersConfig.getSlaveAddresses();
if (set != null && !set.isEmpty()) {
for (Object obj : set) {
if (obj instanceof String) {
String str = (String) obj;
if (StringUtils.isBlank(str)) {
continue;
}
if (StringUtils.indexOf(str, ":") != -1) {
String[] arr = StringUtils.split(str, ':');
builder.append(arr[0]).append(',');
}
} else if (URI.class.isAssignableFrom(obj.getClass())) {
builder.append(((URI) obj).getHost()).append(",");
}
}
}
if (builder.length() > 0) {
builder.deleteCharAt(builder.length() - 1);
}
if (builder.length() > 0) {
return builder.toString();
} else {
return "6379";
}
}
SingleServerConfig singleServerConfig = getSingleServerConfig(config);
if (singleServerConfig != null) {
String address = getAddress(singleServerConfig);
if (StringUtils.isNotBlank(address)) {
if (StringUtils.indexOf(address, ":") == -1) {
return "6379";
} else {
String[] arr = StringUtils.split(address, ':');
return StringUtils.trim(arr[1]);
}
}
}
ClusterServersConfig clusterServersConfig = getClusterServersConfig(config);
if (clusterServersConfig != null) {
List list = clusterServersConfig.getNodeAddresses();
if (list != null && !list.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Object obj : list) {
String str = obj == null ? null : obj.toString();
if (StringUtils.isBlank(str)) {
continue;
}
if (StringUtils.indexOf(str, ":") != -1) {
String[] arr = StringUtils.split(str, ':');
builder.append(arr[0]).append(',');
}
}
if (builder.length() > 0) {
builder.deleteCharAt(builder.length() - 1);
}
if (builder.length() > 0) {
return builder.toString();
} else {
return "6379";
}
}
}
ReplicatedServersConfig replicatedServersConfig = getReplicatedServersConfig(config);
if (replicatedServersConfig != null) {
List list = replicatedServersConfig.getNodeAddresses();
StringBuilder builder = new StringBuilder();
for (Object obj : list) {
String str = obj == null ? null : obj.toString();
if (StringUtils.isBlank(str)) {
continue;
}
if (StringUtils.indexOf(str, ":") != -1) {
String[] arr = StringUtils.split(str, ':');
builder.append(arr[0]).append(',');
}
}
if (builder.length() > 0) {
builder.deleteCharAt(builder.length() - 1);
}
if (builder.length() > 0) {
return builder.toString();
} else {
return "6379";
}
}
return null;
}
use of org.redisson.config.ReplicatedServersConfig in project force-oneself by Force-oneself.
the class RedissonConfig method useReplicatedServers.
@Bean
@ConditionalOnMissingBean(Config.class)
@ConditionalOnProperty(prefix = RedissonConstant.PROPERTIES_PREFIX, name = "enable", havingValue = "replicated")
public Config useReplicatedServers(RedissonProperties properties) {
Config config = new Config();
Objects.requireNonNull(properties.getCluster(), "请配置replicated");
ReplicatedServersConfig replicated = properties.getReplicated();
config.useReplicatedServers().setDatabase(replicated.getDatabase()).setPassword(replicated.getPassword()).setScanInterval(replicated.getScanInterval()).getNodeAddresses().addAll(replicated.getNodeAddresses());
return config;
}
Aggregations