@Override protected void setUp() throws Exception SerializingTranscoder transcoder = new SerializingTranscoder( 50 * 1024 * 1024 // 50 MB ); transcoder.setCompressionThreshold(Integer.MAX_VALUE);
int flags=0; if(o instanceof String) { b=encodeString((String)o); } else if(o instanceof Long) { b=tu.encodeLong((Long)o); flags |= SPECIAL_BYTEARRAY; } else { b=serialize(o); flags |= SERIALIZED; byte[] compressed=compress(b); if(compressed.length < b.length) { getLogger().info("Compressed %s from %d to %d", o.getClass().getName(), b.length, compressed.length); b=compressed; flags |= COMPRESSED; } else { getLogger().info( "Compression increased the size of %s from %d to %d", o.getClass().getName(), b.length, compressed.length); return new CachedData(flags, b, getMaxSize());
Object rv = null; if ((d.getFlags() & COMPRESSED) != 0) { data = decompress(d.getData()); rv = deserialize(data); } else if (flags != 0 && data != null) { switch (flags) { break; default: getLogger().warn("Undecodeable with flags %x", flags); rv = decodeString(data);
public Transcoder<Object> getDefaultTranscoder() { return new SerializingTranscoder(); }
/** * Attempt to get the object represented by the given serialized bytes. */ private Object deserialize() { SerializingTranscoder tc = new SerializingTranscoder(); CachedData d = new CachedData(this.getItemFlags(), this.getValue(), CachedData.MAX_SIZE); Object rv = null; rv = tc.decode(d); return rv; }
public MockMemcachedClient() { transcoder = new LZ4Transcoder(); transcoder.setCompressionThreshold(0); }
int flags = 0; if (o instanceof String) { b = encodeString((String) o); } else if (o instanceof Long) { b = tu.encodeLong((Long) o); flags |= SPECIAL_BYTEARRAY; } else { b = serialize(o); flags |= SERIALIZED; byte[] compressed = compress(b); if (compressed.length < b.length) { getLogger().debug("Compressed %s from %d to %d", o.getClass().getName(), b.length, compressed.length); b = compressed; flags |= COMPRESSED; } else { getLogger().info( "Compression increased the size of %s from %d to %d", o.getClass().getName(), b.length, compressed.length); return new CachedData(flags, b, getMaxSize());
Object rv=null; if((d.getFlags() & COMPRESSED) != 0) { data=decompress(d.getData()); rv=deserialize(data); } else if(flags != 0 && data != null) { switch(flags) { break; default: getLogger().warn("Undecodeable with flags %x", flags); rv=decodeString(data);
public Transcoder<Object> getDefaultTranscoder() { return new SerializingTranscoder(); }
/** * Attempt to get the object represented by the given serialized bytes. */ private Object deserialize() { SerializingTranscoder tc = new SerializingTranscoder(); CachedData d = new CachedData(this.getItemFlags(), this.getValue(), CachedData.MAX_SIZE); Object rv = null; rv = tc.decode(d); return rv; }
int flags=0; if(o instanceof String) { b=encodeString((String)o); } else if(o instanceof Long) { b=tu.encodeLong((Long)o); flags |= SPECIAL_BYTEARRAY; } else { b=serialize(o); flags |= SERIALIZED; byte[] compressed=compress(b); if(compressed.length < b.length) { getLogger().debug("Compressed %s from %d to %d", o.getClass().getName(), b.length, compressed.length); b=compressed; flags |= COMPRESSED; } else { getLogger().info( "Compression increased the size of %s from %d to %d", o.getClass().getName(), b.length, compressed.length); return new CachedData(flags, b, getMaxSize());
Object rv = null; if ((d.getFlags() & COMPRESSED) != 0) { data = decompress(d.getData()); rv = deserialize(data); } else if (flags != 0 && data != null) { switch (flags) { break; default: getLogger().warn("Undecodeable with flags %x", flags); rv = decodeString(data);
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 Transcoder<Object> getDefaultTranscoder() { return new SerializingTranscoder(); }
/** * Attempt to get the object represented by the given serialized bytes. */ private Object deserialize() { SerializingTranscoder tc = new SerializingTranscoder(); CachedData d = new CachedData(this.getItemFlags(), this.getValue(), CachedData.MAX_SIZE); Object rv = null; rv = tc.decode(d); return rv; }
int flags = 0; if (o instanceof String) { b = encodeString((String) o); if (StringUtils.isJsonObject((String) o)) { return new CachedData(flags, b, getMaxSize()); flags |= SPECIAL_BYTEARRAY; } else { b = serialize(o); flags |= SERIALIZED; byte[] compressed = compress(b); if (compressed.length < b.length) { getLogger().debug("Compressed %s from %d to %d", o.getClass().getName(), b.length, compressed.length); b = compressed; flags |= COMPRESSED; } else { getLogger().info("Compression increased the size of %s from %d to %d", o.getClass().getName(), b.length, compressed.length); return new CachedData(flags, b, getMaxSize());
Object rv = null; if ((d.getFlags() & COMPRESSED) != 0) { data = decompress(d.getData()); rv = deserialize(data); } else if (flags != 0 && data != null) { switch (flags) { break; default: getLogger().warn("Undecodeable with flags %x", flags); rv = decodeString(data);
/** * {@inheritDoc} */ @Override public Transcoder<Object> getDefaultTranscoder() { final SerializingTranscoder transcoder = new SerializingTranscoder(); transcoder.setCompressionThreshold( SerializingTranscoder.DEFAULT_COMPRESSION_THRESHOLD ); return new TranscoderWrapperStatisticsSupport( _statistics, transcoder ); }
public Transcoder<Object> getDefaultTranscoder() { return new SerializingTranscoder(); }
int flags = 0; if (o instanceof String) { b = encodeString((String) o); if (StringUtils.isJsonObject((String) o)) { return new CachedData(flags, b, getMaxSize()); flags |= SPECIAL_BYTEARRAY; } else { b = serialize(o); flags |= SERIALIZED; byte[] compressed = compress(b); if (compressed.length < b.length) { getLogger().debug("Compressed %s from %d to %d", o.getClass().getName(), b.length, compressed.length); b = compressed; flags |= COMPRESSED; } else { getLogger().info("Compression increased the size of %s from %d to %d", o.getClass().getName(), b.length, compressed.length); return new CachedData(flags, b, getMaxSize());