DEFAULT_READ_BUFFER_SIZE))); connectionFactoryBuilder.setOpTimeout(Integer.parseInt( getProperties().getProperty(OP_TIMEOUT_PROPERTY, DEFAULT_OP_TIMEOUT)));
public MemcachedBlockCache(Configuration c) throws IOException { LOG.info("Creating MemcachedBlockCache"); long opTimeout = c.getLong(MEMCACHED_OPTIMEOUT_KEY, MEMCACHED_DEFAULT_TIMEOUT); long queueTimeout = c.getLong(MEMCACHED_TIMEOUT_KEY, opTimeout + MEMCACHED_DEFAULT_TIMEOUT); boolean optimize = c.getBoolean(MEMCACHED_OPTIMIZE_KEY, MEMCACHED_OPTIMIZE_DEFAULT); ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder() .setOpTimeout(opTimeout) .setOpQueueMaxBlockTime(queueTimeout) // Cap the max time before anything times out .setFailureMode(FailureMode.Redistribute) .setShouldOptimize(optimize) .setDaemon(true) // Don't keep threads around past the end of days. .setUseNagleAlgorithm(false) // Ain't nobody got time for that .setReadBufferSize(HConstants.DEFAULT_BLOCKSIZE * 4 * 1024); // Much larger just in case // Assume only the localhost is serving memecached. // A la mcrouter or co-locating memcached with split regionservers. // // If this config is a pool of memecached servers they will all be used according to the // default hashing scheme defined by the memcache client. Spy Memecache client in this // case. String serverListString = c.get(MEMCACHED_CONFIG_KEY,"localhost:11211"); String[] servers = serverListString.split(","); List<InetSocketAddress> serverAddresses = new ArrayList<>(servers.length); for (String s:servers) { serverAddresses.add(Addressing.createInetSocketAddressFromHostAndPortStr(s)); } client = new MemcachedClient(builder.build(), serverAddresses); }
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; }
.setShouldOptimize(true) .setOpQueueMaxBlockTime(config.getTimeout()) .setOpTimeout(config.getTimeout()) .setReadBufferSize(config.getReadBufferSize()) .setOpQueueFactory(opQueueFactory)
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 setOpTimeout(final long t) { connectionFactoryBuilder.setOpTimeout(t); }
public void setOpTimeout(final long t) { connectionFactoryBuilder.setOpTimeout(t); }
public void setOpTimeout(final long t) { connectionFactoryBuilder.setOpTimeout(t); }
public void setOpTimeout(final long t) { connectionFactoryBuilder.setOpTimeout(t); }
: new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setAuthDescriptor(authDescriptor) .setOpTimeout(operationTimeout) .setMaxReconnectDelay(maxReconnectDelay) .build();
public MemcachedBlockCache(Configuration c) throws IOException { LOG.info("Creating MemcachedBlockCache"); long opTimeout = c.getLong(MEMCACHED_OPTIMEOUT_KEY, MEMCACHED_DEFAULT_TIMEOUT); long queueTimeout = c.getLong(MEMCACHED_TIMEOUT_KEY, opTimeout + MEMCACHED_DEFAULT_TIMEOUT); boolean optimize = c.getBoolean(MEMCACHED_OPTIMIZE_KEY, MEMCACHED_OPTIMIZE_DEFAULT); ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder() .setOpTimeout(opTimeout) .setOpQueueMaxBlockTime(queueTimeout) // Cap the max time before anything times out .setFailureMode(FailureMode.Redistribute) .setShouldOptimize(optimize) .setDaemon(true) // Don't keep threads around past the end of days. .setUseNagleAlgorithm(false) // Ain't nobody got time for that .setReadBufferSize(HConstants.DEFAULT_BLOCKSIZE * 4 * 1024); // Much larger just in case // Assume only the localhost is serving memecached. // A la mcrouter or co-locating memcached with split regionservers. // // If this config is a pool of memecached servers they will all be used according to the // default hashing scheme defined by the memcache client. Spy Memecache client in this // case. String serverListString = c.get(MEMCACHED_CONFIG_KEY,"localhost:11211"); String[] servers = serverListString.split(","); List<InetSocketAddress> serverAddresses = new ArrayList<>(servers.length); for (String s:servers) { serverAddresses.add(Addressing.createInetSocketAddressFromHostAndPortStr(s)); } client = new MemcachedClient(builder.build(), serverAddresses); }
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.setOpTimeout(conf.getOperationTimeout());
@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)); }
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) .setAuthDescriptor(authDescriptor) .setOpTimeout(operationTimeout) .setMaxReconnectDelay(maxReconnectDelay) .build();
.setShouldOptimize(true) .setOpQueueMaxBlockTime(config.getTimeout()) .setOpTimeout(config.getTimeout()) .setReadBufferSize(config.getReadBufferSize()) .setOpQueueFactory(opQueueFactory)
public ConnectionFactoryBuilder(ConnectionFactory cf) { setAuthDescriptor(cf.getAuthDescriptor()); setDaemon(cf.isDaemon()); setFailureMode(cf.getFailureMode()); setHashAlg(cf.getHashAlg()); setInitialObservers(cf.getInitialObservers()); setMaxReconnectDelay(cf.getMaxReconnectDelay()); setOpQueueMaxBlockTime(cf.getOpQueueMaxBlockTime()); setOpTimeout(cf.getOperationTimeout()); setReadBufferSize(cf.getReadBufSize()); setShouldOptimize(cf.shouldOptimize()); setTimeoutExceptionThreshold(cf.getTimeoutExceptionThreshold()); setTranscoder(cf.getDefaultTranscoder()); setUseNagleAlgorithm(cf.useNagleAlgorithm()); }
public ConnectionFactoryBuilder(ConnectionFactory cf) { setAuthDescriptor(cf.getAuthDescriptor()); setDaemon(cf.isDaemon()); setFailureMode(cf.getFailureMode()); setHashAlg(cf.getHashAlg()); setInitialObservers(cf.getInitialObservers()); setMaxReconnectDelay(cf.getMaxReconnectDelay()); setOpQueueMaxBlockTime(cf.getOpQueueMaxBlockTime()); setOpTimeout(cf.getOperationTimeout()); setReadBufferSize(cf.getReadBufSize()); setShouldOptimize(cf.shouldOptimize()); setTimeoutExceptionThreshold(cf.getTimeoutExceptionThreshold()); setTranscoder(cf.getDefaultTranscoder()); setUseNagleAlgorithm(cf.useNagleAlgorithm()); setEnableMetrics(cf.enableMetrics()); setListenerExecutorService(cf.getListenerExecutorService()); setAuthWaitTime(cf.getAuthWaitTime()); }
public ConnectionFactoryBuilder(ConnectionFactory cf) { setClientMode(cf.getClientMode()); setAuthDescriptor(cf.getAuthDescriptor()); setDaemon(cf.isDaemon()); setFailureMode(cf.getFailureMode()); setHashAlg(cf.getHashAlg()); setInitialObservers(cf.getInitialObservers()); setMaxReconnectDelay(cf.getMaxReconnectDelay()); setOpQueueMaxBlockTime(cf.getOpQueueMaxBlockTime()); setOpTimeout(cf.getOperationTimeout()); setReadBufferSize(cf.getReadBufSize()); setShouldOptimize(cf.shouldOptimize()); setTimeoutExceptionThreshold(cf.getTimeoutExceptionThreshold()); setTranscoder(cf.getDefaultTranscoder()); setUseNagleAlgorithm(cf.useNagleAlgorithm()); setEnableMetrics(cf.enableMetrics()); setListenerExecutorService(cf.getListenerExecutorService()); setAuthWaitTime(cf.getAuthWaitTime()); }