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


Java Promise.setFailure方法代碼示例

本文整理匯總了Java中io.netty.util.concurrent.Promise.setFailure方法的典型用法代碼示例。如果您正苦於以下問題:Java Promise.setFailure方法的具體用法?Java Promise.setFailure怎麽用?Java Promise.setFailure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.util.concurrent.Promise的用法示例。


在下文中一共展示了Promise.setFailure方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: await

import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public <R> R await(Future<R> cmd) {
    if (!cmd.awaitUninterruptibly(redisClient.getTimeout(), TimeUnit.MILLISECONDS)) {
        Promise<R> promise = (Promise<R>)cmd;
        RedisTimeoutException ex = new RedisTimeoutException();
        promise.setFailure(ex);
        throw ex;
    }
    if (!cmd.isSuccess()) {
        if (cmd.cause() instanceof RedisException) {
            throw (RedisException) cmd.cause();
        }
        throw new RedisException("Unexpected exception while processing command", cmd.cause());
    }
    return cmd.getNow();
}
 
開發者ID:rollenholt-SourceReading,項目名稱:redisson,代碼行數:16,代碼來源:RedisConnection.java

示例2: 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

示例3: 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

示例4: 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

示例5: callMethod

import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
/**
 * Calls method on channel
 * @param method to call
 * @param controller to run call with
 * @param request to send
 * @param responsePrototype to construct response with
 */
public Promise<Message> callMethod(final Descriptors.MethodDescriptor method,
    final PayloadCarryingRpcController controller, final Message request,
    final Message responsePrototype, MetricsConnection.CallStats callStats) {
  final AsyncCall call =
      new AsyncCall(channel.eventLoop(), client.callIdCnt.getAndIncrement(), method, request,
          controller, responsePrototype, callStats);
  controller.notifyOnCancel(new RpcCallback<Object>() {
    @Override
    public void run(Object parameter) {
      // TODO: do not need to call AsyncCall.setFailed?
      synchronized (pendingCalls) {
        pendingCalls.remove(call.id);
      }
    }
  });
  // TODO: this should be handled by PayloadCarryingRpcController.
  if (controller.isCanceled()) {
    // To finish if the call was cancelled before we set the notification (race condition)
    call.cancel(true);
    return call;
  }

  synchronized (pendingCalls) {
    if (closed) {
      Promise<Message> promise = channel.eventLoop().newPromise();
      promise.setFailure(new ConnectException());
      return promise;
    }
    pendingCalls.put(call.id, call);
    // Add timeout for cleanup if none is present
    if (cleanupTimer == null && call.getRpcTimeout() > 0) {
      cleanupTimer =
          client.newTimeout(timeoutTask, call.getRpcTimeout(),
            TimeUnit.MILLISECONDS);
    }
    if (!connected) {
      return call;
    }
  }
  writeRequest(call);
  return call;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:50,代碼來源:AsyncRpcChannel.java

示例6: closeAndFail

import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
private static void closeAndFail(Channel channel, Throwable cause, Promise<?> promise) {
    closeChannel(channel);
    promise.setFailure(cause);
}
 
開發者ID:line,項目名稱:armeria,代碼行數:5,代碼來源:DefaultKeyedChannelPool.java

示例7: exceptionCaught

import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
	 throws Exception {

 LOGGER.error( cause.getLocalizedMessage(), cause);

 AutoFlushWriterChannelQueue queue = m_channelQueue.remove(ctx.channel());

 if (queue == null) return;

 MessageEvent[] events = queue.get();

 if (events == null) return;

 for (int i=0; i < events.length; i++) {

	 MessageEvent ev = events[i];

	 Promise promise = ev.getPromise();

	 if (promise != null)
		 promise.setFailure(cause);

	 ((ByteBuf) ev.getMsg()).release();

 }


 if (queue != null) {
	 queue.clear();

 }

 super.exceptionCaught(ctx, cause);
}
 
開發者ID:pulsarIO,項目名稱:jetstream,代碼行數:36,代碼來源:NettyAutoFlushBatcher.java

示例8: channelInactive

import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {

 AutoFlushWriterChannelQueue queue = m_channelQueue.remove(ctx.channel());

 if (queue == null) {
	 ctx.fireChannelInactive();
	 return;
 }

 MessageEvent[] events = queue.get();

 if (events == null) {
	 ctx.fireChannelInactive();
	 return;
 }

 Throwable cause = new ClosedChannelException();


 for (int i=0; i < events.length; i++) {

	 MessageEvent ev = events[i];

	 Promise promise = ev.getPromise();

	 if (promise != null)
		 promise.setFailure(cause);

	 ((ByteBuf) ev.getMsg()).release();

 }


 if (queue != null) {
	 queue.clear();

 }

 ctx.fireChannelInactive();
}
 
開發者ID:pulsarIO,項目名稱:jetstream,代碼行數:42,代碼來源:NettyAutoFlushBatcher.java


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