本文整理汇总了Java中org.apache.rocketmq.common.protocol.body.ClusterInfo类的典型用法代码示例。如果您正苦于以下问题:Java ClusterInfo类的具体用法?Java ClusterInfo怎么用?Java ClusterInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClusterInfo类属于org.apache.rocketmq.common.protocol.body包,在下文中一共展示了ClusterInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBrokerClusterInfo
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
public ClusterInfo getBrokerClusterInfo(final long timeoutMillis) throws InterruptedException, RemotingTimeoutException,
RemotingSendRequestException, RemotingConnectException, MQBrokerException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null);
RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
assert response != null;
switch (response.getCode()) {
case ResponseCode.SUCCESS: {
return ClusterInfo.decode(response.getBody(), ClusterInfo.class);
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark());
}
示例2: cleanExpiredConsumerQueue
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
@Override
public boolean cleanExpiredConsumerQueue(String cluster) throws RemotingConnectException, RemotingSendRequestException,
RemotingTimeoutException, MQClientException, InterruptedException {
boolean result = false;
try {
ClusterInfo clusterInfo = examineBrokerClusterInfo();
if (null == cluster || "".equals(cluster)) {
for (String targetCluster : clusterInfo.retrieveAllClusterNames()) {
result = cleanExpiredConsumerQueueByCluster(clusterInfo, targetCluster);
}
} else {
result = cleanExpiredConsumerQueueByCluster(clusterInfo, cluster);
}
} catch (MQBrokerException e) {
log.error("cleanExpiredConsumerQueue error.", e);
}
return result;
}
示例3: cleanUnusedTopic
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
@Override
public boolean cleanUnusedTopic(String cluster) throws RemotingConnectException, RemotingSendRequestException,
RemotingTimeoutException, MQClientException, InterruptedException {
boolean result = false;
try {
ClusterInfo clusterInfo = examineBrokerClusterInfo();
if (null == cluster || "".equals(cluster)) {
for (String targetCluster : clusterInfo.retrieveAllClusterNames()) {
result = cleanUnusedTopicByCluster(clusterInfo, targetCluster);
}
} else {
result = cleanUnusedTopicByCluster(clusterInfo, cluster);
}
} catch (MQBrokerException e) {
log.error("cleanExpiredConsumerQueue error.", e);
}
return result;
}
示例4: consumed
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException,
MQBrokerException {
ConsumeStats cstats = this.examineConsumeStats(group);
ClusterInfo ci = this.examineBrokerClusterInfo();
Iterator<Entry<MessageQueue, OffsetWrapper>> it = cstats.getOffsetTable().entrySet().iterator();
while (it.hasNext()) {
Entry<MessageQueue, OffsetWrapper> next = it.next();
MessageQueue mq = next.getKey();
if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) {
BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName());
if (brokerData != null) {
String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
if (addr.equals(RemotingUtil.socketAddress2String(msg.getStoreHost()))) {
if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) {
return true;
}
}
}
}
}
return false;
}
示例5: getTopicClusterList
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
@Override
public Set<String> getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException,
RemotingException {
Set<String> clusterSet = new HashSet<String>();
ClusterInfo clusterInfo = examineBrokerClusterInfo();
TopicRouteData topicRouteData = examineTopicRouteInfo(topic);
BrokerData brokerData = topicRouteData.getBrokerDatas().get(0);
String brokerName = brokerData.getBrokerName();
Iterator<Map.Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Set<String>> next = it.next();
if (next.getValue().contains(brokerName)) {
clusterSet.add(next.getKey());
}
}
return clusterSet;
}
示例6: fetchMasterAndSlaveAddrByClusterName
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
public static Set<String> fetchMasterAndSlaveAddrByClusterName(final MQAdminExt adminExt, final String clusterName)
throws InterruptedException, RemotingConnectException, RemotingTimeoutException,
RemotingSendRequestException, MQBrokerException {
Set<String> masterSet = new HashSet<String>();
ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();
Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName);
if (brokerNameSet != null) {
for (String brokerName : brokerNameSet) {
BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
if (brokerData != null) {
final Collection<String> addrs = brokerData.getBrokerAddrs().values();
masterSet.addAll(addrs);
}
}
} else {
System.out
.printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct.");
}
return masterSet;
}
示例7: findTopicBelongToWhichCluster
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
private String findTopicBelongToWhichCluster(final String topic, final ClusterInfo clusterInfo,
final DefaultMQAdminExt defaultMQAdminExt) throws RemotingException, MQClientException,
InterruptedException {
TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
BrokerData brokerData = topicRouteData.getBrokerDatas().get(0);
String brokerName = brokerData.getBrokerName();
Iterator<Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator();
while (it.hasNext()) {
Entry<String, Set<String>> next = it.next();
if (next.getValue().contains(brokerName)) {
return next.getKey();
}
}
return null;
}
示例8: testExamineBrokerClusterInfo
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
@Test
public void testExamineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
HashMap<String, BrokerData> brokerList = clusterInfo.getBrokerAddrTable();
assertThat(brokerList.get("default-broker").getBrokerName()).isEqualTo("default-broker");
assertThat(brokerList.containsKey("broker-test")).isTrue();
HashMap<String, Set<String>> clusterMap = new HashMap<>();
Set<String> brokers = new HashSet<>();
brokers.add("default-broker");
brokers.add("broker-test");
clusterMap.put("default-cluster", brokers);
ClusterInfo cInfo = mock(ClusterInfo.class);
when(cInfo.getClusterAddrTable()).thenReturn(clusterMap);
HashMap<String, Set<String>> clusterAddress = cInfo.getClusterAddrTable();
assertThat(clusterAddress.containsKey("default-cluster")).isTrue();
assertThat(clusterAddress.get("default-cluster").size()).isEqualTo(2);
}
示例9: isBrokerExist
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
public static boolean isBrokerExist(String ns, String ip) {
ClusterInfo clusterInfo = getCluster(ns);
if (clusterInfo == null) {
return false;
} else {
HashMap<String, BrokerData> brokers = clusterInfo.getBrokerAddrTable();
for (String brokerName : brokers.keySet()) {
HashMap<Long, String> brokerIps = brokers.get(brokerName).getBrokerAddrs();
for (long brokerId : brokerIps.keySet()) {
if (brokerIps.get(brokerId).contains(ip))
return true;
}
}
}
return false;
}
示例10: getBrokerClusterInfo
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
public ClusterInfo getBrokerClusterInfo(
final long timeoutMillis) throws InterruptedException, RemotingTimeoutException,
RemotingSendRequestException, RemotingConnectException, MQBrokerException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null);
RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
assert response != null;
switch (response.getCode()) {
case ResponseCode.SUCCESS: {
return ClusterInfo.decode(response.getBody(), ClusterInfo.class);
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark());
}
示例11: cleanExpiredConsumerQueue
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
@Override
public boolean cleanExpiredConsumerQueue(
String cluster) throws RemotingConnectException, RemotingSendRequestException,
RemotingTimeoutException, MQClientException, InterruptedException {
boolean result = false;
try {
ClusterInfo clusterInfo = examineBrokerClusterInfo();
if (null == cluster || "".equals(cluster)) {
for (String targetCluster : clusterInfo.retrieveAllClusterNames()) {
result = cleanExpiredConsumerQueueByCluster(clusterInfo, targetCluster);
}
} else {
result = cleanExpiredConsumerQueueByCluster(clusterInfo, cluster);
}
} catch (MQBrokerException e) {
log.error("cleanExpiredConsumerQueue error.", e);
}
return result;
}
示例12: getTopicClusterList
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
@Override
public Set<String> getTopicClusterList(
final String topic) throws InterruptedException, MQBrokerException, MQClientException,
RemotingException {
Set<String> clusterSet = new HashSet<String>();
ClusterInfo clusterInfo = examineBrokerClusterInfo();
TopicRouteData topicRouteData = examineTopicRouteInfo(topic);
BrokerData brokerData = topicRouteData.getBrokerDatas().get(0);
String brokerName = brokerData.getBrokerName();
Iterator<Map.Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Set<String>> next = it.next();
if (next.getValue().contains(brokerName)) {
clusterSet.add(next.getKey());
}
}
return clusterSet;
}
示例13: cleanExpiredConsumerQueueByCluster
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
public boolean cleanExpiredConsumerQueueByCluster(ClusterInfo clusterInfo, String cluster) throws RemotingConnectException,
RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException {
boolean result = false;
String[] addrs = clusterInfo.retrieveAllAddrByCluster(cluster);
for (String addr : addrs) {
result = cleanExpiredConsumerQueueByAddr(addr);
}
return result;
}
示例14: cleanUnusedTopicByCluster
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
public boolean cleanUnusedTopicByCluster(ClusterInfo clusterInfo, String cluster) throws RemotingConnectException,
RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException {
boolean result = false;
String[] addrs = clusterInfo.retrieveAllAddrByCluster(cluster);
for (String addr : addrs) {
result = cleanUnusedTopicByAddr(addr);
}
return result;
}
示例15: fetchMasterAndSlaveDistinguish
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入依赖的package包/类
public static Map<String/*master addr*/, List<String>/*slave addr*/> fetchMasterAndSlaveDistinguish(
final MQAdminExt adminExt, final String clusterName)
throws InterruptedException, RemotingConnectException,
RemotingTimeoutException, RemotingSendRequestException,
MQBrokerException {
Map<String, List<String>> masterAndSlaveMap = new HashMap<String, List<String>>(4);
ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();
Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName);
if (brokerNameSet == null) {
System.out
.printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct.");
return masterAndSlaveMap;
}
for (String brokerName : brokerNameSet) {
BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
if (brokerData == null || brokerData.getBrokerAddrs() == null) {
continue;
}
String masterAddr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
masterAndSlaveMap.put(masterAddr, new ArrayList<String>());
for (Long id : brokerData.getBrokerAddrs().keySet()) {
if (brokerData.getBrokerAddrs().get(id) == null
|| id.longValue() == MixAll.MASTER_ID) {
continue;
}
masterAndSlaveMap.get(masterAddr).add(brokerData.getBrokerAddrs().get(id));
}
}
return masterAndSlaveMap;
}