• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CompletableFutures类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: resourceEdit

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


示例17: executeRequest

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
private CompletionStage<Response<ByteString>> executeRequest(final Request request) {
  final Optional<String> authToken;
  try {
    authToken = auth.getToken(this.apiHost.toString());
  } catch (IOException | GeneralSecurityException e) {
    // Credential probably invalid, configured wrongly or the token request failed.
    return CompletableFutures.exceptionallyCompletedFuture(
        new ClientErrorException("Authentication failure: " + e.getMessage(), e));
  }
  return client.send(decorateRequest(request, authToken)).handle((response, e) -> {
    if (e != null) {
      final Throwable rootCause = Throwables.getRootCause(e);
      if (rootCause instanceof SocketTimeoutException) {
        throw new ClientErrorException("Connection failed: " + rootCause.getMessage() + ": " + apiHost, e);
      } else {
        throw new ClientErrorException("Request failed: " + request, e);
      }
    } else {
      switch (response.status().family()) {
        case SUCCESSFUL:
          return response;
        default:
          final String message = response.status().code() + " " + response.status().reasonPhrase();
          throw new ApiErrorException(message, response.status().code(), authToken.isPresent());
      }
    }
  });
}
 
开发者ID:spotify,项目名称:styx,代码行数:29,代码来源:StyxApolloClient.java


示例18: testClientUnknownError

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
@Test
public void testClientUnknownError() {
  final NullPointerException exception = new NullPointerException();
  when(client.triggerWorkflowInstance(any(), any(), any()))
      .thenReturn(CompletableFutures.exceptionallyCompletedFuture(exception));

  try {
    CliMain.run(cliContext, "t", "foo", "bar", "2017-01-02");
    fail();
  } catch (CliExitException e) {
    assertThat(e.status(), is(ExitStatus.ClientError));
  }

  verify(cliOutput).printError(Throwables.getStackTraceAsString(exception));
}
 
开发者ID:spotify,项目名称:styx,代码行数:16,代码来源:CliMainTest.java


示例19: createCompletableFuture

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
CompletableFuture<Chunk> createCompletableFuture() {
    LoadState currentState = state.get();
    if (currentState == LoadState.COMPLETED) {
        return CompletableFuture.completedFuture(loaded.get());
    } else if (currentState == LoadState.EXCEPTIONAL) {
        return CompletableFutures.exceptionallyCompletedFuture(loadException.get());
    }

    CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
    futuresToComplete.add(completableFuture);
    return completableFuture;
}
 
开发者ID:voxelwind,项目名称:voxelwind,代码行数:13,代码来源:LevelChunkManager.java


示例20: getChunksForRadius

import com.spotify.futures.CompletableFutures; //导入依赖的package包/类
private CompletableFuture<List<Chunk>> getChunksForRadius(int radius) {
    // Get current player's position in chunk coordinates.
    int chunkX = getPosition().getFloorX() >> 4;
    int chunkZ = getPosition().getFloorZ() >> 4;

    // Now get and send chunk data.
    Set<Vector2i> chunksForRadius = new HashSet<>();
    List<CompletableFuture<Chunk>> completableFutures = new ArrayList<>();

    for (int x = -radius; x <= radius; x++) {
        for (int z = -radius; z <= radius; z++) {
            int newChunkX = chunkX + x, newChunkZ = chunkZ + z;
            Vector2i chunkCoords = new Vector2i(newChunkX, newChunkZ);
            chunksForRadius.add(chunkCoords);

            if (!sentChunks.add(chunkCoords)) {
                // Already sent, don't need to resend.
                continue;
            }

            completableFutures.add(getLevel().getChunk(newChunkX, newChunkZ));
        }
    }

    sentChunks.retainAll(chunksForRadius);

    return CompletableFutures.allAsList(completableFutures);
}
 
开发者ID:voxelwind,项目名称:voxelwind,代码行数:29,代码来源:PlayerSession.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CombinedHighlighter类代码示例发布时间:2022-05-23
下一篇:
Java VoteAuthorityEntry类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap