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


Java CompletableFutures类代码示例

本文整理汇总了Java中com.spotify.futures.CompletableFutures的典型用法代码示例。如果您正苦于以下问题:Java CompletableFutures类的具体用法?Java CompletableFutures怎么用?Java CompletableFutures使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: updateWorkflowState

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletionStage<WorkflowState> updateWorkflowState(String componentId, String workflowId,
                                                          WorkflowState workflowState) {
  final HttpUrl.Builder urlBuilder = getUrlBuilder()
      .addPathSegment("workflows")
      .addPathSegment(componentId)
      .addPathSegment(workflowId)
      .addPathSegment("state");
  final ByteString payload;
  try {
    payload = serialize(workflowState);
  } catch (JsonProcessingException e) {
    return CompletableFutures.exceptionallyCompletedFuture(new RuntimeException(e));
  }
  return executeRequest(Request.forUri(urlBuilder.build().toString(), "PATCH")
                            .withPayload(payload), WorkflowState.class);
}
 
开发者ID:spotify,项目名称:styx,代码行数:18,代码来源:StyxApolloClient.java

示例2: triggerWorkflowInstance

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletionStage<Void> triggerWorkflowInstance(String componentId,
                                                     String workflowId,
                                                     String parameter) {
  final HttpUrl.Builder urlBuilder = getUrlBuilder()
      .addPathSegment("scheduler")
      .addPathSegment("trigger");
  final WorkflowInstance workflowInstance = WorkflowInstance.create(
      WorkflowId.create(componentId, workflowId),
      parameter);
  try {
    final ByteString payload = serialize(workflowInstance);
    return executeRequest(
        Request.forUri(urlBuilder.build().toString(), "POST").withPayload(payload))
        .thenApply(response -> (Void) null);
  } catch (JsonProcessingException e) {
    return CompletableFutures.exceptionallyCompletedFuture(new RuntimeException(e));
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:20,代码来源:StyxApolloClient.java

示例3: haltWorkflowInstance

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletionStage<Void> haltWorkflowInstance(String componentId,
                                                  String workflowId,
                                                  String parameter) {
  final HttpUrl.Builder urlBuilder = getUrlBuilder()
      .addPathSegment("scheduler")
      .addPathSegment("halt");
  final WorkflowInstance workflowInstance = WorkflowInstance.create(
      WorkflowId.create(componentId, workflowId),
      parameter);
  try {
    final ByteString payload = serialize(workflowInstance);
    return executeRequest(
        Request.forUri(urlBuilder.build().toString(), "POST").withPayload(payload))
        .thenApply(response -> (Void) null);
  } catch (JsonProcessingException e) {
    return CompletableFutures.exceptionallyCompletedFuture(new RuntimeException(e));
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:20,代码来源:StyxApolloClient.java

示例4: retryWorkflowInstance

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletionStage<Void> retryWorkflowInstance(String componentId,
                                                   String workflowId,
                                                   String parameter) {
  final HttpUrl.Builder urlBuilder = getUrlBuilder()
      .addPathSegment("scheduler")
      .addPathSegment("retry");
  final WorkflowInstance workflowInstance = WorkflowInstance.create(
      WorkflowId.create(componentId, workflowId),
      parameter);
  try {
    final ByteString payload = serialize(workflowInstance);
    return executeRequest(
        Request.forUri(urlBuilder.build().toString(), "POST").withPayload(payload))
        .thenApply(response -> (Void) null);
  } catch (JsonProcessingException e) {
    return CompletableFutures.exceptionallyCompletedFuture(new RuntimeException(e));
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:20,代码来源:StyxApolloClient.java

示例5: backfillCreate

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletionStage<Backfill> backfillCreate(String componentId, String workflowId,
                                                String start, String end,
                                                int concurrency,
                                                String description) {
  final HttpUrl.Builder urlBuilder = getUrlBuilder().addPathSegment("backfills");
  try {
    final ByteString payload = serialize(BackfillInput.create(
        Instant.parse(start), Instant.parse(end), componentId, workflowId, concurrency,
        Optional.ofNullable(description)));
    return executeRequest(Request.forUri(urlBuilder.build().toString(), "POST")
        .withPayload(payload), Backfill.class);
  } catch (JsonProcessingException e) {
    return CompletableFutures.exceptionallyCompletedFuture(new RuntimeException(e));
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:17,代码来源:StyxApolloClient.java

示例6: backfillEditConcurrency

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletionStage<Backfill> backfillEditConcurrency(String backfillId, int concurrency) {
  return backfill(backfillId, false).thenCompose(backfillPayload -> {
    final Backfill editedBackfill = backfillPayload.backfill().builder()
        .concurrency(concurrency)
        .build();
    final HttpUrl.Builder urlBuilder = getUrlBuilder()
        .addPathSegment("backfills")
        .addPathSegment(backfillId);
    try {
      final ByteString payload = serialize(editedBackfill);
      return executeRequest(Request.forUri(urlBuilder.build().toString(), "PUT")
          .withPayload(payload), Backfill.class);
    } catch (JsonProcessingException e) {
      return CompletableFutures.exceptionallyCompletedFuture(new RuntimeException(e));
    }
  });
}
 
开发者ID:spotify,项目名称:styx,代码行数:19,代码来源:StyxApolloClient.java

示例7: haltActiveBackfillInstances

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
private CompletionStage<Response<ByteString>> haltActiveBackfillInstances(Backfill backfill, Client client) {
  return CompletableFutures.allAsList(
      retrieveBackfillStatuses(backfill).stream()
          .filter(BackfillResource::isActiveState)
          .map(RunStateData::workflowInstance)
          .map(workflowInstance -> haltActiveBackfillInstance(workflowInstance, client))
          .collect(toList()))
      .handle((result, throwable) -> {
        if (throwable != null || result.contains(Boolean.FALSE)) {
          return Response.forStatus(
              Status.INTERNAL_SERVER_ERROR
                  .withReasonPhrase(
                      "some active instances cannot be halted, however no new ones will be triggered"));
        } else {
          return Response.ok();
        }
      });
}
 
开发者ID:spotify,项目名称:styx,代码行数:19,代码来源:BackfillResource.java

示例8: multiget

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
private CompletionStage<List<GetResult<V>>> multiget(List<byte[]> keys, int ttl) {
  final int size = keys.size();
  if (size == 0) {
    return CompletableFuture.completedFuture(Collections.<GetResult<V>>emptyList());
  }

  final List<List<byte[]>> keyPartition =
        Lists.partition(keys, MemcacheEncoder.MAX_MULTIGET_SIZE);
  final List<CompletionStage<List<GetResult<byte[]>>>> futureList =
        new ArrayList<>(keyPartition.size());

  for (final List<byte[]> part : keyPartition) {
    MultigetRequest request = MultigetRequest.create(part, ttl);
    futureList.add(rawMemcacheClient.send(request));
  }

  final CompletionStage<List<GetResult<byte[]>>> future =
      CompletableFutures.allAsList(futureList)
          .thenApply(Utils.flatten());

  metrics.measureMultigetFuture(future);
  return transformerUtil.decodeList(future);
}
 
开发者ID:spotify,项目名称:folsom,代码行数:24,代码来源:DefaultBinaryMemcacheClient.java

示例9: multiget

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
private CompletionStage<List<GetResult<V>>> multiget(List<byte[]> keys, boolean withCas) {
  final int size = keys.size();
  if (size == 0) {
    return CompletableFuture.completedFuture(Collections.<GetResult<V>>emptyList());
  }

  final List<List<byte[]>> keyPartition =
          Lists.partition(keys, MemcacheEncoder.MAX_MULTIGET_SIZE);
  final List<CompletionStage<List<GetResult<byte[]>>>> futureList =
          new ArrayList<>(keyPartition.size());

  for (final List<byte[]> part : keyPartition) {
    MultigetRequest request = MultigetRequest.create(part, withCas);
    futureList.add(rawMemcacheClient.send(request));
  }

  final CompletionStage<List<GetResult<byte[]>>> future =
      ((CompletionStage<List<List<GetResult<byte[]>>>>) CompletableFutures.allAsList(futureList))
          .thenApply(Utils.flatten());

  metrics.measureMultigetFuture(future);
  return transformerUtil.decodeList(future);
}
 
开发者ID:spotify,项目名称:folsom,代码行数:24,代码来源:DefaultAsciiMemcacheClient.java

示例10: checkAndUpdateHealthyServers

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
private CompletableFuture<Void> checkAndUpdateHealthyServers() {
    List<ServerConnection> checkedServers = updateServerList();

    CompletableFuture<List<Boolean>> healthCheckResults = CompletableFutures.successfulAsList(
            checkedServers.stream()
                          .map(connection -> connection.healthChecker.isHealthy(connection.endpoint()))
                          .collect(toImmutableList()),
            t -> false);
    return healthCheckResults.handle(voidFunction((result, thrown) -> {
        ImmutableList.Builder<Endpoint> newHealthyEndpoints = ImmutableList.builder();
        for (int i = 0; i < result.size(); i++) {
            if (result.get(i)) {
                newHealthyEndpoints.add(checkedServers.get(i).endpoint());
            }
        }
        setEndpoints(newHealthyEndpoints.build());
    }));
}
 
开发者ID:line,项目名称:armeria,代码行数:19,代码来源:HealthCheckedEndpointGroup.java

示例11: sendRequest

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
static <T extends Options, S extends Output> CompletionStage<S> sendRequest(
    final Client client,
    final String uri,
    final T options,
    final Class<S> cls) throws RktLauncherRemoteException {
  final ByteString payload;
  try {
    payload = ByteString.of(Json.serialize(options));
  } catch (JsonProcessingException e) {
    return CompletableFutures.exceptionallyCompletedFuture(
        new RktLauncherRemoteException("failed to serialize payload", e));
  }
  return sendRequest(client, Request.forUri(uri, DEFAULT_HTTP_METHOD).withPayload(payload), cls);
}
 
开发者ID:honnix,项目名称:rkt-launcher,代码行数:15,代码来源:RktCommandHelper.java

示例12: normalize

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletableFuture<Revision> normalize(Revision revision) {
    try {
        return CompletableFuture.completedFuture(blockingNormalize(revision));
    } catch (RevisionNotFoundException e) {
        return CompletableFutures.exceptionallyCompletedFuture(e);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:9,代码来源:GitRepository.java

示例13: continueAfterResponse

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
public CompletableFuture<TaggedResponse> continueAfterResponse(ImapResponse imapResponse, Throwable throwable) {
  if (throwable != null) {
    return CompletableFutures.exceptionallyCompletedFuture(throwable);
  }

  String toEncode = NUL + user + NUL + password;
  String base64EncodedAuthRequest = BaseEncoding.base64().encode(toEncode.getBytes(StandardCharsets.UTF_8));
  return imapClient.send(new SimpleStringCommand(base64EncodedAuthRequest));
}
 
开发者ID:HubSpot,项目名称:NioImapClient,代码行数:10,代码来源:AuthenticatePlainCommand.java

示例14: createOrUpdateWorkflow

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletionStage<Workflow> createOrUpdateWorkflow(String componentId, WorkflowConfiguration workflowConfig) {
  final HttpUrl.Builder urlBuilder = getUrlBuilder()
      .addPathSegment("workflows")
      .addPathSegment(componentId);
  final ByteString payload;
  try {
    payload = serialize(workflowConfig);
  } catch (JsonProcessingException e) {
    return CompletableFutures.exceptionallyCompletedFuture(new RuntimeException(e));
  }
  final Request request = Request.forUri(urlBuilder.build().toString(), "POST").withPayload(payload);
  return executeRequest(request, Workflow.class);
}
 
开发者ID:spotify,项目名称:styx,代码行数:15,代码来源:StyxApolloClient.java

示例15: resourceCreate

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Override
public CompletionStage<Resource> resourceCreate(String resourceId, int concurrency) {
  final HttpUrl.Builder urlBuilder = getUrlBuilder().addPathSegment("resources");
  try {
    final ByteString payload = serialize(Resource.create(resourceId, concurrency));
    return executeRequest(Request.forUri(urlBuilder.build().toString(), "POST")
        .withPayload(payload), Resource.class);
  } catch (JsonProcessingException e) {
    return CompletableFutures.exceptionallyCompletedFuture(new RuntimeException(e));
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:12,代码来源:StyxApolloClient.java


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