Search in sources :

Example 1 with ServiceRequestInfo

use of org.apache.pulsar.functions.worker.request.ServiceRequestInfo in project incubator-pulsar by apache.

the class FunctionMetaDataManager method submit.

@VisibleForTesting
CompletableFuture<RequestResult> submit(Request.ServiceRequest serviceRequest) {
    ServiceRequestInfo serviceRequestInfo = ServiceRequestInfo.of(serviceRequest);
    CompletableFuture<MessageId> messageIdCompletableFuture = this.serviceRequestManager.submitRequest(serviceRequest);
    serviceRequestInfo.setCompletableFutureRequestMessageId(messageIdCompletableFuture);
    CompletableFuture<RequestResult> requestResultCompletableFuture = new CompletableFuture<>();
    serviceRequestInfo.setRequestResultCompletableFuture(requestResultCompletableFuture);
    this.pendingServiceRequests.put(serviceRequestInfo.getServiceRequest().getRequestId(), serviceRequestInfo);
    return requestResultCompletableFuture;
}
Also used : RequestResult(org.apache.pulsar.functions.worker.request.RequestResult) CompletableFuture(java.util.concurrent.CompletableFuture) ServiceRequestInfo(org.apache.pulsar.functions.worker.request.ServiceRequestInfo) MessageId(org.apache.pulsar.client.api.MessageId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ServiceRequestInfo

use of org.apache.pulsar.functions.worker.request.ServiceRequestInfo in project incubator-pulsar by apache.

the class FunctionMetaDataManager method completeRequest.

/**
 * Complete requests that this worker has pending
 * @param serviceRequest
 * @param isSuccess
 * @param message
 */
private void completeRequest(Request.ServiceRequest serviceRequest, boolean isSuccess, String message) {
    ServiceRequestInfo pendingServiceRequestInfo = this.pendingServiceRequests.getOrDefault(serviceRequest.getRequestId(), null);
    if (pendingServiceRequestInfo != null) {
        RequestResult requestResult = new RequestResult();
        requestResult.setSuccess(isSuccess);
        requestResult.setMessage(message);
        pendingServiceRequestInfo.getRequestResultCompletableFuture().complete(requestResult);
    }
}
Also used : RequestResult(org.apache.pulsar.functions.worker.request.RequestResult) ServiceRequestInfo(org.apache.pulsar.functions.worker.request.ServiceRequestInfo)

Aggregations

RequestResult (org.apache.pulsar.functions.worker.request.RequestResult)2 ServiceRequestInfo (org.apache.pulsar.functions.worker.request.ServiceRequestInfo)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 MessageId (org.apache.pulsar.client.api.MessageId)1