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

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

Introduction

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

Prototype

public static <V> SettableFuture<V> create() 

Source Link

Document

Creates a new SettableFuture that can be completed or cancelled by a later method call.

Usage

From source file:fi.jumi.core.ipc.IpcCommandSender.java

public Future<Path> runTests(SuiteConfiguration suiteConfiguration) {
    SettableFuture<Path> future = SettableFuture.create();
    handlersForExpectedResponses.add(new ResponseListener() {
        @Override//  w w w  .j  a v a 2  s. c o  m
        public void onSuiteStarted(Path suiteResults) {
            future.set(suiteResults);
        }
    });
    requestSender.runTests(suiteConfiguration);
    return future;
}

From source file:org.apache.drill.exec.rpc.bit.FutureBitCommand.java

public FutureBitCommand() {
    this.settableFuture = SettableFuture.create();
    this.parentFuture = new RpcCheckedFuture<T>(settableFuture);
}

From source file:org.apache.druid.indexing.overlord.RemoteTaskRunnerWorkItem.java

public RemoteTaskRunnerWorkItem(String taskId, String taskType, Worker worker, TaskLocation location,
        String dataSource) {//  ww w  . j a v  a 2s . com
    this(taskId, taskType, SettableFuture.create(), worker, location, dataSource);
}

From source file:com.continuuity.loom.common.zookeeper.ZKClientExt.java

/**
 * Acts as {@link ZKClient#create(String, byte[], org.apache.zookeeper.CreateMode, boolean)} if node does not exist,
 * otherwise as {@link ZKClient#setData(String, byte[])}.
 *///from   ww w  .  java2  s  . c o m
public static ListenableFuture<SetResult> createOrSet(final ZKClient zkClient, final String path,
        @Nullable final byte[] data, final CreateMode createMode, final boolean createParent) {
    final SettableFuture<SetResult> resultFuture = SettableFuture.create();

    final OperationFuture<String> createResult = zkClient.create(path, data, createMode, createParent);
    Futures.addCallback(createResult, new FutureCallback<String>() {
        private final FutureCallback<String> createCallback = this;

        @Override
        public void onSuccess(String result) {
            resultFuture.set(new SetResult(result, null));
        }

        @Override
        public void onFailure(Throwable t) {
            if (causedBy(t, KeeperException.NodeExistsException.class)) {
                OperationFuture<Stat> setDataResult = zkClient.setData(path, data);
                Futures.addCallback(setDataResult, new FutureCallback<Stat>() {
                    @Override
                    public void onSuccess(Stat result) {
                        resultFuture.set(new SetResult(null, result));
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        if (causedBy(t, KeeperException.NoNodeException.class)) {
                            Futures.addCallback(zkClient.create(path, data, createMode, createParent),
                                    createCallback);
                            return;
                        }
                        resultFuture.setException(t);
                    }
                });
                return;
            }
            resultFuture.setException(t);
        }
    });

    return resultFuture;
}

From source file:org.glowroot.central.util.MoreFutures.java

public static <V> ListenableFuture<V> onFailure(ListenableFuture<V> future, Runnable onFailure) {
    SettableFuture<V> outerFuture = SettableFuture.create();
    Futures.addCallback(future, new FutureCallback<V>() {
        @Override// w w  w . j  ava 2s . co  m
        public void onSuccess(V result) {
            outerFuture.set(result);
        }

        @Override
        public void onFailure(Throwable t) {
            logger.debug(t.getMessage(), t);
            onFailure.run();
            outerFuture.setException(t);
        }
    }, MoreExecutors.directExecutor());
    return outerFuture;
}

From source file:org.eclipse.che.plugin.nodejsdbg.server.command.NodeJsDebugCommandImpl.java

public NodeJsDebugCommandImpl(NodeJsOutputParser<T> parser, String input) {
    this.parser = parser;
    this.input = input;
    this.result = SettableFuture.create();
}

From source file:com.microsoft.sharepointservices.http.SharepointCookieCredentials.java

/**
 * Show login for cookies./*from  w  w  w  .  j a  va 2  s .  co m*/
 *
 * @param activity the activity
 * @param startUrl the start url
 * @return the listenable future
 */
@SuppressLint("SetJavaScriptEnabled")
protected static ListenableFuture<String> showLoginForCookies(Activity activity, final String startUrl) {

    final SettableFuture<String> codeFuture = SettableFuture.create();
    if (startUrl == null || startUrl.equals("")) {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (activity == null) {
        throw new IllegalArgumentException("activity can not be null");
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    // Create the Web View to show the login page
    final WebView wv = new WebView(activity);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            codeFuture.setException(new Exception("User cancelled"));
        }
    });

    wv.getSettings().setJavaScriptEnabled(true);

    wv.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    wv.getSettings().setLoadWithOverviewMode(true);
    wv.getSettings().setUseWideViewPort(true);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int webViewHeight = displaymetrics.heightPixels;

    wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight));

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(activity);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(activity);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        boolean mResultReturned = false;
        final Object mSync = new Object();

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            synchronized (mSync) {
                // If the URL of the started page matches with the final URL
                // format, the login process finished
                if (cookieWasFound(view) && !mResultReturned) {
                    mResultReturned = true;

                    CookieManager cookieManager = CookieManager.getInstance();
                    String cookie = cookieManager.getCookie(url);
                    dialog.dismiss();
                    codeFuture.set(cookie);
                }

                super.onPageStarted(view, url, favicon);
            }
        }

        private boolean cookieWasFound(WebView view) {
            CookieManager cookieManager = CookieManager.getInstance();
            String cookie = cookieManager.getCookie(startUrl);
            return cookie != null && cookie.contains("rtFa");
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();

    return codeFuture;
}

From source file:io.radiowitness.kinesis.consumer.KinesisRecordConsumerFactory.java

protected KinesisRecordConsumerFactory() {
    errorFuture = SettableFuture.create();
}

From source file:org.opendaylight.ocpjava.protocol.impl.clients.SimpleClient.java

private void init() {
    isOnlineFuture = SettableFuture.create();
    scenarioDone = SettableFuture.create();
}

From source file:com.facebook.presto.hive.util.AsyncRecursiveWalker.java

public ListenableFuture<Void> beginWalk(Path path, FileStatusCallback callback) {
    SettableFuture<Void> settableFuture = SettableFuture.create();
    recursiveWalk(path, callback, new AtomicLong(), settableFuture);
    return settableFuture;
}