当前位置: 首页>>代码示例>>Java>>正文


Java Futures.addCallback方法代码示例

本文整理汇总了Java中com.google.common.util.concurrent.Futures.addCallback方法的典型用法代码示例。如果您正苦于以下问题:Java Futures.addCallback方法的具体用法?Java Futures.addCallback怎么用?Java Futures.addCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.util.concurrent.Futures的用法示例。


在下文中一共展示了Futures.addCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<Boolean> validate() {
    LOG.debug("Validating transaction for shard {}", shardRoot);

    checkTransactionReadied();
    final List<ListenableFuture<Boolean>> futures =
            cohorts.stream().map(DOMStoreThreePhaseCommitCohort::canCommit).collect(Collectors.toList());
    final SettableFuture<Boolean> ret = SettableFuture.create();

    Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<Boolean>>() {
        @Override
        public void onSuccess(final List<Boolean> result) {
            ret.set(true);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            ret.setException(throwable);
        }
    }, MoreExecutors.directExecutor());

    return ret;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:ShardProxyTransaction.java

示例2: sendRequests

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@VisibleForTesting
List<ListenableFuture<RequestVoteResponse>> sendRequests(final RaftStateContext ctx) {

    RequestVote request = RequestVote.newBuilder().setTerm(log.currentTerm()).setCandidateId(log.self().toString()).setLastLogIndex(log.lastLogIndex()).setLastLogTerm(log.lastLogTerm()).build();

    List<ListenableFuture<RequestVoteResponse>> responses = Lists.newArrayList();
    for (Replica replica : log.members()) {
        ListenableFuture<RequestVoteResponse> response = client.requestVote(replica, request);
        Futures.addCallback(response, new FutureCallback<RequestVoteResponse>() {
            @Override
            public void onSuccess(@Nullable RequestVoteResponse result) {
                checkTermOnResponse(ctx, result);
            }

            @Override
            public void onFailure(Throwable t) {
            }
        });
        responses.add(response);
    }

    return responses;
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:24,代码来源:Candidate.java

示例3: create

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
static <KEY, RESULT> QuorumCall<KEY, RESULT> create(
    Map<KEY, ? extends ListenableFuture<RESULT>> calls) {
  final QuorumCall<KEY, RESULT> qr = new QuorumCall<KEY, RESULT>();
  for (final Entry<KEY, ? extends ListenableFuture<RESULT>> e : calls.entrySet()) {
    Preconditions.checkArgument(e.getValue() != null,
        "null future for key: " + e.getKey());
    Futures.addCallback(e.getValue(), new FutureCallback<RESULT>() {
      @Override
      public void onFailure(Throwable t) {
        qr.addException(e.getKey(), t);
      }

      @Override
      public void onSuccess(RESULT res) {
        qr.addResult(e.getKey(), res);
      }
    });
  }
  return qr;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:QuorumCall.java

示例4: prepare

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<Void> prepare() {
    LOG.debug("Preparing transaction for shard {}", shardRoot);

    checkTransactionReadied();
    final List<ListenableFuture<Void>> futures =
            cohorts.stream().map(DOMStoreThreePhaseCommitCohort::preCommit).collect(Collectors.toList());
    final SettableFuture<Void> ret = SettableFuture.create();

    Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<Void>>() {
        @Override
        public void onSuccess(final List<Void> result) {
            ret.set(null);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            ret.setException(throwable);
        }
    }, MoreExecutors.directExecutor());

    return ret;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:ShardProxyTransaction.java

示例5: load

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public String load(final Object o) throws Exception {

    ListenableFuture<String> future = lex.submit(() -> {
        String result = toolTipsGenerator.getToolTipText(o);

        getCache().invalidate(o);
        getCache().put(o, result);

        return result;
    });
    Futures.addCallback(future, this);

    return Labels.LOADING;
}
 
开发者ID:CLARIN-PL,项目名称:WordnetLoom,代码行数:16,代码来源:ToolTipList.java

示例6: onLoadKey

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
default void onLoadKey(Runnable runnable) {
    Futures.addCallback(getMasterPassword(), new FutureCallback<String>() {
        @Override
        public void onSuccess(@Nullable String result) {
            runnable.run();
        }

        @Override
        public void onFailure(Throwable t) {
            LOGGER.error("failed to run callback " + runnable.toString() + " due to unexpected error while waiting for keyfile: ", t);
        }
    });
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:14,代码来源:EncyptionKeyProvider.java

示例7: put

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public void put(Collection<SinkRecord> sinkRecords) {

	// If KinesisProducers cannot write to Kinesis Streams (because of
	// connectivity issues, access issues
	// or misconfigured shards we will pause consumption of messages till
	// backlog is cleared

	validateOutStandingRecords();

	String partitionKey;
	for (SinkRecord sinkRecord : sinkRecords) {

		ListenableFuture<UserRecordResult> f;
		// Kinesis does not allow empty partition key
		if (sinkRecord.key() != null && !sinkRecord.key().toString().trim().equals("")) {
			partitionKey = sinkRecord.key().toString().trim();
		} else {
			partitionKey = Integer.toString(sinkRecord.kafkaPartition());
		}

		if (singleKinesisProducerPerPartition)
			f = addUserRecord(producerMap.get(sinkRecord.kafkaPartition() + "@" + sinkRecord.topic()), streamName,
					partitionKey, usePartitionAsHashKey, sinkRecord);
		else
			f = addUserRecord(kinesisProducer, streamName, partitionKey, usePartitionAsHashKey, sinkRecord);

		Futures.addCallback(f, callback);

	}
}
 
开发者ID:awslabs,项目名称:kinesis-kafka-connector,代码行数:32,代码来源:AmazonKinesisSinkTask.java

示例8: JobCollectContext

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public JobCollectContext(final CollectPhase collectPhase,
                         MapSideDataCollectOperation collectOperation,
                         String localNodeId,
                         RamAccountingContext queryPhaseRamAccountingContext,
                         final RowReceiver rowReceiver,
                         SharedShardContexts sharedShardContexts) {
    super(collectPhase.executionPhaseId(), LOGGER);
    this.collectPhase = collectPhase;
    this.collectOperation = collectOperation;
    this.queryPhaseRamAccountingContext = queryPhaseRamAccountingContext;
    this.sharedShardContexts = sharedShardContexts;

    listenableRowReceiver = RowReceivers.listenableRowReceiver(rowReceiver);
    Futures.addCallback(listenableRowReceiver.finishFuture(), new FutureCallback<Void>() {
        @Override
        public void onSuccess(@Nullable Void result) {
            close();
        }

        @Override
        public void onFailure(@Nonnull Throwable t) {
            closeDueToFailure(t);
        }
    });
    this.rowReceiver = listenableRowReceiver;
    this.threadPoolName = threadPoolName(collectPhase, localNodeId);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:28,代码来源:JobCollectContext.java

示例9: execute

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public ListenableFuture<FullHttpResponse> execute() throws URISyntaxException {
  Preconditions.checkState(request != null);
  final SettableFuture<FullHttpResponse> error = SettableFuture.create();
  final SettableFuture<FullHttpResponse> response = SettableFuture.create();
  final ListenableFuture<ChannelFuture> connectFuture =
      connect(XUrl.getInetSocket(uri), client.getBootstrap(), buildRetryLoop());

  Futures.addCallback(
      connectFuture,
      new FutureCallback<ChannelFuture>() {
        @Override
        public void onSuccess(ChannelFuture result) {
          try {
            Channel channel = result.await().channel();
            channel.writeAndFlush(request);

            HttpResponseHandler responseHandler =
                (HttpResponseHandler) channel.pipeline().get("responseHandler");
            response.setFuture(responseHandler.getResponse());
          } catch (InterruptedException e) {
            response.cancel(true);
            error.setException(e);
          }
        }

        @Override
        public void onFailure(Throwable t) {
          response.cancel(true);
          error.setException(t);
        }
      });

  if (response.isCancelled()) {
    return error;
  } else {
    return response;
  }
}
 
开发者ID:Nordstrom,项目名称:xrpc,代码行数:39,代码来源:Call.java

示例10: onCarBought

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public void onCarBought(CarBought notification) {

  final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
  carPersonBuilder.setCarId(notification.getCarId());
  carPersonBuilder.setPersonId(notification.getPersonId());
  CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
  carPersonBuilder.setKey(key);
  final CarPerson carPerson = carPersonBuilder.build();

  LOG.info("Car bought, adding car-person entry: [{}]", carPerson);

  InstanceIdentifier<CarPerson> carPersonIId =
      InstanceIdentifier.<CarPeople>builder(CarPeople.class).child(CarPerson.class, carPerson.getKey()).build();


  WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
  tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson, true);

  Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
    @Override
    public void onSuccess(final Void result) {
      LOG.info("Successfully added car-person entry: [{}]", carPerson);
    }

    @Override
    public void onFailure(final Throwable t) {
      LOG.error(String.format("Failed to add car-person entry: [%s]", carPerson), t);
    }
  });

}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:33,代码来源:PeopleCarListener.java

示例11: ProjectorChainContext

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public ProjectorChainContext(int id,
                             String name,
                             UUID jobId,
                             ProjectorFactory projectorFactory,
                             List<Projection> projections,
                             RowReceiver rowReceiver,
                             RamAccountingContext ramAccountingContext) {
    super(id, LOGGER);
    this.name = name;
    ListenableRowReceiver listenableRowReceiver = RowReceivers.listenableRowReceiver(rowReceiver);
    Futures.addCallback(listenableRowReceiver.finishFuture(), new FutureCallback<Void>() {
        @Override
        public void onSuccess(@Nullable Void result) {
            ProjectorChainContext.this.close(null);
        }

        @Override
        public void onFailure(@Nonnull Throwable t) {
            ProjectorChainContext.this.close(t);
        }
    });
    projectorChain = FlatProjectorChain.withAttachedDownstream(
            projectorFactory,
            ramAccountingContext,
            projections,
            listenableRowReceiver,
            jobId
    );
    this.rowReceiver = projectorChain.firstProjector();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:ProjectorChainContext.java

示例12: addCallback

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public FluentFuture<V> addCallback(FutureCallback<V> callback) {
  Futures.addCallback(this, callback, executor);
  return this;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:FluentFutures.java

示例13: trackTimestamp

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
/** Track the timestamp of the event for determining watermark values until it has been sent or dropped. */
public void trackTimestamp(ListenableFuture<UserRecordResult> f, TripEvent event) {
  Futures.addCallback(f, new RemoveTimestampCallback(event));
}
 
开发者ID:awslabs,项目名称:flink-stream-processing-refarch,代码行数:5,代码来源:WatermarkTracker.java

示例14: getDevice

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public void getDevice(DeviceId deviceId, PluginCallback<Device> callback) {
  ListenableFuture<Device> deviceFuture = pluginCtx.deviceService.findDeviceByIdAsync(deviceId);
  Futures.addCallback(deviceFuture, getCallback(callback, v -> v));
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:6,代码来源:PluginProcessingContext.java

示例15: addSuccessCallback

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public RedFuture addSuccessCallback(Executor executor, EmptyCallback callback) {
    Futures.addCallback(_settableFuture, safeCallback(t -> callback.call(), null), executor);
    return this;
}
 
开发者ID:avivcarmis,项目名称:java-red,代码行数:6,代码来源:BaseOpenRedFuture.java


注:本文中的com.google.common.util.concurrent.Futures.addCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。