in core/src/main/java/com/google/cloud/sql/core/MonitoredCache.java [79:112]
private void checkDomainName() {
// Resolve the domain name again. If it changed, close the sockets
try {
CloudSqlInstanceName resolved = this.resolve.apply(cache.getConfig());
if (!resolved.getConnectionName().equals(cache.getConfig().getCloudSqlInstance())) {
logger.info(
"Cloud SQL Instance associated with domain name {} changed from {} to {}.",
cache.getConfig().getDomainName(),
cache.getConfig().getCloudSqlInstance(),
resolved.getConnectionName());
this.close();
return;
}
} catch (RuntimeException e) {
// The domain name failed to resolve. Log the error and continue. Do not close the
// connections on a dns error.
logger.debug(
"Cloud SQL Instance associated with domain name {} did not resolve {}.",
cache.getConfig().getDomainName(),
cache.getConfig().getCloudSqlInstance(),
e);
}
// Iterate through the list of sockets and remove all closed sockets.
// this will reuse the existing ArrayList.
synchronized (sockets) {
for (Iterator<Socket> it = sockets.iterator(); it.hasNext(); ) {
Socket socket = it.next();
if (socket.isClosed()) {
it.remove();
}
}
}
}