List of usage examples for com.google.common.util.concurrent SettableFuture create
public static <V> SettableFuture<V> create()
From source file:com.spotify.apollo.concurrent.Util.java
public static <T> ListenableFuture<T> asFuture(CompletionStage<T> stage) { SettableFuture<T> future = SettableFuture.create(); stage.whenComplete((result, throwable) -> { if (throwable != null) { future.setException(throwable); } else {//from ww w . java2 s . c o m future.set(result); } }); return future; }
From source file:org.opendaylight.openflowplugin.openflow.md.queue.TicketImpl.java
/** * default ctor */ public TicketImpl() { future = SettableFuture.create(); }
From source file:com.microsoft.services.orc.http.BaseHttpTransport.java
@Override public ListenableFuture<Response> execute(final Request request) { final SettableFuture<Response> future = SettableFuture.create(); final NetworkRunnable target = createNetworkRunnable(request, future); final NetworkThread networkThread = new NetworkThread(target) { @Override/*from w w w . j ava 2 s. com*/ public void releaseAndStop() { try { target.closeStreamAndConnection(); } catch (Throwable ignored) { } } }; Futures.addCallback(future, new FutureCallback<Response>() { @Override public void onFailure(Throwable t) { networkThread.releaseAndStop(); } @Override public void onSuccess(Response response) { } }); networkThread.start(); return future; }
From source file:com.pingcap.tikv.util.FutureObserver.java
public FutureObserver(Getter<V, T> getter) { this.resultFuture = SettableFuture.create(); this.getter = getter; }
From source file:com.facebook.presto.util.Threads.java
public static boolean isSameThreadExecutor(Executor executor) { requireNonNull(executor, "executor is null"); if (executor.getClass() == GUAVA_SAME_THREAD_EXECUTOR_CLASS) { return true; }//from w w w . j a v a 2 s . c o m final Thread thisThread = Thread.currentThread(); final SettableFuture<Boolean> isSameThreadExecutor = SettableFuture.create(); executor.execute(new Runnable() { @Override public void run() { isSameThreadExecutor.set(thisThread == Thread.currentThread()); } }); try { return Futures.get(isSameThreadExecutor, 10, TimeUnit.SECONDS, Exception.class); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw Throwables.propagate(e); } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:com.intellij.concurrency.AsyncFutureResultImpl.java
public AsyncFutureResultImpl() { myFuture = SettableFuture.create(); }
From source file:com.microsoft.sharepointservices.http.JavaHttpConnection.java
@Override public ListenableFuture<Response> execute(final Request request) { request.addHeader(USER_AGENT_HEADER, Platform.getUserAgent()); final SettableFuture<Response> future = SettableFuture.create(); final NetworkRunnable target = new NetworkRunnable(request, future); final NetworkThread networkThread = new NetworkThread(target) { @Override/*from ww w .jav a 2 s.co m*/ void releaseAndStop() { try { target.closeStreamAndConnection(); } catch (Throwable error) { } } }; Futures.addCallback(future, new FutureCallback<Response>() { @Override public void onFailure(Throwable arg0) { networkThread.releaseAndStop(); } @Override public void onSuccess(Response response) { } }); networkThread.start(); return future; }
From source file:com.google.enterprise.adaptor.sharepoint.AsyncCacheLoader.java
@Override public ListenableFuture<V> reload(final K key, V oldValue) { final SettableFuture<V> future = SettableFuture.create(); executor().execute(new Runnable() { @Override//from www.j a va 2 s . c o m public void run() { try { future.set(load(key)); } catch (Throwable t) { future.setException(t); } } }); return future; }
From source file:com.microsoft.office365.http.SharepointCookieCredentials.java
@SuppressLint("SetJavaScriptEnabled") protected static ListenableFuture<String> showLoginForCookies(Activity activity, final String startUrl) { final SettableFuture<String> codeFuture = SettableFuture.create(); if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); }//from w w w. j a v a 2 s. c o m 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().setUserAgentString("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36"); 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; 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; // CookieSyncManager syncManager = // CookieSyncManager.createInstance(view.getContext()); 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); if (cookie != null && cookie.contains("rtFa")) { return true; } else { return false; } } }); wv.loadUrl(startUrl); dialog.show(); return codeFuture; }
From source file:com.microsoft.azure.storage.DictionaryKeyResolver.java
@Override public ListenableFuture<IKey> resolveKeyAsync(String keyId) { SettableFuture<IKey> future = SettableFuture.create(); future.set(this.keys.get(keyId)); return future; }