本文整理匯總了Java中io.netty.util.concurrent.Promise.setSuccess方法的典型用法代碼示例。如果您正苦於以下問題:Java Promise.setSuccess方法的具體用法?Java Promise.setSuccess怎麽用?Java Promise.setSuccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.util.concurrent.Promise
的用法示例。
在下文中一共展示了Promise.setSuccess方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: propagateResponse
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
private synchronized void propagateResponse(Chunk chunk) {
ChunkRequest chunkRequest = chunkRequestMap.get(chunk.getKey());
for (Promise<Chunk> localRequester : chunkRequest.localRequesters) {
localRequester.setSuccess(chunk);
}
for (Map.Entry<Long, Collection<BzzRetrieveReqMessage>> e :
chunkRequest.requesters.entrySet()) {
BzzStoreReqMessage msg = new BzzStoreReqMessage(e.getKey(), chunk.getKey(), chunk.getData());
int counter = requesterCount;
for (BzzRetrieveReqMessage r : e.getValue()) {
r.getPeer().sendMessage(msg);
statOutStoreReq.add(1);
if (--counter < 0) {
break;
}
}
}
}
示例2: channelRead0
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, ResponseWrapper msg) throws Exception {
//找到對應的client請求, 給請求設置promise為true,然後給請求設置值
Promise<ResponseWrapper> responsePromise = RpcClient.getRequestWrapperMap().get(msg.getRequestId());
if (responsePromise != null) {
if (msg.getStatus() == 200) {
responsePromise.setSuccess(msg);
} else {
System.out.println("error: " + msg.getStatus());
//設置錯誤!
}
//設置完畢之後就可以移出map了
RpcClient.getRequestWrapperMap().remove(msg.getRequestId());
} else {
System.out.println("requestWrapper not found");
}
}
示例3: channelRead0
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg)
throws Exception {
Integer streamId =
msg.headers().getInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text());
if (streamId == null) {
System.err.println("HttpResponseHandler unexpected message received: "
+ msg);
return;
}
if (streamId.intValue() == 1) {
// this is the upgrade response message, just ignore it.
return;
}
Promise<FullHttpResponse> promise;
synchronized (this) {
promise = streamId2Promise.get(streamId);
}
if (promise == null) {
System.err.println("Message received for unknown stream id " + streamId);
} else {
// Do stuff with the message (for now just print it)
promise.setSuccess(msg.retain());
}
}
示例4: addAllAsync
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@Override
public Future<Boolean> addAllAsync(final Collection<? extends V> c) {
final Promise<Boolean> promise = newPromise();
if (c.isEmpty()) {
promise.setSuccess(false);
return promise;
}
final int listSize = size();
List<Object> args = new ArrayList<Object>(c.size() + 1);
args.add(getName());
args.addAll(c);
Future<Long> res = commandExecutor.writeAsync(getName(), RPUSH, args.toArray());
res.addListener(new FutureListener<Long>() {
@Override
public void operationComplete(Future<Long> future) throws Exception {
if (future.isSuccess()) {
promise.setSuccess(listSize != future.getNow());
} else {
promise.setFailure(future.cause());
}
}
});
return promise;
}
示例5: getAsync
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public synchronized Future<Chunk> getAsync(Key key) {
Chunk chunk = localStore.get(key);
Promise<Chunk> ret = new DefaultPromise<Chunk>() {};
if (chunk == null) {
// long timeout = 0; // TODO
ChunkRequest chunkRequest = new ChunkRequest();
chunkRequest.localRequesters.add(ret);
chunkRequestMap.put(key, chunkRequest);
startSearch(-1, key, timeout);
} else {
ret.setSuccess(chunk);
}
return ret;
}
示例6: readAllAsync
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public <T, R> Future<Collection<R>> readAllAsync(RedisCommand<T> command, Object ... params) {
final Promise<Collection<R>> mainPromise = connectionManager.newPromise();
Promise<R> promise = new DefaultPromise<R>() {
Queue<R> results = new ConcurrentLinkedQueue<R>();
AtomicInteger counter = new AtomicInteger(connectionManager.getEntries().keySet().size());
@Override
public Promise<R> setSuccess(R result) {
if (result instanceof Collection) {
results.addAll((Collection)result);
} else {
results.add(result);
}
if (counter.decrementAndGet() == 0
&& !mainPromise.isDone()) {
mainPromise.setSuccess(results);
}
return this;
}
@Override
public Promise<R> setFailure(Throwable cause) {
mainPromise.setFailure(cause);
return this;
}
};
for (Integer slot : connectionManager.getEntries().keySet()) {
async(true, slot, null, connectionManager.getCodec(), command, params, promise, 0);
}
return mainPromise;
}
示例7: allAsync
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public <T, R> Future<R> allAsync(boolean readOnlyMode, RedisCommand<T> command, final SlotCallback<T, R> callback, Object ... params) {
final Promise<R> mainPromise = connectionManager.newPromise();
Promise<T> promise = new DefaultPromise<T>() {
AtomicInteger counter = new AtomicInteger(connectionManager.getEntries().keySet().size());
@Override
public Promise<T> setSuccess(T result) {
if (callback != null) {
callback.onSlotResult(result);
}
if (counter.decrementAndGet() == 0) {
if (callback != null) {
mainPromise.setSuccess(callback.onFinish());
} else {
mainPromise.setSuccess(null);
}
}
return this;
}
@Override
public Promise<T> setFailure(Throwable cause) {
mainPromise.setFailure(cause);
return this;
}
};
for (Integer slot : connectionManager.getEntries().keySet()) {
async(readOnlyMode, slot, null, connectionManager.getCodec(), command, params, promise, 0);
}
return mainPromise;
}
示例8: evalAllAsync
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public <T, R> Future<R> evalAllAsync(boolean readOnlyMode, RedisCommand<T> command, final SlotCallback<T, R> callback, String script, List<Object> keys, Object ... params) {
final Promise<R> mainPromise = connectionManager.newPromise();
Promise<T> promise = new DefaultPromise<T>() {
AtomicInteger counter = new AtomicInteger(connectionManager.getEntries().keySet().size());
@Override
public Promise<T> setSuccess(T result) {
callback.onSlotResult(result);
if (counter.decrementAndGet() == 0
&& !mainPromise.isDone()) {
mainPromise.setSuccess(callback.onFinish());
}
return this;
}
@Override
public Promise<T> setFailure(Throwable cause) {
mainPromise.setFailure(cause);
return this;
}
};
List<Object> args = new ArrayList<Object>(2 + keys.size() + params.length);
args.add(script);
args.add(keys.size());
args.addAll(keys);
args.addAll(Arrays.asList(params));
for (Integer slot : connectionManager.getEntries().keySet()) {
async(readOnlyMode, slot, null, connectionManager.getCodec(), command, args.toArray(), promise, 0);
}
return mainPromise;
}
示例9: releaseAndOffer
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
private void releaseAndOffer(K key, Channel channel, Promise<Void> promise) throws Exception {
if (offerChannel(key, channel)) {
channelPoolHandler.channelReleased(key, channel);
promise.setSuccess(null);
} else {
closeAndFail(channel, FULL_EXCEPTION, promise);
}
}
示例10: makeContextAwareFutureListener
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@Test
@SuppressWarnings("deprecation")
public void makeContextAwareFutureListener() {
RequestContext context = createContext();
Promise<String> promise = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
promise.addListener(context.makeContextAware((FutureListener<String>) f -> {
assertCurrentContext(context);
assertDepth(1);
assertThat(f.getNow()).isEqualTo("success");
}));
promise.setSuccess("success");
}
示例11: contextAwareEventExecutor
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@Test
public void contextAwareEventExecutor() throws Exception {
when(channel.eventLoop()).thenReturn(eventLoop);
RequestContext context = createContext();
Set<Integer> callbacksCalled = Collections.newSetFromMap(new ConcurrentHashMap<>());
EventExecutor executor = context.contextAwareEventLoop();
CountDownLatch latch = new CountDownLatch(18);
executor.execute(() -> checkCallback(1, context, callbacksCalled, latch));
executor.schedule(() -> checkCallback(2, context, callbacksCalled, latch), 0, TimeUnit.SECONDS);
executor.schedule(() -> {
checkCallback(2, context, callbacksCalled, latch);
return "success";
}, 0, TimeUnit.SECONDS);
executor.scheduleAtFixedRate(() -> checkCallback(3, context, callbacksCalled, latch), 0, 1000,
TimeUnit.SECONDS);
executor.scheduleWithFixedDelay(() -> checkCallback(4, context, callbacksCalled, latch), 0, 1000,
TimeUnit.SECONDS);
executor.submit(() -> checkCallback(5, context, callbacksCalled, latch));
executor.submit(() -> checkCallback(6, context, callbacksCalled, latch), "success");
executor.submit(() -> {
checkCallback(7, context, callbacksCalled, latch);
return "success";
});
executor.invokeAll(makeTaskList(8, 10, context, callbacksCalled, latch));
executor.invokeAll(makeTaskList(11, 12, context, callbacksCalled, latch), 10000, TimeUnit.SECONDS);
executor.invokeAny(makeTaskList(13, 13, context, callbacksCalled, latch));
executor.invokeAny(makeTaskList(14, 14, context, callbacksCalled, latch), 10000, TimeUnit.SECONDS);
Promise<String> promise = executor.newPromise();
promise.addListener(f -> checkCallback(15, context, callbacksCalled, latch));
promise.setSuccess("success");
executor.newSucceededFuture("success")
.addListener(f -> checkCallback(16, context, callbacksCalled, latch));
executor.newFailedFuture(new IllegalArgumentException())
.addListener(f -> checkCallback(17, context, callbacksCalled, latch));
ProgressivePromise<String> progressivePromise = executor.newProgressivePromise();
progressivePromise.addListener(f -> checkCallback(18, context, callbacksCalled, latch));
progressivePromise.setSuccess("success");
latch.await();
eventLoop.shutdownGracefully().sync();
assertThat(callbacksCalled).containsExactlyElementsOf(IntStream.rangeClosed(1, 18).boxed()::iterator);
}