Guava SettableFuture - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava SettableFuture class.

This code example shows how to use the following methods:set
    } 
 
    try { 
     if (Command.isEndOfSequence(sequence, message.toLowerCase())) {
       // Once we see the OK message, we should process the data and return. 
       valueFuture.set(command.extract(value));
       return true; 
      } 
    } 
    catch(ExtractionException ee) {
      valueFuture.setException(ee);
      return true; 
    } 
 
    return false; 
  } 
 
  @Override public String toString() {
    return commandString;
  } 
5
CodeRank
This code example shows how to use the following methods:isDone, set
        count++;
    } 
 
    public synchronized void release() 
    { 
        checkState(!freeFuture.isDone(), "Reference has already been freed");
        count--;
        if (count == 0) {
            freeFuture.set(null);
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:isDone, set
        SettableFuture<?> future;
        synchronized (this) {
            bufferedBytes.addAndGet(bytesAdded);
 
            // if we are full, then breakout 
            if (bufferedBytes.get() > maxBufferedBytes || notFullFuture.isDone()) {
                return; 
            } 
 
            // otherwise, we are not full, so complete the future 
            future = notFullFuture;
            notFullFuture = NOT_FULL;
        } 
 
        // complete future outside of lock since this can invoke callbacks 
        future.set(null);
    } 
 
    public synchronized ListenableFuture<?> getNotFullFuture()
    { 
        // if we are full and still blocking and the current not full future is already complete, create a new one 
5
CodeRank
This code example shows how to use the following methods:get, isDone
            // wait for the thread to be started 
            assertTrue(started.await(1, TimeUnit.SECONDS));
 
            // sleep for a bit, and assure the thread is blocked 
            TimeUnit.MILLISECONDS.sleep(200);
            assertTrue(!splits.isDone());
 
            // add a split 
            hiveSplitSource.addToQueue(new TestSplit(33));
 
            // wait for thread to get the split 
            ConnectorSplit split = splits.get(200, TimeUnit.MILLISECONDS);
            assertSame(split.getInfo(), 33);
        } 
        finally { 
            // make sure the thread exits 
            getterThread.interrupt();
        } 
    } 
 
5
CodeRank
This code example shows how to use the following methods:set
        this.future = future;
    } 
 
    @Override 
    public void onSuccess(R result) {
        future.set(result);
    } 
 
    @Override 
    public void onFailure(Throwable throwable) {
        future.setException(throwable);
    } 
 
    public SettableFuture<R> getFuture() {
        return future;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:setException
        final Object tag = request.tag(); 
        checkState(tag != null, "saw a request with null tag");
 
        final SettableFuture<Void> future = inFlight.remove(tag);
        checkState(future != null, "Saw tag %s but not in in flight map", tag);
        future.setException(e);
 
        LOG.warn("While running %s %s: %s", request.method(), request.urlString(), e.getMessage());
    } 
 
    @Override 
    public void onResponse(final Response response) throws IOException
    { 
        final Object tag = response.request().tag(); 
        checkState(tag != null, "saw a request with null tag");
 
        final SettableFuture<Void> future = inFlight.remove(tag);
        checkState(future != null, "Saw tag %s but not in in flight map", tag);
        future.set(null);
 
3
CodeRank
This code example shows how to use the following methods:setException
            } 
        } 
 
        @Override 
        public void onFailure(Throwable e) {
            result.setException(e);
        } 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:setException
    } 
 
    @Override 
    public void upstreamFailed(Throwable throwable) {
        if (upstreamsRemaining.decrementAndGet() <= 0) {
            result.setException(throwable);
        } 
    } 
 
    @Override 
    public ListenableFuture<Object[][]> result() {
        return result; 
    } 
 
    @Override 
    public Iterator<Object[]> iterator() throws IllegalStateException {
        if (!result.isDone()) { 
            throw new IllegalStateException("result not ready yet");
        } 
        return rows.iterator(); 
4
CodeRank
This code example shows how to use the following methods:set
     * Return a page from the buffer, or null if none exists 
     */ 
    public synchronized Page poll()
    { 
        if (settableFuture != null) {
            settableFuture.set(null);
            settableFuture = null;
        } 
        return pages.poll();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:isCancelled
    return myFuture.cancel(mayInterruptIfRunning);
  } 
 
  @Override 
  public boolean isCancelled() { 
    return myFuture.isCancelled();
  } 
 
  @Override 
  public boolean isDone() { 
    return myFuture.isDone();
  } 
 
  @Override 
  public V get() throws InterruptedException, ExecutionException {
    return myFuture.get();
  } 
 
  @Override 
  public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
4
CodeRank
See Code Examples for Guava SettableFuture Methods: