List of usage examples for com.google.common.util.concurrent SettableFuture set
@Override public boolean set(@Nullable V value)
From source file:io.crate.blob.v2.BlobAdminClient.java
public ListenableFuture<Void> createBlobTable(String tableName, Settings indexSettings) { Settings.Builder builder = Settings.builder(); builder.put(indexSettings);//from ww w . ja v a 2 s.c o m builder.put(SETTING_INDEX_BLOBS_ENABLED, true); final SettableFuture<Void> result = SettableFuture.create(); createIndexAction.execute(new CreateIndexRequest(fullIndexName(tableName), builder.build()), new ActionListener<CreateIndexResponse>() { @Override public void onResponse(CreateIndexResponse createIndexResponse) { assert createIndexResponse.isAcknowledged() : "createIndexResponse must be acknowledged"; result.set(null); } @Override public void onFailure(Throwable e) { result.setException(e); } }); return result; }
From source file:org.fiware.kiara.transport.http.HttpTransportFactory.java
private ListenableFuture<Transport> openConnection(URI uri, Map<String, Object> settings) throws IOException { String scheme = uri.getScheme() == null ? "http" : uri.getScheme(); String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost(); int port = uri.getPort(); if (port == -1) { if ("http".equalsIgnoreCase(scheme)) { port = 80;//w ww . j a v a 2 s. c o m } else if ("https".equalsIgnoreCase(scheme)) { port = 443; } } if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) { throw new IOException("Only HTTP(S) is supported."); } // Configure SSL context if necessary. final boolean ssl = "https".equalsIgnoreCase(scheme); final SslContext sslCtx; if (ssl) { sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE); } else { sslCtx = null; } // Configure the client. final SettableFuture<Transport> onConnectionActive = SettableFuture.create(); final HttpHandler clientHandler = new HttpHandler(this, uri, HttpMethod.POST, null); clientHandler.setConnectionListener(new TransportConnectionListener() { @Override public void onConnectionOpened(TransportImpl connection) { clientHandler.setConnectionListener(null); onConnectionActive.set(connection); } @Override public void onConnectionClosed(TransportImpl connection) { } }); Bootstrap b = new Bootstrap(); b.group(getEventLoopGroup()).channel(NioSocketChannel.class) .handler(new HttpClientInitializer(sslCtx, clientHandler)); b.connect(host, port); return onConnectionActive; }
From source file:com.microsoft.office365.starter.helpers.Authentication.java
public static SettableFuture<Void> authenticate(final Activity rootActivity, final DefaultDependencyResolver resolver, String resourceId) { final SettableFuture<Void> result = SettableFuture.create(); getAuthenticationContext(rootActivity).acquireToken(rootActivity, resourceId, Constants.CLIENT_ID.trim(), Constants.REDIRECT_URI.trim(), PromptBehavior.Auto, new AuthenticationCallback<AuthenticationResult>() { @Override/* w w w.jav a 2s .c o m*/ public void onSuccess(final AuthenticationResult authenticationResult) { if (authenticationResult != null && !TextUtils.isEmpty(authenticationResult.getAccessToken())) { resolver.setCredentialsFactory(new CredentialsFactory() { @Override public Credentials getCredentials() { return new Credentials() { @Override public void prepareRequest(Request request) { request.addHeader("Authorization", "Bearer " + authenticationResult.getAccessToken()); } }; } }); storeUserId(rootActivity, authenticationResult); result.set(null); } } private void storeUserId(final Activity rootActivity, final AuthenticationResult authenticationResult) { UserInfo ui = authenticationResult.getUserInfo(); SharedPreferences sharedPref = rootActivity.getPreferences(Context.MODE_PRIVATE); if (ui != null) { mLoggedInUser = ui.getUserId(); Editor editor = sharedPref.edit(); editor.putString("UserId", mLoggedInUser); editor.putString("DisplayName", ui.getGivenName() + " " + ui.getFamilyName()); editor.commit(); } else { mLoggedInUser = sharedPref.getString("UserId", ""); } } @Override public void onError(Exception exc) { result.setException(exc); } }); return result; }
From source file:org.apache.qpid.server.security.SiteSpecificTrustStoreImpl.java
private void generateTrustAndSetState(final SettableFuture<Void> result) { State state = State.ERRORED; try {/*from w w w . j a v a 2 s .c o m*/ generateTrustManagers(); state = State.ACTIVE; result.set(null); } catch (IllegalConfigurationException e) { result.setException(e); } finally { setState(state); result.set(null); } }
From source file:com.continuuity.weave.internal.kafka.client.SimpleKafkaClient.java
private <V> ChannelFutureListener getPublishChannelFutureListener(final SettableFuture<V> result, final V resultObj, final ConnectionPool.ConnectionReleaser releaser) { return new ChannelFutureListener() { @Override//from w w w. j av a2 s. c om public void operationComplete(ChannelFuture future) throws Exception { try { if (future.isSuccess()) { result.set(resultObj); } else if (future.isCancelled()) { result.cancel(true); } else { result.setException(future.getCause()); } } finally { releaser.release(); } } }; }
From source file:org.opendaylight.controller.cluster.datastore.SimpleShardDataTreeCohort.java
@Override public ListenableFuture<Void> abort() { dataTree.startAbort(this); state = State.ABORTED;/*from w ww . j a v a 2 s. co m*/ final Optional<Future<Iterable<Object>>> maybeAborts = userCohorts.abort(); if (!maybeAborts.isPresent()) { return VOID_FUTURE; } final Future<Iterable<Object>> aborts = maybeAborts.get(); if (aborts.isCompleted()) { return VOID_FUTURE; } final SettableFuture<Void> ret = SettableFuture.create(); aborts.onComplete(new OnComplete<Iterable<Object>>() { @Override public void onComplete(final Throwable failure, final Iterable<Object> objs) { if (failure != null) { ret.setException(failure); } else { ret.set(null); } } }, ExecutionContexts.global()); return ret; }
From source file:org.neoscoinj.core.TransactionConfidence.java
/** * Returns a future that completes when the transaction has been confirmed by "depth" blocks. For instance setting * depth to one will wait until it appears in a block on the best chain, and zero will wait until it has been seen * on the network./*from ww w. jav a2 s. com*/ */ public synchronized ListenableFuture<TransactionConfidence> getDepthFuture(final int depth, Executor executor) { final SettableFuture<TransactionConfidence> result = SettableFuture.create(); if (getDepthInBlocks() >= depth) { result.set(this); } addEventListener(new Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { if (getDepthInBlocks() >= depth) { removeEventListener(this); result.set(confidence); } } }, executor); return result; }
From source file:com.google.devcoin.core.TransactionConfidence.java
/** * Returns a future that completes when the transaction has been confirmed by "depth" blocks. For instance setting * depth to one will wait until it appears in a block on the best chain, and zero will wait until it has been seen * on the network./*from ww w . j a v a2s . co m*/ */ public synchronized ListenableFuture<Transaction> getDepthFuture(final int depth) { final SettableFuture<Transaction> result = SettableFuture.create(); if (getDepthInBlocks() >= depth) { result.set(transaction); } addEventListener(new Listener() { @Override public void onConfidenceChanged(Transaction tx, ChangeReason reason) { // Runs in user code thread. if (getDepthInBlocks() >= depth) { removeEventListener(this); result.set(transaction); } } }); return result; }
From source file:com.google.reddcoin.core.TransactionConfidence.java
/** * Returns a future that completes when the transaction has been confirmed by "depth" blocks. For instance setting * depth to one will wait until it appears in a block on the best chain, and zero will wait until it has been seen * on the network./*w w w .j av a 2s .c o m*/ */ public synchronized ListenableFuture<Transaction> getDepthFuture(final int depth, Executor executor) { final SettableFuture<Transaction> result = SettableFuture.create(); if (getDepthInBlocks() >= depth) { result.set(transaction); } addEventListener(new Listener() { @Override public void onConfidenceChanged(Transaction tx, ChangeReason reason) { if (getDepthInBlocks() >= depth) { removeEventListener(this); result.set(transaction); } } }, executor); return result; }
From source file:org.opendaylight.openflowjava.protocol.impl.core.UdpHandler.java
@Override public ListenableFuture<Boolean> shutdown() { final SettableFuture<Boolean> result = SettableFuture.create(); group.shutdownGracefully()/*from ww w. j a v a 2s . c o m*/ .addListener(new GenericFutureListener<io.netty.util.concurrent.Future<Object>>() { @Override public void operationComplete(final io.netty.util.concurrent.Future<Object> downResult) throws Exception { result.set(downResult.isSuccess()); if (downResult.cause() != null) { result.setException(downResult.cause()); } } }); return result; }