Example usage for com.google.common.util.concurrent SettableFuture set

List of usage examples for com.google.common.util.concurrent SettableFuture set

Introduction

In this page you can find the example usage for com.google.common.util.concurrent SettableFuture set.

Prototype

@Override
    public boolean set(@Nullable V value) 

Source Link

Usage

From source file:org.eclipse.scada.protocol.iec60870.client.Client.java

protected synchronized void handleOperationComplete(final SettableFuture<Void> result,
        final ChannelFuture future) {
    if (this.connectFuture != result) {
        // this should never happen
        return;//  w  w  w .  j  av  a2  s  . c  om
    }

    this.connectFuture = null;

    try {
        future.get();
        this.channel = future.channel();

        fireConnected();
        result.set(null);
    } catch (final InterruptedException | ExecutionException e) {
        fireDisconnected(e);
        result.setException(e);
    }
}

From source file:io.crate.operation.join.SinglePagePageableTaskIterable.java

@Override
public ListenableFuture<Void> fetchPage(PageInfo pageInfo) throws NoSuchElementException {
    this.pageInfo(pageInfo);

    final SettableFuture<Void> future = SettableFuture.create();
    Futures.addCallback(currentTaskResult.fetch(pageInfo), new FutureCallback<PageableTaskResult>() {
        @Override/*from   ww w  . j  a  v  a  2  s.co m*/
        public void onSuccess(@Nullable PageableTaskResult result) {
            if (result == null) {
                future.setException(new IllegalArgumentException("PageableTaskResult is null"));
            }
            currentTaskResult = result;
            future.set(null);
        }

        @Override
        public void onFailure(Throwable t) {
            future.setException(t);
        }
    });
    return future;
}

From source file:com.microsoft.services.odata.ODataMediaEntityFetcher.java

public ListenableFuture<byte[]> getContent() {

    final SettableFuture<byte[]> result = SettableFuture.create();

    Request request = getResolver().createRequest();
    request.setVerb(HttpVerb.GET);//from w ww.  j  a  va  2  s. c o m
    ODataURL url = request.getUrl();
    url.appendPathComponent("$value");

    ListenableFuture<ODataResponse> future = oDataExecute(request);

    Futures.addCallback(future, new FutureCallback<ODataResponse>() {
        @Override
        public void onSuccess(ODataResponse response) {
            result.set(response.getPayload());
        }

        @Override
        public void onFailure(Throwable t) {
            result.setException(t);
        }
    });
    return result;
}

From source file:co.cask.cdap.common.discovery.AbstractEndpointStrategy.java

@Override
public Discoverable pick(long timeout, TimeUnit timeoutUnit) {
    Discoverable discoverable = pick();//from  w w w  . j a va2  s .  c o  m
    if (discoverable != null) {
        return discoverable;
    }
    final SettableFuture<Discoverable> future = SettableFuture.create();
    Cancellable cancellable = serviceDiscovered.watchChanges(new ServiceDiscovered.ChangeListener() {
        @Override
        public void onChange(ServiceDiscovered serviceDiscovered) {
            // The serviceDiscovered provided is the same as the one in the field, hence ok to just call pick().
            Discoverable discoverable = pick();
            if (discoverable != null) {
                future.set(discoverable);
            }
        }
    }, Threads.SAME_THREAD_EXECUTOR);
    try {
        return future.get(timeout, timeoutUnit);
    } catch (Exception e) {
        return null;
    } finally {
        cancellable.cancel();
    }
}

From source file:io.crate.autocomplete.InformationSchemaDataProvider.java

private ListenableFuture<List<String>> execute(String statement, Object[] args) {
    final SettableFuture<List<String>> result = SettableFuture.create();
    transportAction.get().execute(new SQLRequest(statement, args), new ActionListener<SQLResponse>() {
        @Override//from   w w w . j av  a2 s .  c o  m
        public void onResponse(SQLResponse response) {
            List<String> rows = new ArrayList<>();
            for (Object[] objects : response.rows()) {
                rows.add((String) objects[0]);
            }
            result.set(rows);
        }

        @Override
        public void onFailure(Throwable e) {
            result.setException(e);
        }
    });
    return result;
}

From source file:com.microsoft.filediscovery.datasource.ListItemsDataSource.java

public ListenableFuture<byte[]> getFile(FileItem file) {
    FileClient fileClient = mApplication.getCurrentFileClient(file.getResourceId(), file.getEndpoint());
    final SettableFuture<byte[]> result = SettableFuture.create();
    ListenableFuture<byte[]> future = fileClient.getFile(file.getId(), null);

    Futures.addCallback(future, new FutureCallback<byte[]>() {
        @Override//from   w w w. j  a v a  2 s  . co  m
        public void onFailure(Throwable t) {
            result.setException(t);
        }

        @Override
        public void onSuccess(byte[] payload) {
            result.set(payload);
        }
    });
    return result;
}

From source file:com.yahoo.omid.committable.hbase.HBaseCommitTable.java

@Override
public ListenableFuture<Writer> getWriter() {
    SettableFuture<Writer> f = SettableFuture.<Writer>create();
    try {/*from  w w  w . j a  va  2 s .  c  o m*/
        f.set(new HBaseWriter(hbaseConfig, tableName));
    } catch (IOException ioe) {
        f.setException(ioe);
    }
    return f;
}

From source file:com.yahoo.omid.committable.hbase.HBaseCommitTable.java

@Override
public ListenableFuture<Client> getClient() {
    SettableFuture<Client> f = SettableFuture.<Client>create();
    try {//from www  .  j  a v  a2 s .c o m
        f.set(new HBaseClient(hbaseConfig, tableName));
    } catch (IOException ioe) {
        f.setException(ioe);
    }
    return f;
}

From source file:org.voltdb.CatalogSpecificPlanner.java

public ListenableFuture<AdHocPlannedStmtBatch> plan(String sql, boolean multipart) {
    /*//from   w ww.  j  a va2  s  .  co m
     * If this is multi-part, don't give the planner a partition param AND
     * tell it not to infer whether the plan is single part. Those optimizations
     * are fine for adhoc SQL planned outside a stored proc, but not when those
     * factors have already been determined by the proc.
     */
    final SettableFuture<AdHocPlannedStmtBatch> retval = SettableFuture.create();
    AdHocPlannerWork work = new AdHocPlannerWork(-1, false, 0, 0, "", false, null, //none of the params on this line are used
            sql, Arrays.asList(new String[] { sql }), multipart ? null : 0, m_catalogContext, true, !multipart,
            new AsyncCompilerWorkCompletionHandler() {

                @Override
                public void onCompletion(AsyncCompilerResult result) {
                    retval.set((AdHocPlannedStmtBatch) result);
                }

            });
    m_agent.compileAdHocPlanForProcedure(work);
    return retval;
}

From source file:com.navercorp.nbasearc.gcp.Gateway.java

ListenableFuture<?> unuse(Set<VirtualConnection> vcConcurrentSet) {
    state = UNUSED;/* w  w  w . j a va  2 s . c om*/

    final SettableFuture<?> sf = SettableFuture.create();
    final AtomicInteger closedConCnt = new AtomicInteger(cons.length);
    for (PhysicalConnection con : cons) {
        con.unuse(vcConcurrentSet).addListener(new Runnable() {
            @Override
            public void run() {
                if (closedConCnt.decrementAndGet() == 0) {
                    sf.set(null);
                }
            }
        }, MoreExecutors.directExecutor());
    }

    return sf;
}