use of io.servicecomb.serviceregistry.utils.Timer in project java-chassis by ServiceComb.
the class IpPortManager method createServiceRegistryCache.
public void createServiceRegistryCache() throws TimerException {
if (instanceCache != null) {
LOGGER.warn("already cache service registry addresses");
return;
}
// 绑定微服务与SR的依赖,同时建立cache
Timer timer = Timer.newForeverTimer();
while (true) {
instanceCache = InstanceCacheManager.INSTANCE.getOrCreate(Const.REGISTRY_APP_ID, Const.REGISTRY_SERVICE_NAME, Const.REGISTRY_VERSION);
if (instanceCache != null) {
break;
}
LOGGER.error("create service registry {}/{}/{} instance caches failed", Const.REGISTRY_APP_ID, Const.REGISTRY_SERVICE_NAME, Const.REGISTRY_VERSION);
timer.sleep();
}
LOGGER.info("create service registry {}/{}/{} instance caches successfully", Const.REGISTRY_APP_ID, Const.REGISTRY_SERVICE_NAME, Const.REGISTRY_VERSION);
}
use of io.servicecomb.serviceregistry.utils.Timer in project java-chassis by ServiceComb.
the class RegistryUtils method heartbeat.
public static HeartbeatResponse heartbeat() {
Timer timer = Timer.newForeverTimer();
HeartbeatResponse response;
while (true) {
response = srClient.heartbeat(getMicroservice().getServiceId(), getMicroserviceInstance().getInstanceId());
if (response != null) {
break;
}
if (!needToWatch()) {
exception(new ClientException("could not connect to service center"));
}
try {
LOGGER.warn("Update heartbeat to service center failed, retry after {}s. service={}/{}", timer.getNextTimeout(), getMicroservice().getServiceId(), getMicroserviceInstance().getInstanceId());
timer.sleep();
} catch (TimerException e) {
LOGGER.error("Update heartbeat to service center failed, can not connect to service center. service={}/{}", getMicroservice().getServiceId(), getMicroserviceInstance().getInstanceId());
return null;
}
}
if (!response.isOk()) {
LOGGER.error("Update heartbeat to service center failed, microservice instance={}/{} does not exist", getMicroservice().getServiceId(), getMicroserviceInstance().getInstanceId());
}
return response;
}
Aggregations