dnsMonitoring turned on by default for SingleServerConfig

pull/903/head
Nikita 8 years ago
parent ee3617be5d
commit 4a37a5e4a4

@ -64,7 +64,7 @@ public class SingleServerConfig extends BaseConfig<SingleServerConfig> {
* <em>NB: applications must ensure the JVM DNS cache TTL is low enough to support this.</em> * <em>NB: applications must ensure the JVM DNS cache TTL is low enough to support this.</em>
* e.g., http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-jvm-ttl.html * e.g., http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-jvm-ttl.html
*/ */
private boolean dnsMonitoring = false; private boolean dnsMonitoring = true;
/** /**
* Interval in milliseconds to check DNS * Interval in milliseconds to check DNS
@ -144,8 +144,10 @@ public class SingleServerConfig extends BaseConfig<SingleServerConfig> {
/** /**
* Monitoring of the endpoint address for DNS changes. * Monitoring of the endpoint address for DNS changes.
* * <p>
* Default is false * Applications must ensure the JVM DNS cache TTL is low enough to support this
* <p>
* Default is <code>true</code>
* *
* @param dnsMonitoring flag * @param dnsMonitoring flag
* @return config * @return config
@ -161,7 +163,7 @@ public class SingleServerConfig extends BaseConfig<SingleServerConfig> {
/** /**
* Interval in milliseconds to check the endpoint DNS if {@link #isDnsMonitoring()} is true. * Interval in milliseconds to check the endpoint DNS if {@link #isDnsMonitoring()} is true.
* *
* Default is 5000 * Default is <code>5000</code>
* *
* @param dnsMonitoringInterval time * @param dnsMonitoringInterval time
* @return config * @return config

@ -93,27 +93,33 @@ public class SingleConnectionManager extends MasterSlaveConnectionManager {
} }
private void monitorDnsChange(final SingleServerConfig cfg) { private void monitorDnsChange(final SingleServerConfig cfg) {
monitorFuture = GlobalEventExecutor.INSTANCE.scheduleWithFixedDelay(new Runnable() { monitorFuture = GlobalEventExecutor.INSTANCE.schedule(new Runnable() {
@Override @Override
public void run() { public void run() {
try { // As InetAddress.getByName call is blocking. Method should be run in dedicated thread
InetAddress master = currentMaster.get(); getExecutor().execute(new Runnable() {
InetAddress now = InetAddress.getByName(cfg.getAddress().getHost()); @Override
if (!now.getHostAddress().equals(master.getHostAddress())) { public void run() {
log.info("Detected DNS change. {} has changed from {} to {}", cfg.getAddress().getHost(), master.getHostAddress(), now.getHostAddress()); try {
if (currentMaster.compareAndSet(master, now)) { InetAddress master = currentMaster.get();
changeMaster(singleSlotRange.getStartSlot(), cfg.getAddress()); InetAddress now = InetAddress.getByName(cfg.getAddress().getHost());
log.info("Master has been changed"); if (!now.getHostAddress().equals(master.getHostAddress())) {
log.info("Detected DNS change. {} has changed from {} to {}", cfg.getAddress().getHost(), master.getHostAddress(), now.getHostAddress());
if (currentMaster.compareAndSet(master, now)) {
changeMaster(singleSlotRange.getStartSlot(), cfg.getAddress());
log.info("Master has been changed");
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
monitorDnsChange(cfg);
} }
} }
});
} catch (Exception e) {
log.error(e.getMessage(), e);
}
} }
}, cfg.getDnsMonitoringInterval(), cfg.getDnsMonitoringInterval(), TimeUnit.MILLISECONDS); }, cfg.getDnsMonitoringInterval(), TimeUnit.MILLISECONDS);
} }
@Override @Override

Loading…
Cancel
Save