當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。