Skip to content

Commit

Permalink
Update Memcached to use DynamicDNS
Browse files Browse the repository at this point in the history
  • Loading branch information
tootedom committed Jun 10, 2018
1 parent d878b4f commit a443ec6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
*
*/
class BaseMemcachedCache<V extends Serializable> implements RequiresShutdown,ClearableCache,
abstract class BaseMemcachedCache<V extends Serializable> implements RequiresShutdown,ClearableCache,
SerializableOnlyCacheWithExpiry<V>, RevalidateInBackgroundCapableCache<V>
{

Expand Down Expand Up @@ -91,12 +91,22 @@ public static ReferencedClientFactory createReferenceClientFactory(ElastiCacheCa
private final CacheKeyCreator cacheKeyCreator;


public BaseMemcachedCache(MemcachedCacheConfig config) {
this(null,config);
}

public BaseMemcachedCache(
MemcachedClientFactory clientFactory,
MemcachedCacheConfig config) {
this.config = config;
if(clientFactory == null) {
this.clientFactory = buildClientFactory(config);
} else {
this.clientFactory = clientFactory;
}


cacheKeyCreator = CacheKeyCreatorFactory.DEFAULT_INSTANCE.create(config);
this.clientFactory = clientFactory;

int maxCapacity = config.getMaxCapacity();

Expand Down Expand Up @@ -142,6 +152,9 @@ public BaseMemcachedCache(
staleCacheWriter = new NoWaitForCacheWrite(metricRecorder);
}

public abstract MemcachedClientFactory buildClientFactory(Object cfg);


private ConcurrentMap createInternalCache(boolean createCache,
int initialCapacity,
int maxCapacity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.greencheek.caching.herdcache.memcached.elasticacheconfig.client.ElastiCacheServerConnectionDetails;
import org.greencheek.caching.herdcache.memcached.elasticacheconfig.client.LocalhostElastiCacheServerConnectionDetails;
import org.greencheek.caching.herdcache.memcached.factory.ElastiCacheClientFactory;
import org.greencheek.caching.herdcache.memcached.factory.MemcachedClientFactory;
import org.greencheek.caching.herdcache.memcached.factory.ReferencedClientFactory;

import java.io.Serializable;
Expand Down Expand Up @@ -45,6 +46,29 @@ private ElastiCacheMemcachedCache(MemcachedCacheConfig mConfig,ElastiCacheCacheC
}


@Override
public MemcachedClientFactory buildClientFactory(Object cfg) {
ElastiCacheCacheConfig config = (ElastiCacheCacheConfig) cfg;
MemcachedCacheConfig mConfig = config.getMemcachedCacheConfig();
return new ElastiCacheClientFactory(
createReferenceClientFactory(config),
ElastiCacheConfigHostsParser.parseElastiCacheConfigHosts(config.getElastiCacheConfigHosts()),
config.getConfigPollingTime(),
config.getInitialConfigPollingDelay(),
config.getIdleReadTimeout(),
config.getReconnectDelay(),
config.getDelayBeforeClientClose(),
mConfig.getHostResolver(),
mConfig.getDnsConnectionTimeout(),
config.isUpdateConfigVersionOnDnsTimeout(),
config.getNumberOfConsecutiveInvalidConfigurationsBeforeReconnect(),
config.getConnectionTimeoutInMillis(),
config.getClusterUpdatedObservers(),
config.getConfigUrlUpdater(),
config.isUpdateConfigOnlyOnVersionChange());

}



}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.greencheek.caching.herdcache.memcached;

import org.greencheek.caching.herdcache.memcached.config.ElastiCacheCacheConfig;
import org.greencheek.caching.herdcache.memcached.config.MemcachedCacheConfig;
import org.greencheek.caching.herdcache.memcached.factory.FolsomReferencedClientFactory;
import org.greencheek.caching.herdcache.memcached.factory.MemcachedClientFactory;
import org.greencheek.caching.herdcache.memcached.factory.SpyMemcachedClientFactory;

import java.io.Serializable;
Expand All @@ -15,4 +17,13 @@ public FolsomMemcachedCache(ElastiCacheCacheConfig config) {
config.getMemcachedCacheConfig().getDnsConnectionTimeout(), config.getMemcachedCacheConfig().getHostStringParser(),
config.getMemcachedCacheConfig().getHostResolver(), new FolsomReferencedClientFactory<V>(config)), config.getMemcachedCacheConfig());
}

@Override
public MemcachedClientFactory buildClientFactory(Object cfg) {
ElastiCacheCacheConfig config = (ElastiCacheCacheConfig) cfg;

return new SpyMemcachedClientFactory<V>(config.getMemcachedCacheConfig().getMemcachedHosts(),
config.getMemcachedCacheConfig().getDnsConnectionTimeout(), config.getMemcachedCacheConfig().getHostStringParser(),
config.getMemcachedCacheConfig().getHostResolver(), new FolsomReferencedClientFactory<V>(config));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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;

Expand All @@ -11,8 +13,19 @@
*/
public class SpyMemcachedCache<V extends Serializable> extends BaseMemcachedCache<V> {
public SpyMemcachedCache(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)));
}
}
}

0 comments on commit a443ec6

Please sign in to comment.