refactor(pulsar-query): 优化pulsar项目依赖和代码性能
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package com.lanyuanxiaoyao.service.configuration.entity.pulsar;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Pulsar 信息
|
||||
@@ -12,10 +11,10 @@ import java.util.stream.Collectors;
|
||||
* @date 2023-04-28
|
||||
*/
|
||||
public class PulsarInfo {
|
||||
public static final List<PulsarInfo> DEFAULT_INFOS = ListUtil.of(
|
||||
public static final ImmutableList<PulsarInfo> DEFAULT_INFOS = Lists.immutable.of(
|
||||
new PulsarInfo(
|
||||
"main",
|
||||
ListUtil.of(
|
||||
Lists.immutable.of(
|
||||
"132.122.113.167:16680",
|
||||
"132.122.113.168:16680",
|
||||
"132.122.113.169:16680",
|
||||
@@ -32,7 +31,7 @@ public class PulsarInfo {
|
||||
),
|
||||
new PulsarInfo(
|
||||
"acct",
|
||||
ListUtil.of(
|
||||
Lists.immutable.of(
|
||||
"132.122.115.158:16650",
|
||||
"132.122.115.159:16650",
|
||||
"132.122.115.160:16650",
|
||||
@@ -45,7 +44,7 @@ public class PulsarInfo {
|
||||
),
|
||||
new PulsarInfo(
|
||||
"order",
|
||||
ListUtil.of(
|
||||
Lists.immutable.of(
|
||||
"132.122.115.158:16660",
|
||||
"132.122.115.159:16660",
|
||||
"132.122.115.160:16660",
|
||||
@@ -58,7 +57,7 @@ public class PulsarInfo {
|
||||
),
|
||||
new PulsarInfo(
|
||||
"cust",
|
||||
ListUtil.of(
|
||||
Lists.immutable.of(
|
||||
"132.122.113.167:16670",
|
||||
"132.122.113.168:16670",
|
||||
"132.122.113.169:16670",
|
||||
@@ -74,34 +73,24 @@ public class PulsarInfo {
|
||||
"132.122.113.167:18108"
|
||||
)
|
||||
);
|
||||
public static final Map<String, PulsarInfo> PULSAR_CLIENT_INFO_MAPPING = DEFAULT_INFOS.stream()
|
||||
.flatMap(info -> info.getBrokers()
|
||||
.stream()
|
||||
.map(url -> new Pair<>(url, info)))
|
||||
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
public static final Map<String, String> PULSAR_CLIENT_NAME_MAPPING = PULSAR_CLIENT_INFO_MAPPING.entrySet()
|
||||
.stream()
|
||||
.map(entry -> new Pair<>(entry.getKey(), entry.getValue().name))
|
||||
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
public static final Map<String, String> PULSAR_CLIENT_ADMIN_MAPPING = PULSAR_CLIENT_INFO_MAPPING.entrySet()
|
||||
.stream()
|
||||
.map(entry -> new Pair<>(entry.getKey(), entry.getValue().admin))
|
||||
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
public static final Map<String, String> PULSAR_CLIENT_PRESTO_MAPPING = PULSAR_CLIENT_INFO_MAPPING.entrySet()
|
||||
.stream()
|
||||
.map(entry -> new Pair<>(entry.getKey(), entry.getValue().presto))
|
||||
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
public static final Map<String, PulsarInfo> PULSAR_NAME_INFO_MAPPING = DEFAULT_INFOS.stream()
|
||||
.collect(Collectors.toMap(PulsarInfo::getName, info -> info));
|
||||
public static final ImmutableMap<String, PulsarInfo> PULSAR_CLIENT_INFO_MAPPING = DEFAULT_INFOS
|
||||
.flatCollect(info -> info.getBrokers()
|
||||
.collect(url -> new Pair<>(url, info)))
|
||||
.toMap(Pair::getLeft, Pair::getRight)
|
||||
.toImmutable();
|
||||
public static final ImmutableMap<String, String> PULSAR_CLIENT_NAME_MAPPING = PULSAR_CLIENT_INFO_MAPPING.collectValues((key, value) -> value.getName());
|
||||
public static final ImmutableMap<String, String> PULSAR_CLIENT_ADMIN_MAPPING = PULSAR_CLIENT_INFO_MAPPING.collectValues((key, value) -> value.getAdmin());
|
||||
public static final ImmutableMap<String, String> PULSAR_CLIENT_PRESTO_MAPPING = PULSAR_CLIENT_INFO_MAPPING.collectValues((key, value) -> value.getPresto());
|
||||
public static final ImmutableMap<String, PulsarInfo> PULSAR_NAME_INFO_MAPPING = DEFAULT_INFOS.toMap(PulsarInfo::getName, info -> info).toImmutable();
|
||||
private String name;
|
||||
private List<String> brokers;
|
||||
private ImmutableList<String> brokers;
|
||||
private String presto;
|
||||
private String admin;
|
||||
|
||||
public PulsarInfo() {
|
||||
}
|
||||
|
||||
public PulsarInfo(String name, List<String> brokers, String presto, String admin) {
|
||||
public PulsarInfo(String name, ImmutableList<String> brokers, String presto, String admin) {
|
||||
this.name = name;
|
||||
this.brokers = brokers;
|
||||
this.presto = presto;
|
||||
@@ -112,7 +101,7 @@ public class PulsarInfo {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getBrokers() {
|
||||
public ImmutableList<String> getBrokers() {
|
||||
return brokers;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user