private ConnectionFactoryBuilder newConnectionFactoryBuilder(final Config conf) { ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder(); ifset(conf, "authWaitTime", path -> builder .setAuthWaitTime(conf.getDuration(path, TimeUnit.MILLISECONDS))); ifset(conf, "daemon", path -> builder.setDaemon(conf.getBoolean(path))); ifset(conf, "enableMetrics", path -> builder .setEnableMetrics(enumFor(conf.getString(path), MetricType.values()))); ifset(conf, "failureMode", path -> builder .setFailureMode(enumFor(conf.getString(path), FailureMode.values()))); ifset(conf, "locator", path -> builder .setLocatorType(enumFor(conf.getString(path), Locator.values()))); ifset(conf, "maxReconnectDelay", path -> builder .setMaxReconnectDelay(conf.getDuration(path, TimeUnit.SECONDS))); ifset(conf, "opQueueMaxBlockTime", path -> builder .setOpQueueMaxBlockTime(conf.getDuration(path, TimeUnit.MILLISECONDS))); ifset(conf, "opTimeout", path -> builder .setOpTimeout(conf.getDuration(path, TimeUnit.MILLISECONDS))); ifset(conf, "protocol", path -> builder .setProtocol(enumFor(conf.getString(path), Protocol.values()))); ifset(conf, "readBufferSize", path -> builder .setReadBufferSize(conf.getInt(path))); ifset(conf, "shouldOptimize", path -> builder .setShouldOptimize(conf.getBoolean(path))); ifset(conf, "timeoutExceptionThreshold", path -> builder .setTimeoutExceptionThreshold(conf.getInt(path))); ifset(conf, "useNagleAlgorithm", path -> builder .setUseNagleAlgorithm(conf.getBoolean(path))); return builder; }
.setHashAlg(MURMUR3_128) .setProtocol(ConnectionFactoryBuilder.Protocol.valueOf(StringUtils.toUpperCase(config.getProtocol()))) .setLocatorType(ConnectionFactoryBuilder.Locator.valueOf(StringUtils.toUpperCase(config.getLocator()))) .setDaemon(true) .setFailureMode(FailureMode.Cancel)
new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH) .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT) .setDaemon(true) .setFailureMode(FailureMode.Retry)
public static MemcachedCache create(final MemcachedCacheConfig config, String memcachedPrefix, int timeToLive) { try { SerializingTranscoder transcoder = new SerializingTranscoder(config.getMaxObjectSize()); // always no compression inside, we compress/decompress outside transcoder.setCompressionThreshold(Integer.MAX_VALUE); OperationQueueFactory opQueueFactory; int maxQueueSize = config.getMaxOperationQueueSize(); if (maxQueueSize > 0) { opQueueFactory = new ArrayOperationQueueFactory(maxQueueSize); } else { opQueueFactory = new LinkedOperationQueueFactory(); } String hostsStr = config.getHosts(); ConnectionFactory connectionFactory = new MemcachedConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH) .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true) .setFailureMode(FailureMode.Redistribute).setTranscoder(transcoder).setShouldOptimize(true) .setOpQueueMaxBlockTime(config.getTimeout()).setOpTimeout(config.getTimeout()) .setReadBufferSize(config.getReadBufferSize()).setOpQueueFactory(opQueueFactory).build(); return new MemcachedCache(new MemcachedClient(new MemcachedConnectionFactory(connectionFactory), AddrUtil.getAddresses(hostsStr)), config, memcachedPrefix, timeToLive); } catch (IOException e) { logger.error("Unable to create MemcachedCache instance.", e); throw Throwables.propagate(e); } }
public void setLocatorType(final Locator l) { connectionFactoryBuilder.setLocatorType(l); }
public void setLocatorType(final Locator l) { connectionFactoryBuilder.setLocatorType(l); }
public void setLocatorType(final Locator l) { connectionFactoryBuilder.setLocatorType(l); }
public void setLocatorType(final Locator l) { connectionFactoryBuilder.setLocatorType(l); }
builder.setLocatorType(Locator.ARRAY_MOD); } else if ("ketama".equals(distributionValue) || "consistent_ketama".equals(distributionValue)) { builder.setLocatorType(Locator.CONSISTENT); } else { throw Error.newNotSupport(ruby, "distribution not support");
private ConnectionFactoryBuilder newConnectionFactoryBuilder(final Config conf) { ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder(); ifset(conf, "authWaitTime", path -> builder .setAuthWaitTime(conf.getDuration(path, TimeUnit.MILLISECONDS))); ifset(conf, "daemon", path -> builder.setDaemon(conf.getBoolean(path))); ifset(conf, "enableMetrics", path -> builder .setEnableMetrics(enumFor(conf.getString(path), MetricType.values()))); ifset(conf, "failureMode", path -> builder .setFailureMode(enumFor(conf.getString(path), FailureMode.values()))); ifset(conf, "locator", path -> builder .setLocatorType(enumFor(conf.getString(path), Locator.values()))); ifset(conf, "maxReconnectDelay", path -> builder .setMaxReconnectDelay(conf.getDuration(path, TimeUnit.SECONDS))); ifset(conf, "opQueueMaxBlockTime", path -> builder .setOpQueueMaxBlockTime(conf.getDuration(path, TimeUnit.MILLISECONDS))); ifset(conf, "opTimeout", path -> builder .setOpTimeout(conf.getDuration(path, TimeUnit.MILLISECONDS))); ifset(conf, "protocol", path -> builder .setProtocol(enumFor(conf.getString(path), Protocol.values()))); ifset(conf, "readBufferSize", path -> builder .setReadBufferSize(conf.getInt(path))); ifset(conf, "shouldOptimize", path -> builder .setShouldOptimize(conf.getBoolean(path))); ifset(conf, "timeoutExceptionThreshold", path -> builder .setTimeoutExceptionThreshold(conf.getInt(path))); ifset(conf, "useNagleAlgorithm", path -> builder .setUseNagleAlgorithm(conf.getBoolean(path))); return builder; }
builder.setLocatorType(Locator.CONSISTENT);
@Override public CacheClient create(final List<InetSocketAddress> addrs, final CacheConfiguration conf) throws IOException { // currently its works because this factory creates clients with the same connection settings, only memcached // addresses can be changed if (connectionFactory == null) { ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder(); if (conf.isConsistentHashing()) { builder.setHashAlg(DefaultHashAlgorithm.KETAMA_HASH); builder.setLocatorType(Locator.CONSISTENT); } builder.setProtocol(conf.isUseBinaryProtocol() ? Protocol.BINARY : Protocol.TEXT); if (conf.getOperationTimeout() != null) { builder.setOpTimeout(conf.getOperationTimeout()); } if (conf instanceof SpymemcachedConfiguration) { setProviderSpecificSettings(builder, (SpymemcachedConfiguration) conf); } connectionFactory = builder.build(); } return new MemcacheClientWrapper(new MemcachedClient(connectionFactory, addrs)); }
.setHashAlg(MURMUR3_128) .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT) .setDaemon(true) .setFailureMode(FailureMode.Cancel)
.setHashAlg(MURMUR3_128) .setProtocol(ConnectionFactoryBuilder.Protocol.valueOf(StringUtils.toUpperCase(config.getProtocol()))) .setLocatorType(ConnectionFactoryBuilder.Locator.valueOf(StringUtils.toUpperCase(config.getLocator()))) .setDaemon(true) .setFailureMode(FailureMode.Cancel)
public static MemcachedCache create(final MemcachedCacheConfig config, String memcachedPrefix, int timeToLive) { try { SerializingTranscoder transcoder = new SerializingTranscoder(config.getMaxObjectSize()); // always no compression inside, we compress/decompress outside transcoder.setCompressionThreshold(Integer.MAX_VALUE); OperationQueueFactory opQueueFactory; int maxQueueSize = config.getMaxOperationQueueSize(); if (maxQueueSize > 0) { opQueueFactory = new ArrayOperationQueueFactory(maxQueueSize); } else { opQueueFactory = new LinkedOperationQueueFactory(); } String hostsStr = config.getHosts(); ConnectionFactory connectionFactory = new MemcachedConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH) .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true) .setFailureMode(FailureMode.Redistribute).setTranscoder(transcoder).setShouldOptimize(true) .setOpQueueMaxBlockTime(config.getTimeout()).setOpTimeout(config.getTimeout()) .setReadBufferSize(config.getReadBufferSize()).setOpQueueFactory(opQueueFactory).build(); return new MemcachedCache(new MemcachedClient(new MemcachedConnectionFactory(connectionFactory), AddrUtil.getAddresses(hostsStr)), config, memcachedPrefix, timeToLive); } catch (IOException e) { logger.error("Unable to create MemcachedCache instance.", e); throw Throwables.propagate(e); } }
new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH) .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT) .setDaemon(true) .setFailureMode(FailureMode.Cancel)
builder.setLocatorType(conf.getLocatorType());
builder.setLocatorType(conf.getLocatorType());