List of usage examples for io.netty.util.concurrent Future cause
Throwable cause();
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<Void> toVoid(EventExecutor executor) { return new PromiseConverter<Void>(executor) { @Override/*from w w w.j a v a2 s.c om*/ public FutureListener<Object> newListener(final Promise<Void> promise) { return new FutureListener<Object>() { @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else { promise.trySuccess(null); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<ScanResult<byte[]>> toArrayScanResult(EventExecutor executor) { return new PromiseConverter<ScanResult<byte[]>>(executor) { @Override// w ww . j ava 2s . c o m public FutureListener<Object> newListener(final Promise<ScanResult<byte[]>> promise) { return new FutureListener<Object>() { @SuppressWarnings("unchecked") @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else { List<Object> list = (List<Object>) resp; promise.trySuccess( new ScanResult<byte[]>((byte[]) list.get(0), (List<byte[]>) list.get(1))); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<ScanResult<HashEntry>> toHashScanResult(EventExecutor executor) { return new PromiseConverter<ScanResult<HashEntry>>(executor) { @Override/*from w ww . j a v a2 s. com*/ public FutureListener<Object> newListener(final Promise<ScanResult<HashEntry>> promise) { return new FutureListener<Object>() { @SuppressWarnings("unchecked") @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else { List<Object> list = (List<Object>) resp; byte[] cursor = (byte[]) list.get(0); List<byte[]> rawValueList = (List<byte[]>) list.get(1); List<HashEntry> values = new ArrayList<>(rawValueList.size() / 2); for (Iterator<byte[]> iter = rawValueList.iterator(); iter.hasNext();) { values.add(new HashEntry(iter.next(), iter.next())); } promise.trySuccess(new ScanResult<HashEntry>(cursor, values)); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<ScanResult<SortedSetEntry>> toSortedSetScanResult(EventExecutor executor) { return new PromiseConverter<ScanResult<SortedSetEntry>>(executor) { @Override//from w w w. j av a 2 s . c om public FutureListener<Object> newListener(final Promise<ScanResult<SortedSetEntry>> promise) { return new FutureListener<Object>() { @SuppressWarnings("unchecked") @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else { List<Object> list = (List<Object>) resp; byte[] cursor = (byte[]) list.get(0); List<byte[]> rawValueList = (List<byte[]>) list.get(1); List<SortedSetEntry> values = new ArrayList<>(rawValueList.size() / 2); for (Iterator<byte[]> iter = rawValueList.iterator(); iter.hasNext();) { values.add(new SortedSetEntry(iter.next(), bytesToDouble(iter.next()))); } promise.trySuccess(new ScanResult<SortedSetEntry>(cursor, values)); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<Map<byte[], byte[]>> toMap(EventExecutor executor) { return new PromiseConverter<Map<byte[], byte[]>>(executor) { @Override/*w w w . j av a 2 s. co m*/ public FutureListener<Object> newListener(final Promise<Map<byte[], byte[]>> promise) { return new FutureListener<Object>() { @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else { @SuppressWarnings("unchecked") List<byte[]> rawValueList = (List<byte[]>) resp; Map<byte[], byte[]> values = newBytesKeyMap(); for (Iterator<byte[]> iter = rawValueList.iterator(); iter.hasNext();) { values.put(iter.next(), iter.next()); } promise.trySuccess(values); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<Set<byte[]>> toSet(EventExecutor executor) { return new PromiseConverter<Set<byte[]>>(executor) { @Override//from www .java 2 s . c o m public FutureListener<Object> newListener(final Promise<Set<byte[]>> promise) { return new FutureListener<Object>() { @SuppressWarnings("unchecked") @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else if (resp == RedisResponseDecoder.NULL_REPLY) { promise.trySuccess(null); } else { Set<byte[]> values = newBytesSet(); values.addAll((List<byte[]>) resp); promise.trySuccess(values); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<List<SortedSetEntry>> toSortedSetEntryList(EventExecutor executor) { return new PromiseConverter<List<SortedSetEntry>>(executor) { @Override/*from ww w . ja v a2s . c o m*/ public FutureListener<Object> newListener(final Promise<List<SortedSetEntry>> promise) { return new FutureListener<Object>() { @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else { @SuppressWarnings("unchecked") List<byte[]> rawValueList = (List<byte[]>) resp; List<SortedSetEntry> values = new ArrayList<>(rawValueList.size() / 2); for (Iterator<byte[]> iter = rawValueList.iterator(); iter.hasNext();) { values.add(new SortedSetEntry(iter.next(), bytesToDouble(iter.next()))); } promise.trySuccess(values); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<List<Boolean>> toBooleanList(EventExecutor executor) { return new PromiseConverter<List<Boolean>>(executor) { @Override/*ww w.j ava 2s . com*/ public FutureListener<Object> newListener(final Promise<List<Boolean>> promise) { return new FutureListener<Object>() { @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else if (resp == RedisResponseDecoder.NULL_REPLY) { promise.trySuccess(null); } else { @SuppressWarnings("unchecked") List<Long> rawValueList = (List<Long>) resp; List<Boolean> values = new ArrayList<>(rawValueList.size()); for (long l : rawValueList) { values.add(l != 0L); } promise.trySuccess(values); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<List<Object>> toObjectList(EventExecutor executor) { return new PromiseConverter<List<Object>>(executor) { @Override// w w w . j av a2 s .c o m public FutureListener<Object> newListener(final Promise<List<Object>> promise) { return new FutureListener<Object>() { @SuppressWarnings("unchecked") @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else if (resp == RedisResponseDecoder.NULL_REPLY) { promise.trySuccess(null); } else { promise.trySuccess((List<Object>) resp); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.TestNedis.java
License:Apache License
@Test public void testTimeout() throws InterruptedException { pool = NedisClientPoolBuilder.create().remoteAddress(new InetSocketAddress("127.0.0.1", PORT)).database(1) .build();/*from w ww . ja v a 2s .com*/ NedisClient client = pool.acquire().sync().getNow(); Thread.sleep(1000); assertEquals(1, pool.numPooledConns()); assertEquals(1, pool.numConns()); assertEquals(0L, client.setTimeout(100).sync().getNow().longValue()); Future<?> future = client.blpop(1, toBytes("foo")).await(); assertFalse(future.isSuccess()); assertTrue(future.cause() instanceof ReadTimeoutException); Thread.sleep(1000); assertEquals(0, pool.numPooledConns()); assertEquals(0, pool.numConns()); }