net.spy.memcached.ops.OperationQueueFactory Java Examples

The following examples show how to use net.spy.memcached.ops.OperationQueueFactory. 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: MemcachedCache.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #2
Source File: MemcachedCache.java    From kylin with Apache License 2.0 5 votes vote down vote up
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),
                getResolvedAddrList(hostsStr)), config, memcachedPrefix, timeToLive);
    } catch (IOException e) {
        logger.error("Unable to create MemcachedCache instance.", e);
        throw Throwables.propagate(e);
    }
}