Search in sources :

Example 1 with ServerEvent

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();
    }
}
Also used : PolarisException(com.tencent.polaris.api.exception.PolarisException) ServerEvent(com.tencent.polaris.api.plugin.server.ServerEvent) EventType(com.tencent.polaris.api.pojo.ServiceEventKey.EventType) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) ServiceEventKey(com.tencent.polaris.api.pojo.ServiceEventKey) ServiceUpdateTask(com.tencent.polaris.plugins.connector.common.ServiceUpdateTask) ServiceProto(com.tencent.polaris.client.pb.ServiceProto)

Aggregations

PolarisException (com.tencent.polaris.api.exception.PolarisException)1 ServerEvent (com.tencent.polaris.api.plugin.server.ServerEvent)1 ServiceEventKey (com.tencent.polaris.api.pojo.ServiceEventKey)1 EventType (com.tencent.polaris.api.pojo.ServiceEventKey.EventType)1 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)1 ServiceProto (com.tencent.polaris.client.pb.ServiceProto)1 ServiceUpdateTask (com.tencent.polaris.plugins.connector.common.ServiceUpdateTask)1