use of net.spy.memcached.CachedData in project druid by druid-io.
the class MockMemcachedClient method asyncGetBulk.
@Override
public <T> BulkFuture<Map<String, T>> asyncGetBulk(final Iterator<String> keys, final Transcoder<T> tc) {
return new BulkFuture<Map<String, T>>() {
@Override
public boolean isTimeout() {
return false;
}
@Override
public Map<String, T> getSome(long timeout, TimeUnit unit) {
return get();
}
@Override
public OperationStatus getStatus() {
return null;
}
@Override
public Future<Map<String, T>> addListener(BulkGetCompletionListener bulkGetCompletionListener) {
return null;
}
@Override
public Future<Map<String, T>> removeListener(BulkGetCompletionListener bulkGetCompletionListener) {
return null;
}
@Override
public boolean cancel(boolean b) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public Map<String, T> get() {
Map<String, T> retVal = new HashMap<>();
while (keys.hasNext()) {
String key = keys.next();
CachedData data = theMap.get(key);
retVal.put(key, data != null ? tc.decode(data) : null);
}
return retVal;
}
@Override
public Map<String, T> get(long l, TimeUnit timeUnit) {
return get();
}
};
}
use of net.spy.memcached.CachedData in project druid by druid-io.
the class MockMemcachedClient method asyncGet.
@Override
public <T> Future<T> asyncGet(String key, final Transcoder<T> tc) {
CachedData data = theMap.get(key);
final T theValue = data != null ? tc.decode(data) : null;
return new Future<T>() {
@Override
public boolean cancel(boolean b) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public T get() {
return theValue;
}
@Override
public T get(long l, TimeUnit timeUnit) {
return theValue;
}
};
}
use of net.spy.memcached.CachedData in project cas by apereo.
the class CasKryoTranscoderTests method verifyBorrowAndDecode.
@Test
public void verifyBorrowAndDecode() {
val data = new CachedData(0, ArrayUtils.EMPTY_BYTE_ARRAY, 10);
assertThrows(KryoException.class, () -> transcoder.decode(data));
if (transcoder instanceof CasKryoTranscoder) {
val enc = CasKryoTranscoder.class.cast(this.transcoder);
assertNotNull(enc.getKryo());
}
}
use of net.spy.memcached.CachedData in project cas by apereo.
the class CasKryoTranscoder method encode.
@Override
public CachedData encode(final Object obj) {
try (val kryo = this.kryoPool.borrow();
val byteStream = new ByteArrayOutputStream();
val output = new Output(byteStream)) {
if (obj != null) {
LOGGER.trace("Writing object [{}] to memcached ", obj.getClass());
}
kryo.writeClassAndObject(output, obj);
output.flush();
val bytes = byteStream.toByteArray();
return new CachedData(0, bytes, bytes.length);
} catch (final Exception exception) {
throw new KryoException(exception);
}
}
Aggregations