/** * Use Kafka Streams' Queryable State API to work out if a key/value pair is located on * this node, or on another Kafka Streams node. This returned HostStoreInfo can be used * to redirect an HTTP request to the node that has the data. * <p> * If metadata is available, which can happen on startup, or during a rebalance, block until it is. */ private HostStoreInfo getKeyLocationOrBlock(String id, AsyncResponse asyncResponse) { HostStoreInfo locationOfKey; while (locationMetadataIsUnavailable(locationOfKey = getHostForOrderId(id))) { //The metastore is not available. This can happen on startup/rebalance. if (asyncResponse.isDone()) { //The response timed out so return return null; } try { //Sleep a bit until metadata becomes available Thread.sleep(Math.min(Long.valueOf(CALL_TIMEOUT), 200)); } catch (InterruptedException e) { e.printStackTrace(); } } return locationOfKey; }
@Override public void onComplete() { if (!asyncResponse.isDone()) { asyncResponse.resume(Response.noContent().build()); } } }
private void onCancel(ConverterNetworkProtocol.Status status) { if (asyncResponse.isDone()) { return; } synchronized (answerLock) { if (asyncResponse.isDone()) { return; } LOGGER.info("Sending cancellation response for {}", asyncResponse); asyncResponse.resume(Response .status(status.getStatusCode()) .build()); } } }
@Override public void onException(Exception e) { if (asyncResponse.isDone()) { return; } synchronized (answerLock) { if (asyncResponse.isDone()) { return; } LOGGER.info("Sending exceptional response for {}", asyncResponse, e); asyncResponse.resume(Response .status(ConverterNetworkProtocol.Status.describe(e).getStatusCode()) .build()); } }
@Override public void onComplete(InputStream inputStream) { if (asyncResponse.isDone()) { return; } synchronized (answerLock) { if (asyncResponse.isDone()) { return; } LOGGER.info("Sending successful response for {}", asyncResponse); asyncResponse.resume(Response .status(ConverterNetworkProtocol.Status.OK.getStatusCode()) .entity(inputStream) .type(targetType.toString()) .build()); } }
@Override public void update(String topicName, PluginUpdateQuery updateQuery, String authorization, AsyncResponse asyncResponse) { HivePrincipal principal = (HivePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserVO user = principal.getUser(); PluginVO pluginVO = getPluginVO(topicName, asyncResponse, principal, user); if (!asyncResponse.isDone()) { pluginRegisterService.update(pluginVO, updateQuery) .thenAccept(asyncResponse::resume); } }
@Override public void delete(String topicName, String authorization, AsyncResponse asyncResponse) { HivePrincipal principal = (HivePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserVO user = principal.getUser(); PluginVO pluginVO = getPluginVO(topicName, asyncResponse, principal, user); if (!asyncResponse.isDone()) { pluginRegisterService.delete(pluginVO) .thenAccept(asyncResponse::resume); } }
@Override public void onComplete() { if (!asyncResponse.isDone()) { T element = elementRef.get(); if (element == null) { asyncResponse.resume(new NotFoundException()); } else { asyncResponse.resume(element); } } } }
if (!asyncResponse.isDone()) { asyncResponse.resume(ResponseFactory.response( Response.Status.OK, .subscribe(filters, names, ts, callback); pair.getRight().thenAccept(collection -> { if (!collection.isEmpty() && !asyncResponse.isDone()) { asyncResponse.resume(ResponseFactory.response( Response.Status.OK, if (!asyncResponse.isDone()) { asyncResponse.resume(response);
if (!asyncResponse.isDone()) { asyncResponse.resume(ResponseFactory.response( OK, .sendSubscribeRequest(filters, names, ts, returnUpdated, limit, callback); pair.getRight().thenAccept(collection -> { if (!collection.isEmpty() && !asyncResponse.isDone()) { asyncResponse.resume(ResponseFactory.response( OK, if (!asyncResponse.isDone()) { asyncResponse.resume(response);
if (!asyncResponse.isDone()) { asyncResponse.resume(ResponseFactory.response( OK, future.thenAccept(pair -> { final DeviceCommand deviceCommand = pair.getRight(); if (!asyncResponse.isDone() && deviceCommand.getIsUpdated()) { asyncResponse.resume(ResponseFactory.response( OK, commandService.sendUnsubscribeRequest(Collections.singleton(future.get().getLeft())); } catch (InterruptedException | ExecutionException e) { if (!asyncResponse.isDone()) { asyncResponse.resume(ResponseFactory.response(INTERNAL_SERVER_ERROR)); if (!asyncResponse.isDone()) { asyncResponse.resume(ResponseFactory.response(OK, command, COMMAND_TO_DEVICE));
if (!asyncResponse.isDone()) { asyncResponse.resume( RequestHandlerUtils.makeErrorResponse(