本文整理汇总了Java中com.google.common.util.concurrent.SettableFuture.setException方法的典型用法代码示例。如果您正苦于以下问题:Java SettableFuture.setException方法的具体用法?Java SettableFuture.setException怎么用?Java SettableFuture.setException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.SettableFuture
的用法示例。
在下文中一共展示了SettableFuture.setException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleOperationComplete
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
protected synchronized void handleOperationComplete ( final SettableFuture<Void> result, final ChannelFuture future )
{
if ( this.connectFuture != result )
{
// this should never happen
return;
}
this.connectFuture = null;
try
{
future.get ();
this.channel = future.channel ();
fireConnected ( this.channel );
result.set ( null );
}
catch ( final InterruptedException | ExecutionException e )
{
fireDisconnected ( e );
result.setException ( e );
}
}
示例2: run
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public void run() {
requestSemaphore.acquireUninterruptibly();
try {
currentBatch.getAndUpdate(batch -> (batch == this) ? null : batch); //Removing this batch from current
Map<MetricDir, DirContent> dirsContent = metricSearch.loadDirsContent(requests.keySet());
for (Map.Entry<MetricDir, DirContent> dirDirContentEntry : dirsContent.entrySet()) {
requests.remove(dirDirContentEntry.getKey()).set(dirDirContentEntry.getValue());
}
if (!requests.isEmpty()) {
log.error(requests.size() + " requests without data for dirs: " + requests.entrySet());
throw new IllegalStateException("No data for dirs");
}
} catch (Exception e) {
log.error("Failed to load content for dirs: " + requests.keySet(), e);
for (SettableFuture<DirContent> settableFuture : requests.values()) {
settableFuture.setException(e);
}
} finally {
requestSemaphore.release();
}
}
示例3: getNodeData
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected <M extends Message> ListenableFuture<M> getNodeData(
WatchCallback watcher, String path, Message.Builder builder) {
final SettableFuture<M> future = SettableFuture.create();
byte[] data = new byte[]{};
if (FileUtils.isFileExists(path)) {
data = FileUtils.readFromFile(path);
}
if (data.length == 0) {
future.set(null);
return future;
}
try {
builder.mergeFrom(data);
future.set((M) builder.build());
} catch (InvalidProtocolBufferException e) {
future.setException(new RuntimeException("Could not parse " + Message.Builder.class, e));
}
return future;
}
示例4: setException
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
private void setException(SettableFuture<Long> result, Throwable e, CreateTableAnalyzedStatement statement) {
e = Exceptions.unwrap(e);
String message = e.getMessage();
// sometimes message is empty
if ("mapping [default]".equals(message) && e.getCause() != null) {
// this is a generic mapping parse exception,
// the cause has usually a better more detailed error message
result.setException(e.getCause());
} else if (statement.ifNotExists() &&
(e instanceof IndexAlreadyExistsException
|| (e instanceof IndexTemplateAlreadyExistsException && statement.templateName() != null))) {
result.set(null);
} else {
result.setException(e);
}
}
示例5: start
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public void start() {
FluentIterable<NodeOperation> nodeOperations = FluentIterable.from(nodeOperationTrees)
.transformAndConcat(new Function<NodeOperationTree, Iterable<? extends NodeOperation>>() {
@Nullable
@Override
public Iterable<? extends NodeOperation> apply(NodeOperationTree input) {
return input.nodeOperations();
}
});
Map<String, Collection<NodeOperation>> operationByServer = NodeOperationGrouper.groupByServer(nodeOperations);
InitializationTracker initializationTracker = new InitializationTracker(operationByServer.size());
List<Tuple<ExecutionPhase, RowReceiver>> handlerPhases = createHandlerPhases(initializationTracker);
try {
setupContext(operationByServer, handlerPhases, initializationTracker);
} catch (Throwable throwable) {
for (SettableFuture<TaskResult> result : results) {
result.setException(throwable);
}
}
}
示例6: innerClose
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
protected void innerClose(@Nullable Throwable t) {
if (t != null) {
for (SettableFuture<TaskResult> resultFuture : resultFutures) {
if (!resultFuture.isDone()) {
resultFuture.setException(t);
}
}
}
}
示例7: executeUpsertRequest
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
private void executeUpsertRequest(final UpsertByIdNode.Item item, final SettableFuture<TaskResult> futureResult) {
ShardId shardId;
try {
shardId = clusterService.operationRouting().indexShards(
clusterService.state(),
item.index(),
Constants.DEFAULT_MAPPING_TYPE,
item.id(),
item.routing()
).shardId();
} catch (IndexNotFoundException e) {
if (PartitionName.isPartition(item.index())) {
futureResult.set(TaskResult.ZERO);
return;
}
throw e;
}
ShardUpsertRequest upsertRequest = new ShardUpsertRequest(
shardId, node.updateColumns(), node.insertColumns(), item.routing(), jobId());
upsertRequest.continueOnError(false);
ShardUpsertRequest.Item requestItem = new ShardUpsertRequest.Item(
item.id(), item.updateAssignments(), item.insertValues(), item.version());
upsertRequest.add(0, requestItem);
UpsertByIdContext upsertByIdContext = new UpsertByIdContext(
node.executionPhaseId(), upsertRequest, item, futureResult, transportShardUpsertActionDelegate);
createJobExecutionContext(upsertByIdContext);
try {
jobExecutionContext.start();
} catch (Throwable throwable) {
futureResult.setException(throwable);
}
}
示例8: executeRead
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public <T> void executeRead(AbstractRead<T> readCmd, SettableFuture<T> proxyFuture) {
LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(),
readCmd.getPath());
final Throwable t;
if (failure instanceof NoShardLeaderException) {
t = new DataStoreUnavailableException(failure.getMessage(), failure);
} else {
t = failure;
}
proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName()
+ " for path " + readCmd.getPath(), t));
}
示例9: executeRead
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> returnFuture) {
LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(),
readCmd.getPath());
// Send any batched modifications. This is necessary to honor the read uncommitted semantics of the
// public API contract.
acquireOperation();
sendBatchedModifications();
OnComplete<Object> onComplete = new OnComplete<Object>() {
@Override
public void onComplete(Throwable failure, Object response) throws Throwable {
if (failure != null) {
LOG.debug("Tx {} {} operation failed: {}", getIdentifier(), readCmd.getClass().getSimpleName(),
failure);
returnFuture.setException(new ReadFailedException("Error checking "
+ readCmd.getClass().getSimpleName() + " for path " + readCmd.getPath(), failure));
} else {
LOG.debug("Tx {} {} operation succeeded", getIdentifier(), readCmd.getClass().getSimpleName());
readCmd.processResponse(response, returnFuture);
}
}
};
Future<Object> future = executeOperationAsync(readCmd.asVersion(getTransactionVersion()),
actorContext.getOperationTimeout());
future.onComplete(onComplete, actorContext.getClientDispatcher());
}
示例10: processResponse
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public void processResponse(Object readResponse, SettableFuture<Optional<NormalizedNode<?, ?>>> returnFuture) {
if (ReadDataReply.isSerializedType(readResponse)) {
ReadDataReply reply = ReadDataReply.fromSerializable(readResponse);
returnFuture.set(Optional.<NormalizedNode<?, ?>>fromNullable(reply.getNormalizedNode()));
} else {
returnFuture.setException(new ReadFailedException("Invalid response reading data for path " + getPath()));
}
}
示例11: processResponse
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public void processResponse(Object response, SettableFuture<Boolean> returnFuture) {
if (DataExistsReply.isSerializedType(response)) {
returnFuture.set(Boolean.valueOf(DataExistsReply.fromSerializable(response).exists()));
} else {
returnFuture.setException(new ReadFailedException("Invalid response checking exists for path "
+ getPath()));
}
}
示例12: testFireOnceMajorityFailed1
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void testFireOnceMajorityFailed1() {
SettableFuture<Boolean> f1 = SettableFuture.create();
SettableFuture<Boolean> f2 = SettableFuture.create();
List<ListenableFuture<Boolean>> responses = Lists.newArrayList(f1, f2, Futures.<Boolean> immediateFuture(Boolean.TRUE));
ListenableFuture<Boolean> collector = majorityResponse(responses, Identity);
f1.setException(new Exception());
assertFalse(collector.isDone());
f2.setException(new Exception());
assertTrue(collector.isDone());
assertFalse(Futures.getUnchecked(collector));
}
示例13: testFireOnceMajorityFailed
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void testFireOnceMajorityFailed() {
SettableFuture<Boolean> f1 = SettableFuture.create();
SettableFuture<Boolean> f2 = SettableFuture.create();
SettableFuture<Boolean> f3 = SettableFuture.create();
List<ListenableFuture<Boolean>> responses = Lists.newArrayList(f1, f2, f3, Futures.<Boolean> immediateFuture(Boolean.TRUE));
ListenableFuture<Boolean> collector = majorityResponse(responses, Identity);
f1.setException(new Exception());
assertFalse(collector.isDone());
f2.setException(new Exception());
assertFalse(collector.isDone());
f3.set(Boolean.TRUE);
assertTrue(collector.isDone());
assertTrue(Futures.getUnchecked(collector));
}
示例14: sendRequest
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public <T extends ApiResponse> ListenableFuture<T> sendRequest( final ApiVersion version, final String path, final Class<T> expectedType ) {
final SettableFuture<T> apiResponseFuture = SettableFuture.create( );
try {
final ApiRequest request = ApiRequestBuilder.newRequest( )
.to( _configuration.getServerUrl( ) )
.forUser( _configuration.getCredentialsUser( ) )
.withPassword( _configuration.getCredentialsPassword( ) )
.request( path )
.apiVersion( version )
.build( );
LOGGER.info( "<< REQUEST: to {}", request );
final AsyncHttpClient.BoundRequestBuilder httpRequest = _httpClient
.prepareGet( request.getURI( ) )
.addHeader( HttpHeaders.ACCEPT, "application/json" );
if ( !request.isGuestMode( ) ) {
final Realm realm = new Realm.RealmBuilder( )
.setPrincipal( request.getUsername( ) )
.setPassword( request.getPassword( ) )
.setUsePreemptiveAuth( true )
.setScheme( Realm.AuthScheme.BASIC )
.build( );
httpRequest.setRealm( realm );
}
if ( _configuration.isUseProxy( ) ) {
// CODEREVIEW Let the user choose the protocol ?
final ProxyServer proxyServer = new ProxyServer( ProxyServer.Protocol.HTTP, checkNotNull( _configuration.getProxyHost( ), "Proxy hostname is not defined" ), _configuration.getProxyPort( ), _configuration.getProxyCredentialsUser( ), _configuration.getProxyCredentialsPassword( ) );
httpRequest.setProxyServer( proxyServer );
}
httpRequest.execute( new AsyncCompletionHandler<Void>( ) {
@Override
public void onThrowable( final Throwable t ) {
super.onThrowable( t );
apiResponseFuture.setException( t );
}
@Override
public Void onCompleted( final Response response ) throws Exception {
if ( response.getStatusCode( ) != 200 ) {
LOGGER.error( ">> RESPONSE: for {} has status code {}", request, response.getStatusCode( ) );
apiResponseFuture.setException( new ApiException( "Http status code is " + response.getStatusCode( ) + " when requesting uri: " + response.getUri( ) ) );
return null;
}
final String content = response.getResponseBody( Charsets.UTF_8.name( ) );
LOGGER.debug( ">> RESPONSE: for {} has content: {}", request, content );
final Gson gson = new GsonBuilder( ).create( );
final T jsonResponse = gson.fromJson( content, expectedType );
apiResponseFuture.set( jsonResponse );
return null;
}
} );
} catch ( Exception e ) {
apiResponseFuture.setException( e );
}
return apiResponseFuture;
}
示例15: testOptimisticAdoptPostResolveFailure
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
/**
* Test the completion and callback invocation of {@link RedFutureHub}
* optimistic union of adopted futures that later were failed
*/
@Test
public void testOptimisticAdoptPostResolveFailure() throws Throwable {
AtomicBoolean reachedSuccessBlock = new AtomicBoolean(false);
AtomicBoolean reachedFailureBlock = new AtomicBoolean(false);
AtomicBoolean reachedFinallyBlock = new AtomicBoolean(false);
RedFutureHub hub = RedFuture.hub();
OpenRedFuture future1 = RedFuture.future();
OpenRedFuture future2 = RedFuture.future();
OpenRedFuture future3 = RedFuture.future();
OpenRedFutureOf<Object> futureOf1 = hub.provideFutureOf();
OpenRedFutureOf<Object> futureOf2 = hub.provideFutureOf();
SettableFuture<Object> settableFuture1 = SettableFuture.create();
SettableFuture<Object> settableFuture2 = SettableFuture.create();
SettableFuture<Object> settableFuture3 = SettableFuture.create();
SettableFuture<Object> settableFuture4 = SettableFuture.create();
SettableFuture<Object> settableFuture5 = SettableFuture.create();
List<RedFuture> redFutureCollection = new LinkedList<>();
redFutureCollection.add(future2);
redFutureCollection.add(futureOf1);
List<ListenableFuture> listenableFutureCollection = new LinkedList<>();
listenableFutureCollection.add(settableFuture1);
listenableFutureCollection.add(settableFuture2);
hub.adoptFuture(future1);
hub.adoptFutures(redFutureCollection);
hub.adoptFutures(future3, futureOf2);
hub.adoptListenableFuture(settableFuture3);
hub.adoptListenableFutures(listenableFutureCollection);
hub.adoptListenableFutures(settableFuture4, settableFuture5);
RedFuture union = hub.uniteOptimistically();
union.addSuccessCallback(() -> reachedSuccessBlock.set(true));
union.addFailureCallback(throwable -> reachedFailureBlock.set(true));
union.addFinallyCallback(() -> reachedFinallyBlock.set(true));
Assert.assertFalse(reachedFinallyBlock.get());
Assert.assertFalse(reachedSuccessBlock.get());
Assert.assertFalse(reachedFailureBlock.get());
settableFuture1.setException(new TestException());
Assert.assertTrue(reachedFinallyBlock.get());
Assert.assertFalse(reachedSuccessBlock.get());
Assert.assertTrue(reachedFailureBlock.get());
}