refactor:optimize project and code

pull/368/head
SkyeBeFreeman 3 years ago
parent 65853777ad
commit 640111a698

@ -38,9 +38,9 @@ import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
*/ */
public class PolarisReactiveDiscoveryClient implements ReactiveDiscoveryClient { public class PolarisReactiveDiscoveryClient implements ReactiveDiscoveryClient {
private static final Logger log = LoggerFactory.getLogger(PolarisReactiveDiscoveryClient.class); private static final Logger LOG = LoggerFactory.getLogger(PolarisReactiveDiscoveryClient.class);
private PolarisServiceDiscovery polarisServiceDiscovery; private final PolarisServiceDiscovery polarisServiceDiscovery;
public PolarisReactiveDiscoveryClient(PolarisServiceDiscovery polarisServiceDiscovery) { public PolarisReactiveDiscoveryClient(PolarisServiceDiscovery polarisServiceDiscovery) {
this.polarisServiceDiscovery = polarisServiceDiscovery; this.polarisServiceDiscovery = polarisServiceDiscovery;
@ -63,7 +63,7 @@ public class PolarisReactiveDiscoveryClient implements ReactiveDiscoveryClient {
return Flux.fromIterable(polarisServiceDiscovery.getInstances(serviceId)); return Flux.fromIterable(polarisServiceDiscovery.getInstances(serviceId));
} }
catch (PolarisException e) { catch (PolarisException e) {
log.error("get service instance[{}] from polaris error!", serviceId, e); LOG.error("get service instance[{}] from polaris error!", serviceId, e);
return Flux.empty(); return Flux.empty();
} }
}; };
@ -76,7 +76,7 @@ public class PolarisReactiveDiscoveryClient implements ReactiveDiscoveryClient {
return Flux.fromIterable(polarisServiceDiscovery.getServices()); return Flux.fromIterable(polarisServiceDiscovery.getServices());
} }
catch (Exception e) { catch (Exception e) {
log.error("get services from polaris server fail,", e); LOG.error("get services from polaris server fail,", e);
return Flux.empty(); return Flux.empty();
} }
}).subscribeOn(Schedulers.boundedElastic()); }).subscribeOn(Schedulers.boundedElastic());

@ -33,7 +33,7 @@ import org.springframework.util.StringUtils;
*/ */
public class PolarisAutoServiceRegistration extends AbstractAutoServiceRegistration<Registration> { public class PolarisAutoServiceRegistration extends AbstractAutoServiceRegistration<Registration> {
private static final Logger log = LoggerFactory.getLogger(PolarisAutoServiceRegistration.class); private static final Logger LOG = LoggerFactory.getLogger(PolarisAutoServiceRegistration.class);
private final PolarisRegistration registration; private final PolarisRegistration registration;
@ -60,7 +60,7 @@ public class PolarisAutoServiceRegistration extends AbstractAutoServiceRegistrat
@Override @Override
protected void register() { protected void register() {
if (!this.registration.isRegisterEnabled()) { if (!this.registration.isRegisterEnabled()) {
log.debug("Registration disabled."); LOG.debug("Registration disabled.");
return; return;
} }
if (this.registration.getPort() <= 0) { if (this.registration.getPort() <= 0) {

@ -51,7 +51,7 @@ import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
*/ */
public class PolarisServiceRegistry implements ServiceRegistry<Registration> { public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
private static final Logger log = LoggerFactory.getLogger(PolarisServiceRegistry.class); private static final Logger LOG = LoggerFactory.getLogger(PolarisServiceRegistry.class);
private static final int ttl = 5; private static final int ttl = 5;
@ -82,7 +82,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
@Override @Override
public void register(Registration registration) { public void register(Registration registration) {
if (StringUtils.isEmpty(registration.getServiceId())) { if (StringUtils.isEmpty(registration.getServiceId())) {
log.warn("No service to register for polaris client..."); LOG.warn("No service to register for polaris client...");
return; return;
} }
// Register instance. // Register instance.
@ -105,7 +105,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
try { try {
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI(); ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
providerClient.register(instanceRegisterRequest); providerClient.register(instanceRegisterRequest);
log.info("polaris registry, {} {} {}:{} {} register finished", LOG.info("polaris registry, {} {} {}:{} {} register finished",
polarisDiscoveryProperties.getNamespace(), polarisDiscoveryProperties.getNamespace(),
registration.getServiceId(), registration.getHost(), registration.getServiceId(), registration.getHost(),
registration.getPort(), staticMetadataManager.getMergedStaticMetadata()); registration.getPort(), staticMetadataManager.getMergedStaticMetadata());
@ -118,17 +118,17 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
} }
} }
catch (Exception e) { catch (Exception e) {
log.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e); LOG.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e);
rethrowRuntimeException(e); rethrowRuntimeException(e);
} }
} }
@Override @Override
public void deregister(Registration registration) { public void deregister(Registration registration) {
log.info("De-registering from Polaris Server now..."); LOG.info("De-registering from Polaris Server now...");
if (StringUtils.isEmpty(registration.getServiceId())) { if (StringUtils.isEmpty(registration.getServiceId())) {
log.warn("No dom to de-register for polaris client..."); LOG.warn("No dom to de-register for polaris client...");
return; return;
} }
@ -144,14 +144,14 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
providerClient.deRegister(deRegisterRequest); providerClient.deRegister(deRegisterRequest);
} }
catch (Exception e) { catch (Exception e) {
log.error("ERR_POLARIS_DEREGISTER, de-register failed...{},", registration, e); LOG.error("ERR_POLARIS_DEREGISTER, de-register failed...{},", registration, e);
} }
finally { finally {
if (null != heartbeatExecutor) { if (null != heartbeatExecutor) {
heartbeatExecutor.shutdown(); heartbeatExecutor.shutdown();
} }
} }
log.info("De-registration finished."); LOG.info("De-registration finished.");
} }
@Override @Override
@ -204,7 +204,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
heartbeatRequest.getHost(), heartbeatRequest.getPort(), healthCheckEndpoint); heartbeatRequest.getHost(), heartbeatRequest.getPort(), healthCheckEndpoint);
if (!OkHttpUtil.get(healthCheckUrl, null)) { if (!OkHttpUtil.get(healthCheckUrl, null)) {
log.error("backend service health check failed. health check endpoint = {}", healthCheckEndpoint); LOG.error("backend service health check failed. health check endpoint = {}", healthCheckEndpoint);
return; return;
} }
} }
@ -212,10 +212,10 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest); polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
} }
catch (PolarisException e) { catch (PolarisException e) {
log.error("polaris heartbeat[{}]", e.getCode(), e); LOG.error("polaris heartbeat[{}]", e.getCode(), e);
} }
catch (Exception e) { catch (Exception e) {
log.error("polaris heartbeat runtime error", e); LOG.error("polaris heartbeat runtime error", e);
} }
}, ttl, ttl, TimeUnit.SECONDS); }, ttl, ttl, TimeUnit.SECONDS);
} }

Loading…
Cancel
Save