use of com.tencent.polaris.api.plugin.server.ServerEvent in project polaris-java by polarismesh.
the class SpecStreamClient method onNext.
/**
* 正常回调
*
* @param response 应答说
*/
public void onNext(ResponseProto.DiscoverResponse response) {
lastRecvTimeMs.set(System.currentTimeMillis());
ValidResult validResult = validMessage(response);
if (validResult.errorCode != ErrorCode.Success) {
exceptionCallback(validResult);
return;
}
ServiceProto.Service service = response.getService();
ServiceKey serviceKey = new ServiceKey(service.getNamespace().getValue(), service.getName().getValue());
EventType eventType = GrpcUtil.buildEventType(response.getType());
ServiceEventKey serviceEventKey = new ServiceEventKey(serviceKey, eventType);
ServiceUpdateTask updateTask;
synchronized (clientLock) {
updateTask = pendingTask.remove(serviceEventKey);
}
if (null == updateTask) {
LOG.error("[ServerConnector]callback not found for:{}", TextFormat.shortDebugString(service));
return;
}
if (updateTask.getTaskType() == Type.FIRST) {
LOG.info("[ServerConnector]receive response for {}", serviceEventKey);
} else {
LOG.debug("[ServerConnector]receive response for {}", serviceEventKey);
}
PolarisException error;
if (!response.hasCode() || response.getCode().getValue() == ServerCodes.EXECUTE_SUCCESS) {
error = null;
} else {
int respCode = response.getCode().getValue();
String info = response.getInfo().getValue();
error = ServerErrorResponseException.build(respCode, String.format("[ServerConnector]code %d, fail to query service %s from server(%s): %s", respCode, serviceKey, connection.getConnID(), info));
}
boolean svcDeleted = updateTask.notifyServerEvent(new ServerEvent(serviceEventKey, response, error));
if (!svcDeleted) {
updateTask.addUpdateTaskSet();
}
}
Aggregations