當前位置: 首頁>>代碼示例>>Java>>正文


Java Promise.setSuccess方法代碼示例

本文整理匯總了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;
            }
        }
    }
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:21,代碼來源:NetStore.java

示例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");
    }
}
 
開發者ID:recklessMo,項目名稱:nettyRpc,代碼行數:18,代碼來源:BusinessClientHandler.java

示例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());

  }
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:27,代碼來源:Http2ResponseHandler.java

示例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;
}
 
開發者ID:rollenholt-SourceReading,項目名稱:redisson,代碼行數:25,代碼來源:RedissonList.java

示例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;
    }
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:15,代碼來源:NetStore.java

示例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;
}
 
開發者ID:rollenholt-SourceReading,項目名稱:redisson,代碼行數:34,代碼來源:CommandExecutorService.java

示例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;
}
 
開發者ID:rollenholt-SourceReading,項目名稱:redisson,代碼行數:31,代碼來源:CommandExecutorService.java

示例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;
}
 
開發者ID:rollenholt-SourceReading,項目名稱:redisson,代碼行數:32,代碼來源:CommandExecutorService.java

示例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);
    }
}
 
開發者ID:line,項目名稱:armeria,代碼行數:9,代碼來源:DefaultKeyedChannelPool.java

示例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");
}
 
開發者ID:line,項目名稱:armeria,代碼行數:13,代碼來源:RequestContextTest.java

示例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);
}
 
開發者ID:line,項目名稱:armeria,代碼行數:42,代碼來源:RequestContextTest.java


注:本文中的io.netty.util.concurrent.Promise.setSuccess方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。