Commit b9ff6841 by Jason Song

Let client access the server which answers long polling first

parent 33ec16d3
...@@ -95,7 +95,6 @@ public class ConfigServiceLocator implements Initializable { ...@@ -95,7 +95,6 @@ public class ConfigServiceLocator implements Initializable {
m_configUtil.getRefreshTimeUnit()); m_configUtil.getRefreshTimeUnit());
} }
//TODO periodically update config services
private synchronized void updateConfigServices() { private synchronized void updateConfigServices() {
String domainName = m_configUtil.getMetaServerDomainName(); String domainName = m_configUtil.getMetaServerDomainName();
String url = domainName + "/services/config"; String url = domainName + "/services/config";
......
...@@ -57,6 +57,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -57,6 +57,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
private final ScheduledExecutorService m_executorService; private final ScheduledExecutorService m_executorService;
private final AtomicBoolean m_longPollingStopped; private final AtomicBoolean m_longPollingStopped;
private SchedulePolicy m_longPollSchedulePolicy; private SchedulePolicy m_longPollSchedulePolicy;
private AtomicReference<ServiceDTO> m_longPollServiceDto;
/** /**
* Constructor. * Constructor.
...@@ -79,6 +80,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -79,6 +80,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
m_longPollingStopped = new AtomicBoolean(false); m_longPollingStopped = new AtomicBoolean(false);
m_executorService = Executors.newScheduledThreadPool(1, m_executorService = Executors.newScheduledThreadPool(1,
ApolloThreadFactory.create("RemoteConfigRepository", true)); ApolloThreadFactory.create("RemoteConfigRepository", true));
m_longPollServiceDto = new AtomicReference<>();
this.trySync(); this.trySync();
this.schedulePeriodicRefresh(); this.schedulePeriodicRefresh();
this.scheduleLongPollingRefresh(); this.scheduleLongPollingRefresh();
...@@ -148,8 +150,12 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -148,8 +150,12 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
List<ServiceDTO> configServices = getConfigServices(); List<ServiceDTO> configServices = getConfigServices();
for (int i = 0; i < maxRetries; i++) { for (int i = 0; i < maxRetries; i++) {
List<ServiceDTO> randomConfigServices = Lists.newArrayList(configServices); List<ServiceDTO> randomConfigServices = Lists.newLinkedList(configServices);
Collections.shuffle(randomConfigServices); Collections.shuffle(randomConfigServices);
//Access the server which notifies the client first
if (m_longPollServiceDto.get() != null) {
randomConfigServices.add(0, m_longPollServiceDto.getAndSet(null));
}
for (ServiceDTO configService : randomConfigServices) { for (ServiceDTO configService : randomConfigServices) {
String url = String url =
...@@ -272,6 +278,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -272,6 +278,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
logger.debug("Long polling response: {}, url: {}", response.getStatusCode(), url); logger.debug("Long polling response: {}, url: {}", response.getStatusCode(), url);
if (response.getStatusCode() == 200) { if (response.getStatusCode() == 200) {
m_longPollServiceDto.set(lastServiceDto);
longPollingService.submit(new Runnable() { longPollingService.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment