Fix #8405, Remove Autowired in EventProcessor.
This commit is contained in:
binbin.zhang 2022-05-27 15:12:41 +08:00 committed by GitHub
commit 16ed6f64b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,10 +21,10 @@ import com.alibaba.nacos.istio.misc.Loggers;
import com.alibaba.nacos.istio.util.IstioExecutor; import com.alibaba.nacos.istio.util.IstioExecutor;
import com.alibaba.nacos.istio.xds.NacosXdsService; import com.alibaba.nacos.istio.xds.NacosXdsService;
import com.alibaba.nacos.sys.utils.ApplicationUtils; import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -41,10 +41,8 @@ public class EventProcessor {
private static final int MAX_WAIT_EVENT_TIME = 100; private static final int MAX_WAIT_EVENT_TIME = 100;
@Autowired
private NacosMcpService nacosMcpService; private NacosMcpService nacosMcpService;
@Autowired
private NacosXdsService nacosXdsService; private NacosXdsService nacosXdsService;
private NacosResourceManager resourceManager; private NacosResourceManager resourceManager;
@ -89,6 +87,10 @@ public class EventProcessor {
Event lastEvent = null; Event lastEvent = null;
while (true) { while (true) {
try { try {
if (!checkDependenceReady()) {
// Make sure dependency service has ready before consumer service event.
TimeUnit.SECONDS.sleep(1);
}
// Today we only care about service event, // Today we only care about service event,
// so we simply ignore event until the last task has been completed. // so we simply ignore event until the last task has been completed.
Event event = events.poll(MAX_WAIT_EVENT_TIME, TimeUnit.MILLISECONDS); Event event = events.poll(MAX_WAIT_EVENT_TIME, TimeUnit.MILLISECONDS);
@ -128,14 +130,23 @@ public class EventProcessor {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
if (null == resourceManager) {
resourceManager = ApplicationUtils.getBean(NacosResourceManager.class);
}
ResourceSnapshot snapshot = resourceManager.createResourceSnapshot(); ResourceSnapshot snapshot = resourceManager.createResourceSnapshot();
nacosXdsService.handleEvent(snapshot, event); nacosXdsService.handleEvent(snapshot, event);
nacosMcpService.handleEvent(snapshot, event); nacosMcpService.handleEvent(snapshot, event);
return null; return null;
} }
} }
private boolean checkDependenceReady() {
if (null == resourceManager) {
resourceManager = ApplicationUtils.getBean(NacosResourceManager.class);
}
if (null == nacosXdsService) {
nacosXdsService = ApplicationUtils.getBean(NacosXdsService.class);
}
if (null == nacosMcpService) {
nacosMcpService = ApplicationUtils.getBean(NacosMcpService.class);
}
return Objects.nonNull(resourceManager) && Objects.nonNull(nacosMcpService) && Objects.nonNull(nacosXdsService);
}
} }