use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class LongPollingService method getSubscribleInfo.
public SampleResult getSubscribleInfo(String dataId, String group, String tenant) {
String groupKey = GroupKey.getKeyTenant(dataId, group, tenant);
SampleResult sampleResult = new SampleResult();
Map<String, String> lisentersGroupkeyStatus = new HashMap<String, String>(50);
for (ClientLongPolling clientLongPolling : allSubs) {
if (clientLongPolling.clientMd5Map.containsKey(groupKey)) {
lisentersGroupkeyStatus.put(clientLongPolling.ip, clientLongPolling.clientMd5Map.get(groupKey));
}
}
sampleResult.setLisentersGroupkeyStatus(lisentersGroupkeyStatus);
return sampleResult;
}
use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class LongPollingService method getSubscribleInfoByIp.
public SampleResult getSubscribleInfoByIp(String clientIp) {
SampleResult sampleResult = new SampleResult();
Map<String, String> lisentersGroupkeyStatus = new HashMap<String, String>(50);
for (ClientLongPolling clientLongPolling : allSubs) {
if (clientLongPolling.ip.equals(clientIp)) {
// One ip can have multiple listener.
if (!lisentersGroupkeyStatus.equals(clientLongPolling.clientMd5Map)) {
lisentersGroupkeyStatus.putAll(clientLongPolling.clientMd5Map);
}
}
}
sampleResult.setLisentersGroupkeyStatus(lisentersGroupkeyStatus);
return sampleResult;
}
use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class LongPollingService method getCollectSubscribleInfoByIp.
public SampleResult getCollectSubscribleInfoByIp(String ip) {
SampleResult sampleResult = new SampleResult();
sampleResult.setLisentersGroupkeyStatus(new HashMap<String, String>(50));
for (int i = 0; i < SAMPLE_TIMES; i++) {
SampleResult sampleTmp = getSubscribleInfoByIp(ip);
if (sampleTmp != null) {
if (sampleTmp.getLisentersGroupkeyStatus() != null && !sampleResult.getLisentersGroupkeyStatus().equals(sampleTmp.getLisentersGroupkeyStatus())) {
sampleResult.getLisentersGroupkeyStatus().putAll(sampleTmp.getLisentersGroupkeyStatus());
}
}
if (i < SAMPLE_TIMES - 1) {
try {
Thread.sleep(SAMPLE_PERIOD);
} catch (InterruptedException e) {
LogUtil.CLIENT_LOG.error("sleep wrong", e);
}
}
}
return sampleResult;
}
use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class CommunicationController method getSubClientConfigByIp.
/**
* Get client config listener lists of subscriber in local machine.
*/
@GetMapping("/watcherConfigs")
public SampleResult getSubClientConfigByIp(HttpServletRequest request, HttpServletResponse response, @RequestParam("ip") String ip, ModelMap modelMap) {
SampleResult result = longPollingService.getCollectSubscribleInfoByIp(ip);
List<Connection> connectionsByIp = connectionManager.getConnectionByIp(ip);
for (Connection connectionByIp : connectionsByIp) {
Map<String, String> listenKeys = configChangeListenContext.getListenKeys(connectionByIp.getMetaInfo().getConnectionId());
if (listenKeys != null) {
result.getLisentersGroupkeyStatus().putAll(listenKeys);
}
}
return result;
}
use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class CommunicationController method getSubClientConfig.
/**
* Get client config information of subscriber in local machine.
*/
@GetMapping("/configWatchers")
public SampleResult getSubClientConfig(@RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestParam(value = "tenant", required = false) String tenant, ModelMap modelMap) {
group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group;
// long polling listners.
SampleResult result = longPollingService.getCollectSubscribleInfo(dataId, group, tenant);
// rpc listeners.
String groupKey = GroupKey2.getKey(dataId, group, tenant);
Set<String> listenersClients = configChangeListenContext.getListeners(groupKey);
if (CollectionUtils.isEmpty(listenersClients)) {
return result;
}
Map<String, String> lisentersGroupkeyStatus = new HashMap<>(listenersClients.size(), 1);
for (String connectionId : listenersClients) {
Connection client = connectionManager.getConnection(connectionId);
if (client != null) {
String md5 = configChangeListenContext.getListenKeyMd5(connectionId, groupKey);
if (md5 != null) {
lisentersGroupkeyStatus.put(client.getMetaInfo().getClientIp(), md5);
}
}
}
result.getLisentersGroupkeyStatus().putAll(lisentersGroupkeyStatus);
return result;
}
Aggregations