Пример #1
0
  @Override
  public Object call(
      final Method method,
      final Object[] args,
      @Nullable final AsyncMethodCallback callback,
      @Nullable final Amount<Long, Time> connectTimeoutOverride)
      throws Exception {
    try {
      Future<Object> result =
          executorService.submit(
              new Callable<Object>() {
                @Override
                public Object call() throws Exception {
                  try {
                    return invoke(method, args, callback, null, connectTimeoutOverride);
                  } catch (Throwable t) {
                    Throwables.propagateIfInstanceOf(t, Exception.class);
                    throw new RuntimeException(t);
                  }
                }
              });

      try {
        return result.get(timeout.getValue(), timeout.getUnit().getTimeUnit());
      } catch (TimeoutException e) {
        result.cancel(true);
        throw new TTimeoutException(e);
      } catch (ExecutionException e) {
        throw Throwables.propagate(e.getCause());
      }
    } catch (RejectedExecutionException e) {
      throw new TResourceExhaustedException(e);
    }
  }
Пример #2
0
    LogStream(
        LogInterface log,
        ReaderInterface reader,
        Amount<Long, Time> readTimeout,
        Provider<WriterInterface> writerFactory,
        Amount<Long, Time> writeTimeout,
        byte[] noopEntry) {

      this.log = log;

      this.reader = reader;
      this.readTimeout = readTimeout.getValue();
      this.readTimeUnit = readTimeout.getUnit().getTimeUnit();

      this.writerFactory = writerFactory;
      this.writeTimeout = writeTimeout.getValue();
      this.writeTimeUnit = writeTimeout.getUnit().getTimeUnit();

      this.noopEntry = noopEntry;
    }