Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
nkorange 2019-11-06 13:46:49 +08:00
commit 8ef3fd9225
3 changed files with 59 additions and 11 deletions

View File

@ -384,6 +384,7 @@ public class InstanceController {
// now try to enable the push // now try to enable the push
try { try {
if (udpPort > 0 && pushService.canEnablePush(agent)) { if (udpPort > 0 && pushService.canEnablePush(agent)) {
pushService.addClient(namespaceId, serviceName, pushService.addClient(namespaceId, serviceName,
clusters, clusters,
agent, agent,
@ -394,7 +395,7 @@ public class InstanceController {
cacheMillis = switchDomain.getPushCacheMillis(serviceName); cacheMillis = switchDomain.getPushCacheMillis(serviceName);
} }
} catch (Exception e) { } catch (Exception e) {
Loggers.SRV_LOG.error("[NACOS-API] failed to added push client", e); Loggers.SRV_LOG.error("[NACOS-API] failed to added push client {}, {}:{}", clientInfo, clientIP, udpPort, e);
cacheMillis = switchDomain.getDefaultCacheMillis(); cacheMillis = switchDomain.getDefaultCacheMillis();
} }

View File

@ -225,7 +225,7 @@ public class PushService implements ApplicationContextAware, ApplicationListener
addClient(client); addClient(client);
} }
public static void addClient(PushClient client) { public void addClient(PushClient client) {
// client is stored by key 'serviceName' because notify event is driven by serviceName change // client is stored by key 'serviceName' because notify event is driven by serviceName change
String serviceKey = UtilsAndCommons.assembleFullServiceName(client.getNamespaceId(), client.getServiceName()); String serviceKey = UtilsAndCommons.assembleFullServiceName(client.getNamespaceId(), client.getServiceName());
ConcurrentMap<String, PushClient> clients = ConcurrentMap<String, PushClient> clients =
@ -403,21 +403,18 @@ public class PushService implements ApplicationContextAware, ApplicationListener
return dataSource; return dataSource;
} }
public PushClient(InetSocketAddress socketAddr) {
this.socketAddr = socketAddr;
}
public boolean zombie() { public boolean zombie() {
return System.currentTimeMillis() - lastRefTime > switchDomain.getPushCacheMillis(serviceName); return System.currentTimeMillis() - lastRefTime > switchDomain.getPushCacheMillis(serviceName);
} }
@Override @Override
public String toString() { public String toString() {
return "serviceName: " + serviceName StringBuilder sb = new StringBuilder();
+ ", clusters: " + clusters sb.append("serviceName: ").append(serviceName)
+ ", ip: " + socketAddr.getAddress().getHostAddress() .append(", clusters: ").append(clusters)
+ ", port: " + socketAddr.getPort() .append(", address: ").append(socketAddr)
+ ", agent: " + agent; .append(", agent: ").append(agent);
return sb.toString();
} }
public String getAgent() { public String getAgent() {

View File

@ -0,0 +1,50 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.naming.push;
import com.alibaba.nacos.naming.BaseTest;
import org.junit.Test;
import java.net.InetSocketAddress;
/**
* @author nkorange
*/
public class PushClientTest extends BaseTest {
@Test
public void testAddClient() {
String namespaceId = "public";
String serviceName = "test.1";
String clusters = "DEFAULT";
String agent = "Nacos-Java-Client:v1.1.4";
String clientIp = "xxxxx";
String app = "nacos";
int udpPort = 10000;
pushService.addClient(namespaceId
, serviceName
, clusters
, agent
, new InetSocketAddress(clientIp, udpPort)
, null
, namespaceId
, app);
}
}