Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
commit
8ef3fd9225
@ -384,6 +384,7 @@ public class InstanceController {
|
||||
// now try to enable the push
|
||||
try {
|
||||
if (udpPort > 0 && pushService.canEnablePush(agent)) {
|
||||
|
||||
pushService.addClient(namespaceId, serviceName,
|
||||
clusters,
|
||||
agent,
|
||||
@ -394,7 +395,7 @@ public class InstanceController {
|
||||
cacheMillis = switchDomain.getPushCacheMillis(serviceName);
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ public class PushService implements ApplicationContextAware, ApplicationListener
|
||||
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
|
||||
String serviceKey = UtilsAndCommons.assembleFullServiceName(client.getNamespaceId(), client.getServiceName());
|
||||
ConcurrentMap<String, PushClient> clients =
|
||||
@ -403,21 +403,18 @@ public class PushService implements ApplicationContextAware, ApplicationListener
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
public PushClient(InetSocketAddress socketAddr) {
|
||||
this.socketAddr = socketAddr;
|
||||
}
|
||||
|
||||
public boolean zombie() {
|
||||
return System.currentTimeMillis() - lastRefTime > switchDomain.getPushCacheMillis(serviceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "serviceName: " + serviceName
|
||||
+ ", clusters: " + clusters
|
||||
+ ", ip: " + socketAddr.getAddress().getHostAddress()
|
||||
+ ", port: " + socketAddr.getPort()
|
||||
+ ", agent: " + agent;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("serviceName: ").append(serviceName)
|
||||
.append(", clusters: ").append(clusters)
|
||||
.append(", address: ").append(socketAddr)
|
||||
.append(", agent: ").append(agent);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getAgent() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user