use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.
the class EphemeralIpPortClientManager method clientDisconnected.
@Override
public boolean clientDisconnected(String clientId) {
Loggers.SRV_LOG.info("Client connection {} disconnect, remove instances and subscribers", clientId);
IpPortBasedClient client = clients.remove(clientId);
if (null == client) {
return true;
}
NotifyCenter.publishEvent(new ClientEvent.ClientDisconnectEvent(client));
client.release();
return true;
}
use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.
the class PersistentIpPortClientManager method clientConnected.
@Override
public boolean clientConnected(final Client client) {
clients.computeIfAbsent(client.getClientId(), s -> {
Loggers.SRV_LOG.info("Client connection {} connect", client.getClientId());
IpPortBasedClient ipPortBasedClient = (IpPortBasedClient) client;
ipPortBasedClient.init();
return ipPortBasedClient;
});
return true;
}
use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.
the class PersistentIpPortClientManager method clientDisconnected.
@Override
public boolean clientDisconnected(String clientId) {
Loggers.SRV_LOG.info("Persistent client connection {} disconnect", clientId);
IpPortBasedClient client = clients.remove(clientId);
if (null == client) {
return true;
}
NotifyCenter.publishEvent(new ClientEvent.ClientDisconnectEvent(client));
client.release();
return true;
}
use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.
the class InstanceOperatorClientImpl method handleBeat.
@Override
public int handleBeat(String namespaceId, String serviceName, String ip, int port, String cluster, RsInfo clientBeat, BeatInfoInstanceBuilder builder) throws NacosException {
Service service = getService(namespaceId, serviceName, true);
String clientId = IpPortBasedClient.getClientId(ip + InternetAddressUtil.IP_PORT_SPLITER + port, true);
IpPortBasedClient client = (IpPortBasedClient) clientManager.getClient(clientId);
if (null == client || !client.getAllPublishedService().contains(service)) {
if (null == clientBeat) {
return NamingResponseCode.RESOURCE_NOT_FOUND;
}
Instance instance = builder.setBeatInfo(clientBeat).setServiceName(serviceName).build();
registerInstance(namespaceId, serviceName, instance);
client = (IpPortBasedClient) clientManager.getClient(clientId);
}
if (!ServiceManager.getInstance().containSingleton(service)) {
throw new NacosException(NacosException.SERVER_ERROR, "service not found: " + serviceName + "@" + namespaceId);
}
if (null == clientBeat) {
clientBeat = new RsInfo();
clientBeat.setIp(ip);
clientBeat.setPort(port);
clientBeat.setCluster(cluster);
clientBeat.setServiceName(serviceName);
}
ClientBeatProcessorV2 beatProcessor = new ClientBeatProcessorV2(namespaceId, clientBeat, client);
HealthCheckReactor.scheduleNow(beatProcessor);
client.setLastUpdatedTime();
return NamingResponseCode.OK;
}
use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.
the class HealthCheckTaskInterceptWrapperTest method setUp.
@Before
public void setUp() throws Exception {
when(applicationContext.getBean(NamingMetadataManager.class)).thenReturn(namingMetadataManager);
when(applicationContext.getBean(GlobalConfig.class)).thenReturn(globalConfig);
when(applicationContext.getBean(SwitchDomain.class)).thenReturn(switchDomain);
when(applicationContext.getBean(DistroMapper.class)).thenReturn(distroMapper);
when(applicationContext.getBean(UpgradeJudgement.class)).thenReturn(upgradeJudgement);
ApplicationUtils.injectContext(applicationContext);
client = new IpPortBasedClient(CLIENT_ID, true);
when(switchDomain.isHealthCheckEnabled()).thenReturn(true);
when(distroMapper.responsible(client.getResponsibleId())).thenReturn(true);
when(upgradeJudgement.isUseGrpcFeatures()).thenReturn(true);
ClientBeatCheckTaskV2 beatCheckTask = new ClientBeatCheckTaskV2(client);
taskWrapper = new HealthCheckTaskInterceptWrapper(beatCheckTask);
}
Aggregations