Java Code Examples for net.spy.memcached.ConnectionFactoryBuilder#setOpTimeout()

The following examples show how to use net.spy.memcached.ConnectionFactoryBuilder#setOpTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemcacheClientFactoryImpl.java    From simple-spring-memcached with MIT License 6 votes vote down vote up
@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));
}
 
Example 2
Source File: MemcacheClientFactoryImpl.java    From simple-spring-memcached with MIT License 5 votes vote down vote up
@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) {
        ElastiCacheConfiguration elasticacheConf = null;
        if (conf instanceof ElastiCacheConfiguration) {
            elasticacheConf = (ElastiCacheConfiguration) conf;
        }
        
        if (elasticacheConf != null && Boolean.TRUE.equals(elasticacheConf.getUseAutoDiscovery())) {
            // there is no way to use custom client settings and auto discovery together
            LOGGER.info("All cache settings will be ignored because useAutoDiscovery is true");
            return new MemcacheClientWrapper(new MemcachedClient(addrs));
        }
        
        
        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 (elasticacheConf != null) {
            setProviderSpecificSettings(builder, elasticacheConf);
        }

        connectionFactory = builder.build();
    }

    return new MemcacheClientWrapper(new MemcachedClient(connectionFactory, addrs));
}
 
Example 3
Source File: MemcacheClientFactoryImpl.java    From simple-spring-memcached with MIT License 4 votes vote down vote up
private void setProviderSpecificSettings(final ConnectionFactoryBuilder builder, final ElastiCacheConfiguration conf) {
    if (conf.getDaemon() != null) {
        builder.setDaemon(conf.getDaemon());
    }

    if (conf.getFailureMode() != null) {
        builder.setFailureMode(conf.getFailureMode());
    }

    if (conf.getHashAlg() != null) {
        builder.setHashAlg(conf.getHashAlg());
    }

    if (conf.getLocatorType() != null) {
        builder.setLocatorType(conf.getLocatorType());
    }

    if (conf.getMaxReconnectDelay() != null) {
        builder.setMaxReconnectDelay(conf.getMaxReconnectDelay());
    }

    if (conf.getOpQueueMaxBlockTime() != null) {
        builder.setOpQueueMaxBlockTime(conf.getOpQueueMaxBlockTime());
    }
    
    if (conf.getOpTimeout() != null) {
        builder.setOpTimeout(conf.getOpTimeout());
    }

    if (conf.getReadBufferSize() != null) {
        builder.setReadBufferSize(conf.getReadBufferSize());
    }

    if (conf.getShouldOptimize() != null) {
        builder.setShouldOptimize(conf.getShouldOptimize());
    }

    if (conf.getTimeoutExceptionThreshold() != null) {
        builder.setTimeoutExceptionThreshold(conf.getTimeoutExceptionThreshold());
    }

    if (conf.getUseNagleAlgorithm() != null) {
        builder.setUseNagleAlgorithm(conf.getUseNagleAlgorithm());
    }

    if (conf.getDefaultTranscoder() != null) {
        builder.setTranscoder(conf.getDefaultTranscoder());
    }

    if (conf.getAuthDescriptor() != null) {
        builder.setAuthDescriptor(conf.getAuthDescriptor());
    }
    
    if (conf.getAuthWaitTime() != null) {
        builder.setAuthWaitTime(conf.getAuthWaitTime());
    }

    if (conf.getInitialObservers() != null) {
        builder.setInitialObservers(conf.getInitialObservers());
    }
    
    if (conf.getClientMode() != null) {
        builder.setClientMode(conf.getClientMode());
    }
    
    if (conf.getEnableMetricType() != null) {
        builder.setEnableMetrics(conf.getEnableMetricType());
    }
    
    if (conf.getMetricCollector() != null) {
        builder.setMetricCollector(conf.getMetricCollector());
    }

}