Last active
March 18, 2020 23:53
-
-
Save anuchandy/108a235506180af11079e65d26311c6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------------------------------------------------------------------------------------- | |
// PublicMethod | |
@Override | |
public Mono<ResourceResponse<Database>> deleteDatabase(String databaseLink, RequestOptions options) { | |
return Mono.defer(new Supplier<Mono<ResourceResponse<Database>>>() { | |
@Override | |
public Mono<ResourceResponse<Database>> get() { | |
DocumentClientRetryPolicy retryPolicyInstance = resetSessionTokenRetryPolicy.getRequestPolicy(); | |
// call InternalMethod_1 | |
return ObservableHelper.inlineIfPossibleAsObs(() -> deleteDatabaseInternal(databaseLink, options, retryPolicyInstance), retryPolicyInstance); | |
} | |
}) | |
.subscriberContext(new Function<Context, Context>() { | |
@Override | |
public Context apply(Context reactorContext) { | |
com.azure.core.util.Context spanContext | |
= tracer.start("AsyncDocumentClient::deleteDatabase", Context.NONE); | |
// put values from spanContext to reactorContext | |
return reactorContext; | |
} | |
}) | |
.doOnError(new Consumer<Throwable>() { | |
@Override | |
public void accept(Throwable throwable) { | |
tracer.end(throwable.getMessage(), throwable, Context.NONE); | |
} | |
}) | |
.doOnSuccess(new Consumer<ResourceResponse<Database>>() { | |
@Override | |
public void accept(ResourceResponse<Database> response) { | |
tracer.end(response.getStatusCode(), null, Context.NONE); | |
} | |
}); | |
} | |
// --------------------------------------------------------------------------------------------- | |
// InternalMethod_1 called from PublicMethod | |
private Mono<ResourceResponse<Database>> deleteDatabaseInternal(String databaseLink, RequestOptions options, | |
DocumentClientRetryPolicy retryPolicyInstance) { | |
try { | |
if (StringUtils.isEmpty(databaseLink)) { | |
throw new IllegalArgumentException("databaseLink"); | |
} | |
logger.debug("Deleting a Database. databaseLink: [{}]", databaseLink); | |
String path = Utils.joinPath(databaseLink, null); | |
Map<String, String> requestHeaders = this.getRequestHeaders(options); | |
RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, | |
ResourceType.Database, path, requestHeaders, options); | |
if (retryPolicyInstance != null) { | |
retryPolicyInstance.onBeforeSendRequest(request); | |
} | |
// Call Lowest InternalMethod_2 | |
return this.delete(request, retryPolicyInstance) | |
.map(response -> toResourceResponse(response, Database.class)); | |
} catch (Exception e) { | |
logger.debug("Failure in deleting a database. due to [{}]", e.getMessage(), e); | |
return Mono.error(e); | |
} | |
} | |
// --------------------------------------------------------------------------------------------- | |
// Lowest InternalMethod_2 called from InternalMethod_2 | |
private Mono<RxDocumentServiceResponse> delete(RxDocumentServiceRequest request, DocumentClientRetryPolicy documentClientRetryPolicy) { | |
populateHeaders(request, RequestVerb.DELETE); | |
if(request.requestContext != null && documentClientRetryPolicy.getRetryCount() > 0) { | |
documentClientRetryPolicy.updateEndTime(); | |
request.requestContext.updateRetryContext(documentClientRetryPolicy, true); | |
} | |
return Mono.deferWithContext(new Function<Context, Mono<RxDocumentServiceResponse>>() { | |
@Override | |
public Mono<RxDocumentServiceResponse> apply(Context reactorContext) { | |
// extract span values from reactorContext | |
// set it in request header | |
return getStoreProxy(request).processMessage(request); | |
} | |
}); | |
} | |
// --------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment