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


Java DocumentClientException.getStatusCode方法代码示例

本文整理汇总了Java中com.microsoft.azure.documentdb.DocumentClientException.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentClientException.getStatusCode方法的具体用法?Java DocumentClientException.getStatusCode怎么用?Java DocumentClientException.getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.azure.documentdb.DocumentClientException的用法示例。


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

示例1: handleRetryAttemptInternal

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
private Observable<Long> handleRetryAttemptInternal(DocumentClientException e, int attemptNumber) throws DocumentClientException {

        RetryPolicy retryPolicy = null;
        if (e.getStatusCode() == HttpConstants.StatusCodes.BADREQUEST && e.getSubStatusCode() != null
                && e.getSubStatusCode() == HttpConstants.SubStatusCodes.PARTITION_KEY_MISMATCH) {
            // If HttpStatusCode is 404 (NotFound) and SubStatusCode is
            // 1001 (PartitionKeyMismatch), invoke the partition key mismatch retry policy
            retryPolicy = keyMismatchRetryPolicy;
        }

        if (retryPolicy == null || !retryPolicy.shouldRetry(e)) {
            LOGGER.trace("Execution encontured exception: {}, status code {} sub status code {}. Won't retry!", 
                    e.getMessage(), e.getStatusCode(), e.getSubStatusCode());
            return Observable.error(e);
        }
        LOGGER.trace("Execution encontured exception: {}, status code {} sub status code {}. Will retry in {}ms", 
                e.getMessage(), e.getStatusCode(), e.getSubStatusCode(), retryPolicy.getRetryAfterInMilliseconds());
       
        long waitTime = retryPolicy.getRetryAfterInMilliseconds();
        return Observable.just(waitTime);
    }
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:22,代码来源:CreateDocumentRetryHandler.java

示例2: safeInit

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
private void safeInit() throws Exception {
    int count = 0;
    long startTime = System.currentTimeMillis();
    while(true) {
        try {
            initialize();
            break;
        } catch (Exception e) {
            count++;
            DocumentClientException dce = ExceptionUtils.getThrottelingException(e);
            long now = System.currentTimeMillis();
            if (count < retryOptions.getMaxRetryAttemptsOnThrottledRequests() 
                    && now - startTime < (retryOptions.getMaxRetryWaitTimeInSeconds() * 1000)
                    && dce != null
                    && dce.getStatusCode() == HttpConstants.StatusCodes.TOO_MANY_REQUESTS ) {
                Thread.sleep(count * dce.getRetryAfterInMilliseconds() + INITIALIZATION_SLEEP_TIME_ON_THROTTLING);
                continue;
            } else {
                throw e;
            }
        }
    }
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:24,代码来源:DocumentBulkImporter.java

示例3: CheckIfRetryNeeded

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
private boolean CheckIfRetryNeeded(Exception exception) {
    this.retryAfterInMilliseconds = 0;

    if(exception instanceof IllegalStateException) {
        exception = (Exception) exception.getCause();
    }
    
    if (exception instanceof DocumentClientException) {
        DocumentClientException dce = (DocumentClientException) exception;

        if (dce.getStatusCode() == REQUEST_RATE_TOO_LARGE) {
            this.retryAfterInMilliseconds = dce.getRetryAfterInMilliseconds() + this.currentAttemptCount * this.retryAdditiveMultiplier;

            if (this.retryAfterInMilliseconds == 0) {
                // we should never reach here as BE should turn non-zero of
                // retry delay.
                this.retryAfterInMilliseconds = this.defaultRetryInSeconds * 1000;
            }

            return true;
        }
    }

    return false;
}
 
开发者ID:Azure,项目名称:azure-documentdb-hadoop,代码行数:26,代码来源:BackoffExponentialRetryPolicy.java

示例4: handleRetryAttemptInternal

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
public Observable<Long> handleRetryAttemptInternal(DocumentClientException e, int attemptNumber) throws DocumentClientException {

        LOGGER.trace("Executing DocumentClientRequest");
        
        RetryPolicy retryPolicy = null;
        if (e.getStatusCode() == HttpConstants.StatusCodes.FORBIDDEN && e.getSubStatusCode() != null
                && e.getSubStatusCode() == HttpConstants.SubStatusCodes.FORBIDDEN_WRITEFORBIDDEN) {
            // If HttpStatusCode is 403 (Forbidden) and SubStatusCode is
            // 3 (WriteForbidden),
            // invoke the endpoint discovery retry policy
            retryPolicy = discoveryRetryPolicy;
        } else if (e.getStatusCode() == HttpConstants.StatusCodes.TOO_MANY_REQUESTS) {
            // If HttpStatusCode is 429 (Too Many Requests), invoke the
            // throttle retry policy
            retryPolicy = throttleRetryPolicy;
        } else if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND && e.getSubStatusCode() != null
                && e.getSubStatusCode() == HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE) {
            // If HttpStatusCode is 404 (NotFound) and SubStatusCode is
            // 1002 (ReadSessionNotAvailable), invoke the session read retry policy
            retryPolicy = sessionReadRetryPolicy;
        }

        if (retryPolicy == null || !retryPolicy.shouldRetry(e)) {
            LOGGER.trace("Execution encontured exception: {}, status code {} sub status code {}. Won't retry!", 
                    e.getMessage(), e.getStatusCode(), e.getSubStatusCode());
            return Observable.error(e);
        }
        LOGGER.trace("Execution encontured exception: {}, status code {} sub status code {}. Will retry in {}ms", 
                e.getMessage(), e.getStatusCode(), e.getSubStatusCode(), retryPolicy.getRetryAfterInMilliseconds());
        
        return Observable.timer(retryPolicy.getRetryAfterInMilliseconds(), TimeUnit.MILLISECONDS);
    }
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:33,代码来源:ExecuteDocumentClientRequestRetryHandler.java

示例5: onServerError

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
public CompletionStage<Result> onServerError(RequestHeader request, Throwable e) {
    String errorMessage;
    int errorCode;
    if (e instanceof DocumentClientException) {
        DocumentClientException ex = (DocumentClientException) e;
        errorCode = ex.getStatusCode();
        switch (errorCode) {
            case Status.NOT_FOUND:
                errorMessage = "The resource requested doesn't exist.";
                break;
            case Status.CONFLICT:
                errorMessage = "There is already a key with the Id specified.";
                break;
            case Status.PRECONDITION_FAILED:
                errorMessage = "ETag mismatch: the resource has been updated by another client.";
                break;
            default:
                errorMessage = ex.getMessage();
                break;
        }
    } else if (e instanceof BadRequestException) {
        errorCode = Status.BAD_REQUEST;
        errorMessage = e.getMessage();
    } else {
        errorCode = Status.INTERNAL_SERVER_ERROR;
        errorMessage = e.getMessage();
    }

    Map<String, Object> errorResult = new HashMap<>();
    errorResult.put("Message", "An error has occurred.");
    errorResult.put("ExceptionType", e.getClass().getName());
    errorResult.put("ExceptionMessage", errorMessage);
    //No StackTrace.
    if (false) {
        errorResult.put("StackTrace", e.getStackTrace());
        Throwable innerException = e.getCause();
        if (innerException != null) {
            errorResult.put("InnerExceptionMessage", innerException.getMessage());
            errorResult.put("InnerExceptionType", innerException.getClass().getName());
            errorResult.put("InnerExceptionStackTrace", innerException.getStackTrace());
        }
    }
    return CompletableFuture.completedFuture(
            Results.status(errorCode, toJson(errorResult))
    );
}
 
开发者ID:Azure,项目名称:pcs-storage-adapter-java,代码行数:47,代码来源:ErrorHandler.java

示例6: isThrottled

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
public static boolean isThrottled(DocumentClientException e) {
    return e.getStatusCode() == HttpConstants.StatusCodes.TOO_MANY_REQUESTS;
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:4,代码来源:ExceptionUtils.java

示例7: isTimedOut

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
public static boolean isTimedOut(DocumentClientException e) {
    return e.getStatusCode() == HttpConstants.StatusCodes.TIMEOUT;
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:4,代码来源:ExceptionUtils.java

示例8: isGone

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
public static boolean isGone(DocumentClientException e) {
    return e.getStatusCode() == HttpConstants.StatusCodes.GONE;
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:4,代码来源:ExceptionUtils.java

示例9: isSplit

import com.microsoft.azure.documentdb.DocumentClientException; //导入方法依赖的package包/类
public static boolean isSplit(DocumentClientException e) {
    return e.getStatusCode() == HttpConstants.StatusCodes.GONE
            && HttpConstants.SubStatusCodes.SPLITTING == e.getSubStatusCode();
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:5,代码来源:ExceptionUtils.java


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