本文整理匯總了Java中io.netty.util.concurrent.Promise.trySuccess方法的典型用法代碼示例。如果您正苦於以下問題:Java Promise.trySuccess方法的具體用法?Java Promise.trySuccess怎麽用?Java Promise.trySuccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.util.concurrent.Promise
的用法示例。
在下文中一共展示了Promise.trySuccess方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toBytes
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<byte[]> toBytes(EventExecutor executor) {
return new PromiseConverter<byte[]>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<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 if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess((byte[]) resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例2: toDouble
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Double> toDouble(EventExecutor executor) {
return new PromiseConverter<Double>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Double> 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 {
promise.trySuccess(bytesToDouble((byte[]) resp));
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例3: toLong
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Long> toLong(EventExecutor executor) {
return new PromiseConverter<Long>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Long> 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 {
promise.trySuccess((Long) resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例4: toObject
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Object> toObject(EventExecutor executor) {
return new PromiseConverter<Object>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Object> 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 {
promise.trySuccess(resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例5: toString
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<String> toString(EventExecutor executor) {
return new PromiseConverter<String>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<String> 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 {
promise.trySuccess(resp.toString());
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例6: toVoid
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Void> toVoid(EventExecutor executor) {
return new PromiseConverter<Void>(executor) {
@Override
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());
}
}
};
}
};
}
示例7: notifyConnect
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
private static void notifyConnect(ChannelFuture future, Promise<Channel> promise)
{
if (future.isSuccess()) {
Channel channel = future.channel();
if (!promise.trySuccess(channel)) {
// Promise was completed in the meantime (likely cancelled), just release the channel again
channel.close();
}
}
else {
promise.tryFailure(future.cause());
}
}
示例8: setPromiseResult
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private boolean setPromiseResult(Promise promise, Message.AddressedMessage message) {
final MessagePayload payload = message.getPayloadChecked(MessagePayload.class);
if (payload instanceof ErrorPayload) {
return promise.tryFailure((ErrorPayload) payload);
} else {
return promise.trySuccess(payload);
}
}
示例9: toList
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<List<byte[]>> toList(EventExecutor executor) {
return new PromiseConverter<List<byte[]>>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<List<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 {
promise.trySuccess((List<byte[]>) resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例10: toBoolean
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Boolean> toBoolean(EventExecutor executor) {
return new PromiseConverter<Boolean>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<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(false);
} else if (resp instanceof String) {
promise.trySuccess(true);
} else {
promise.trySuccess(((Long) resp).intValue() != 0);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例11: toArrayScanResult
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<ScanResult<byte[]>> toArrayScanResult(EventExecutor executor) {
return new PromiseConverter<ScanResult<byte[]>>(executor) {
@Override
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());
}
}
};
}
};
}
示例12: toHashScanResult
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<ScanResult<HashEntry>> toHashScanResult(EventExecutor executor) {
return new PromiseConverter<ScanResult<HashEntry>>(executor) {
@Override
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());
}
}
};
}
};
}
示例13: toSortedSetScanResult
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<ScanResult<SortedSetEntry>> toSortedSetScanResult(
EventExecutor executor) {
return new PromiseConverter<ScanResult<SortedSetEntry>>(executor) {
@Override
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());
}
}
};
}
};
}
示例14: toMap
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Map<byte[], byte[]>> toMap(EventExecutor executor) {
return new PromiseConverter<Map<byte[], byte[]>>(executor) {
@Override
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());
}
}
};
}
};
}
示例15: toSet
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Set<byte[]>> toSet(EventExecutor executor) {
return new PromiseConverter<Set<byte[]>>(executor) {
@Override
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());
}
}
};
}
};
}