public MemberDiscovery(List<String> configCenterUri) { if (configCenterUri != null && !configCenterUri.isEmpty()) { configServerAddresses.addAll(configCenterUri); } Collections.shuffle(configServerAddresses); EventManager.register(this); }
/** * <p>As the process of instance registry is asynchronous, the {@code AFTER_REGISTRY} * event should not be sent immediately after {@link RegistryUtils#run()} is invoked. * When the instance registry succeeds, {@link MicroserviceInstanceRegisterTask} will be posted in {@link EventManager}, * register a subscriber to watch this event and send {@code AFTER_REGISTRY}.</p> * * <p>This method should be called before {@link RegistryUtils#run()} to avoid that the registry process is too quick * that the event is not watched by this subscriber.</p> * * <p>Check if {@code InstanceId} is null to judge whether the instance registry has succeeded.</p> */ private void triggerAfterRegistryEvent() { EventManager.register(new Object() { @Subscribe public void afterRegistryInstance(MicroserviceInstanceRegisterTask microserviceInstanceRegisterTask) { LOGGER.info("receive MicroserviceInstanceRegisterTask event, check instance Id..."); if (!StringUtils.isEmpty(RegistryUtils.getMicroserviceInstance().getInstanceId())) { LOGGER.info("instance registry succeeds for the first time, will send AFTER_REGISTRY event."); status = SCBStatus.UP; triggerEvent(EventType.AFTER_REGISTRY); EventManager.unregister(this); LOGGER.info("ServiceComb is ready."); } } }); }
public MemberDiscovery(List<String> configCenterUri) { if (configCenterUri != null && !configCenterUri.isEmpty()) { configServerAddresses.addAll(configCenterUri); } Collections.shuffle(configServerAddresses); EventManager.register(this); }
/** * <p>As the process of instance registry is asynchronous, the {@code AFTER_REGISTRY} * event should not be sent immediately after {@link RegistryUtils#run()} is invoked. * When the instance registry succeeds, {@link MicroserviceInstanceRegisterTask} will be posted in {@link EventManager}, * register a subscriber to watch this event and send {@code AFTER_REGISTRY}.</p> * * <p>This method should be called before {@link RegistryUtils#run()} to avoid that the registry process is too quick * that the event is not watched by this subscriber.</p> * * <p>Check if {@code InstanceId} is null to judge whether the instance registry has succeeded.</p> */ private void triggerAfterRegistryEvent() { EventManager.register(new Object() { @Subscribe public void afterRegistryInstance(MicroserviceInstanceRegisterTask microserviceInstanceRegisterTask) { LOGGER.info("receive MicroserviceInstanceRegisterTask event, check instance Id..."); if (!StringUtils.isEmpty(RegistryUtils.getMicroserviceInstance().getInstanceId())) { LOGGER.info("instance registry succeeds for the first time, will send AFTER_REGISTRY event."); status = SCBStatus.UP; triggerEvent(EventType.AFTER_REGISTRY); EventManager.unregister(this); LOGGER.info("ServiceComb is ready."); } } }); }