use of com.tencent.polaris.api.plugin.server.CommonProviderRequest in project polaris-java by polarismesh.
the class DefaultProviderAPI method heartbeat.
@Override
public void heartbeat(InstanceHeartbeatRequest req) throws PolarisException {
checkAvailable("ProviderAPI");
Validator.validateHeartbeatRequest(req);
long timeout = getTimeout(req);
long retryInterval = sdkContext.getConfig().getGlobal().getAPI().getRetryInterval();
while (timeout > 0) {
long start = System.currentTimeMillis();
ServiceCallResult serviceCallResult = new ServiceCallResult();
CommonProviderRequest request = req.getRequest();
try {
serverConnector.heartbeat(request);
serviceCallResult.setRetStatus(RetStatus.RetSuccess);
serviceCallResult.setRetCode(ErrorCode.Success.getCode());
return;
} catch (PolarisException e) {
serviceCallResult.setRetStatus(RetStatus.RetFail);
serviceCallResult.setRetCode(exceptionToErrorCode(e).getCode());
if (e instanceof RetriableException) {
LOG.warn("heartbeat request error, retrying.", e);
Utils.sleepUninterrupted(retryInterval);
continue;
}
throw e;
} finally {
long delay = System.currentTimeMillis() - start;
serviceCallResult.setDelay(delay);
reportServerCall(serviceCallResult, request.getTargetServer(), "heartbeat");
timeout -= delay;
}
}
throw new PolarisException(ErrorCode.API_TIMEOUT, "heartbeat request timeout.");
}
use of com.tencent.polaris.api.plugin.server.CommonProviderRequest in project polaris-java by polarismesh.
the class DefaultProviderAPI method deRegister.
@Override
public void deRegister(InstanceDeregisterRequest req) throws PolarisException {
checkAvailable("ProviderAPI");
Validator.validateInstanceDeregisterRequest(req);
long retryInterval = sdkContext.getConfig().getGlobal().getAPI().getRetryInterval();
long timeout = getTimeout(req);
while (timeout > 0) {
long start = System.currentTimeMillis();
ServiceCallResult serviceCallResult = new ServiceCallResult();
CommonProviderRequest request = req.getRequest();
try {
serverConnector.deregisterInstance(request);
serviceCallResult.setRetStatus(RetStatus.RetSuccess);
serviceCallResult.setRetCode(ErrorCode.Success.getCode());
LOG.info("deregister instance {} succ", req);
return;
} catch (PolarisException e) {
serviceCallResult.setRetStatus(RetStatus.RetFail);
serviceCallResult.setRetCode(exceptionToErrorCode(e).getCode());
if (e instanceof RetriableException) {
LOG.warn("instance deregister request error, retrying.", e);
Utils.sleepUninterrupted(retryInterval);
continue;
}
throw e;
} finally {
long delay = System.currentTimeMillis() - start;
serviceCallResult.setDelay(delay);
reportServerCall(serviceCallResult, request.getTargetServer(), "deRegister");
timeout -= delay;
}
}
throw new PolarisException(ErrorCode.API_TIMEOUT, "instance deregister request timeout.");
}
use of com.tencent.polaris.api.plugin.server.CommonProviderRequest in project polaris-java by polarismesh.
the class DefaultProviderAPI method register.
@Override
public InstanceRegisterResponse register(InstanceRegisterRequest req) throws PolarisException {
checkAvailable("ProviderAPI");
Validator.validateInstanceRegisterRequest(req);
long retryInterval = sdkContext.getConfig().getGlobal().getAPI().getRetryInterval();
long timeout = getTimeout(req);
while (timeout > 0) {
long start = System.currentTimeMillis();
ServiceCallResult serviceCallResult = new ServiceCallResult();
CommonProviderRequest request = req.getRequest();
try {
CommonProviderResponse response = serverConnector.registerInstance(request);
LOG.info("register {}/{} instance {} succ", req.getNamespace(), req.getService(), response.getInstanceID());
serviceCallResult.setRetStatus(RetStatus.RetSuccess);
serviceCallResult.setRetCode(ErrorCode.Success.getCode());
return new InstanceRegisterResponse(response.getInstanceID(), response.isExists());
} catch (PolarisException e) {
serviceCallResult.setRetStatus(RetStatus.RetFail);
serviceCallResult.setRetCode(exceptionToErrorCode(e).getCode());
if (e instanceof RetriableException) {
LOG.warn("instance register request error, retrying.", e);
Utils.sleepUninterrupted(retryInterval);
continue;
}
throw e;
} finally {
long delay = System.currentTimeMillis() - start;
serviceCallResult.setDelay(delay);
reportServerCall(serviceCallResult, request.getTargetServer(), "register");
timeout -= delay;
}
}
throw new PolarisException(ErrorCode.API_TIMEOUT, "instance register request timeout.");
}
Aggregations