-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow resolution of multiple hosts from dns
- Loading branch information
Showing
25 changed files
with
845 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 20 additions & 3 deletions
23
src/main/java/org/greencheek/caching/herdcache/memcached/SpyObservableMemcachedCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
package org.greencheek.caching.herdcache.memcached; | ||
|
||
import org.greencheek.caching.herdcache.memcached.config.MemcachedCacheConfig; | ||
import org.greencheek.caching.herdcache.memcached.factory.DynamicSpyMemcachedClientFactory; | ||
import org.greencheek.caching.herdcache.memcached.factory.MemcachedClientFactory; | ||
import org.greencheek.caching.herdcache.memcached.factory.SpyMemcachedClientFactory; | ||
import org.greencheek.caching.herdcache.memcached.factory.SpyMemcachedReferencedClientFactory; | ||
|
||
import java.io.Serializable; | ||
import java.time.Duration; | ||
|
||
/** | ||
* Created by dominictootell on 26/08/2014. | ||
*/ | ||
public class SpyObservableMemcachedCache<V extends Serializable> extends BaseObservableMemcachedCache<V> { | ||
MemcachedCacheConfig config; | ||
|
||
public SpyObservableMemcachedCache(MemcachedCacheConfig config) { | ||
super(new SpyMemcachedClientFactory<V>(config.getMemcachedHosts(), | ||
config.getDnsConnectionTimeout(),config.getHostStringParser(), | ||
config.getHostResolver(),new SpyMemcachedReferencedClientFactory<V>(createMemcachedConnectionFactory(config))), config); | ||
super(config); | ||
} | ||
|
||
|
||
public MemcachedClientFactory buildClientFactory(Object cfg) { | ||
MemcachedCacheConfig config = (MemcachedCacheConfig)cfg; | ||
if (config.resolveHostsFromDns()) { | ||
return new DynamicSpyMemcachedClientFactory<V>(config.getMemcachedHosts(), | ||
config.getDurationForResolvingHostsFromDns(),config.getHostStringParser(),new SpyMemcachedReferencedClientFactory<V>(createMemcachedConnectionFactory(config))); | ||
} else { | ||
return new SpyMemcachedClientFactory<V>(config.getMemcachedHosts(), | ||
config.getDnsConnectionTimeout(),config.getHostStringParser(), | ||
config.getHostResolver(),new SpyMemcachedReferencedClientFactory<V>(createMemcachedConnectionFactory(config))); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/org/greencheek/caching/herdcache/memcached/dns/AddressResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.greencheek.caching.herdcache.memcached.dns; | ||
|
||
import java.net.InetAddress; | ||
|
||
/** | ||
* TODO Document | ||
*/ | ||
public interface AddressResolver { | ||
|
||
/** | ||
* Resolve a host name into one or more IPvX address types. | ||
* | ||
* @param host The host to resolve the IP addresses for. | ||
* | ||
* @return An array of one or more {@link InetAddress} details for a given host. If an error occurred (such as an | ||
* unknown host, or a DNS collision) then an empty result should be returned. | ||
*/ | ||
InetAddress[] resolve(String host); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/greencheek/caching/herdcache/memcached/dns/DefaultAddressResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.greencheek.caching.herdcache.memcached.dns; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.Inet4Address; | ||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Default {@link AddressResolver} that defers to the {@link InetAddress#getAllByName(String)} method for address | ||
* resolution. | ||
* | ||
* If the DNS resolver returns 127.0.53.53 (https://www.icann.org/resources/pages/name-collision-2013-12-06-en), | ||
* then it is ignored from the list of returned addresses. | ||
* | ||
* If there are no addresses, then an Array with 0 elements is returned. | ||
*/ | ||
public class DefaultAddressResolver implements AddressResolver { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAddressResolver.class); | ||
|
||
public static final InetAddress[] EMPTY = new InetAddress[0]; | ||
|
||
@Override | ||
public InetAddress[] resolve(final String host) { | ||
|
||
try { | ||
InetAddress[] addresses = InetAddress.getAllByName(host); | ||
|
||
if (addresses.length == 0) { | ||
return EMPTY; | ||
} | ||
|
||
return addresses; | ||
} catch (UnknownHostException e) { | ||
LOGGER.warn("Failed to resolve address for '{}'", host, e); | ||
return EMPTY; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/org/greencheek/caching/herdcache/memcached/dns/resolver/Foreground.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.greencheek.caching.herdcache.memcached.dns.resolver; | ||
|
||
/** | ||
* Created by dominictootell on 17/05/2018. | ||
*/ | ||
public class Foreground { | ||
|
||
|
||
} |
Oops, something went wrong.