Search in sources :

Example 6 with CachedData

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();
        }
    };
}
Also used : CachedData(net.spy.memcached.CachedData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TimeUnit(java.util.concurrent.TimeUnit) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) BulkGetCompletionListener(net.spy.memcached.internal.BulkGetCompletionListener) BulkFuture(net.spy.memcached.internal.BulkFuture)

Example 7 with CachedData

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;
        }
    };
}
Also used : CachedData(net.spy.memcached.CachedData) Future(java.util.concurrent.Future) OperationFuture(net.spy.memcached.internal.OperationFuture) BulkFuture(net.spy.memcached.internal.BulkFuture) TimeUnit(java.util.concurrent.TimeUnit)

Example 8 with CachedData

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());
    }
}
Also used : lombok.val(lombok.val) CachedData(net.spy.memcached.CachedData) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with CachedData

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);
    }
}
Also used : lombok.val(lombok.val) CachedData(net.spy.memcached.CachedData) KryoException(com.esotericsoftware.kryo.KryoException) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KryoException(com.esotericsoftware.kryo.KryoException)

Aggregations

CachedData (net.spy.memcached.CachedData)9 TimeUnit (java.util.concurrent.TimeUnit)4 BulkFuture (net.spy.memcached.internal.BulkFuture)4 Output (com.esotericsoftware.kryo.io.Output)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Future (java.util.concurrent.Future)2 lombok.val (lombok.val)2 BulkGetCompletionListener (net.spy.memcached.internal.BulkGetCompletionListener)2 OperationFuture (net.spy.memcached.internal.OperationFuture)2 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)2 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)2 KryoException (com.esotericsoftware.kryo.KryoException)1 LinkedHashMap (java.util.LinkedHashMap)1 AcceptUsersAuthenticationHandler (org.apereo.cas.authentication.AcceptUsersAuthenticationHandler)1 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)1 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)1