Search in sources :

Example 11 with SampleResult

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;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SampleResult(com.alibaba.nacos.config.server.model.SampleResult)

Example 12 with 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;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SampleResult(com.alibaba.nacos.config.server.model.SampleResult)

Example 13 with 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;
}
Also used : SampleResult(com.alibaba.nacos.config.server.model.SampleResult)

Example 14 with 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;
}
Also used : Connection(com.alibaba.nacos.core.remote.Connection) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 15 with SampleResult

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;
}
Also used : HashMap(java.util.HashMap) Connection(com.alibaba.nacos.core.remote.Connection) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

SampleResult (com.alibaba.nacos.config.server.model.SampleResult)17 HashMap (java.util.HashMap)11 Test (org.junit.Test)5 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)5 GroupkeyListenserStatus (com.alibaba.nacos.config.server.model.GroupkeyListenserStatus)4 Connection (com.alibaba.nacos.core.remote.Connection)4 ArrayList (java.util.ArrayList)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConnectionMeta (com.alibaba.nacos.core.remote.ConnectionMeta)2 GrpcConnection (com.alibaba.nacos.core.remote.grpc.GrpcConnection)2 Map (java.util.Map)2 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)2 Future (java.util.concurrent.Future)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 Secured (com.alibaba.nacos.auth.annotation.Secured)1 Member (com.alibaba.nacos.core.cluster.Member)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1