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


Java PutResponse类代码示例

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


PutResponse类属于com.google.appengine.api.search包,在下文中一共展示了PutResponse类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPutAsyncDocument

import com.google.appengine.api.search.PutResponse; //导入依赖的package包/类
@Test
public void testPutAsyncDocument() {
    String indexName = "put-index";
    String docId = "testPutDocs";

    Index index = searchService.getIndex(IndexSpec.newBuilder()
            .setName(indexName)
            .build());

    Field field = Field.newBuilder().setName("subject").setText("put(Document)").build();
    Document document = Document.newBuilder()
            .setId(docId + "1")
            .addField(field).build();

    Future<PutResponse> resp = index.putAsync(document);

    while (!resp.isDone()) {
        if (resp.isCancelled()) {
            break;
        }
    }

    GetIndexesRequest request = GetIndexesRequest.newBuilder()
            .setIndexNamePrefix(indexName)
            .build();
    GetResponse<Index> response = searchService.getIndexes(request);
    List<Index> listIndexes = response.getResults();

    for (Index oneIndex : listIndexes) {
        Field retField = oneIndex.get(docId + "1").getOnlyField("subject");
        sync();
        assertEquals("put(Document)", retField.getText());
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:35,代码来源:IndexTest.java

示例2: index

import com.google.appengine.api.search.PutResponse; //导入依赖的package包/类
protected IndexOperation index(T object, K id) {
    Map<String, Object> data = metadata.getData(object);
    Document document = buildDocument(id, data);
    Future<PutResponse> putAsync = getIndex().putAsync(document);
    return new IndexOperation(putAsync);
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:7,代码来源:BaseGaeSearchService.java

示例3: putDocumentWithRetry

import com.google.appengine.api.search.PutResponse; //导入依赖的package包/类
/**
 * Tries putting a document, handling transient errors by retrying with exponential backoff.
 *
 * @throws PutException if a non-transient error is encountered.
 * @throws MaximumRetriesExceededException with final {@link OperationResult}'s message as final message,
 *         if operation fails after maximum retries.
 */
private static void putDocumentWithRetry(String indexName, final Document document)
        throws PutException, MaximumRetriesExceededException {
    final Index index = getIndex(indexName);

    /*
     * The GAE Search API signals put document failure in two ways: it either
     * returns a PutResponse containing an OperationResult with a non-OK StatusCode, or
     * throws a PutException that also contains an embedded OperationResult.
     * We handle both ways by examining the OperationResult to determine what kind of error it is. If it is
     * transient, we use RetryManager to retry the operation; if it is
     * non-transient, we do not retry but throw a PutException upwards instead.
     */
    RM.runUntilSuccessful(new RetryableTaskThrows<PutException>("Put document") {

        private OperationResult lastResult;

        @Override
        public void run() {
            try {
                PutResponse response = index.put(document);
                lastResult = response.getResults().get(0);

            } catch (PutException e) {
                lastResult = e.getOperationResult();
            }
        }

        @Override
        public boolean isSuccessful() throws PutException {
            // Update the final message to be shown if the task fails after maximum retries
            finalMessage = lastResult.getMessage();

            if (StatusCode.OK.equals(lastResult.getCode())) {
                return true;
            } else if (StatusCode.TRANSIENT_ERROR.equals(lastResult.getCode())) {
                // A transient error can be retried
                return false;
            } else {
                // A non-transient error signals that the operation should not be retried
                throw new PutException(lastResult);
            }
        }
    });
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:52,代码来源:SearchManager.java

示例4: putDocumentsWithRetry

import com.google.appengine.api.search.PutResponse; //导入依赖的package包/类
/**
 * Tries putting multiple documents, handling transient errors by retrying with exponential backoff.
 *
 * @throws PutException when only non-transient errors are encountered.
 * @throws MaximumRetriesExceededException with list of failed {@link Document}s as final data and
 *         final {@link OperationResult}'s message as final message, if operation fails after maximum retries.
 */
private static void putDocumentsWithRetry(String indexName, final List<Document> documents)
        throws PutException, MaximumRetriesExceededException {
    final Index index = getIndex(indexName);

    /*
     * The GAE Search API allows batch putting a List of Documents.
     * Results for each document are reported via a List of OperationResults.
     * We use RetryManager to retry putting a List of Documents, with each retry re-putting only
     * the documents that failed in the previous retry.
     * If we encounter one or more transient errors, we retry the operation.
     * If all results are non-transient errors, we give up and throw a PutException upwards.
     */
    RM.runUntilSuccessful(new RetryableTaskThrows<PutException>("Put documents") {

        private List<Document> documentsToPut = documents;
        private List<OperationResult> lastResults;
        private List<String> lastIds;

        @Override
        public void run() throws PutException {
            try {
                PutResponse response = index.put(documentsToPut);
                lastResults = response.getResults();
                lastIds = response.getIds();

            } catch (PutException e) {
                lastResults = e.getResults();
                lastIds = e.getIds();
            }
        }

        @Override
        public boolean isSuccessful() {
            boolean hasTransientError = false;

            List<Document> failedDocuments = new ArrayList<>();
            for (int i = 0; i < documentsToPut.size(); i++) {
                StatusCode code = lastResults.get(i).getCode();
                if (!StatusCode.OK.equals(code)) {
                    failedDocuments.add(documentsToPut.get(i));
                    if (StatusCode.TRANSIENT_ERROR.equals(code)) {
                        hasTransientError = true;
                    }
                }
            }

            // Update the list of documents to be put during the next retry
            documentsToPut = failedDocuments;

            // Update the final message and data to be shown if the task fails after maximum retries
            finalMessage = lastResults.get(0).getMessage();
            finalData = documentsToPut;

            if (documentsToPut.isEmpty()) {
                return true;
            } else if (hasTransientError) {
                // If there is at least one transient error, continue retrying
                return false;
            } else {
                // If all errors are non-transient, do not continue retrying
                throw new PutException(lastResults.get(0), lastResults, lastIds);
            }
        }
    });
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:73,代码来源:SearchManager.java

示例5: testPutAsyncIterable

import com.google.appengine.api.search.PutResponse; //导入依赖的package包/类
@Test
public void testPutAsyncIterable() {
    String indexName = "put-index";
    String docId = "testPutDocs";

    Index index = searchService.getIndex(IndexSpec.newBuilder()
            .setName(indexName)
            .build());

    List<Document> documents = new ArrayList<>();
    Field field = Field.newBuilder().setName("subject").setText("put(Document)").build();
    Document document1 = Document.newBuilder()
            .setId(docId + "1")
            .addField(field).build();
    field = Field.newBuilder().setName("subject").setText("put(Document)").build();
    Document document2 = Document.newBuilder()
            .setId(docId + "2")
            .addField(field).build();

    documents.add(document1);
    documents.add(document2);

    Future<PutResponse> resp = index.putAsync(documents);

    while (!resp.isDone()) {
        if (resp.isCancelled()) {
            break;
        }
    }

    GetIndexesRequest request = GetIndexesRequest.newBuilder()
            .setIndexNamePrefix(indexName)
            .build();
    GetResponse<Index> response = searchService.getIndexes(request);
    List<Index> listIndexes = response.getResults();

    for (Index oneIndex : listIndexes) {
        Field retField = oneIndex.get(docId + "1").getOnlyField("subject");
        assertEquals("put(Document)", retField.getText());
        retField = oneIndex.get(docId + "2").getOnlyField("subject");
        assertEquals("put(Document)", retField.getText());
        sync();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:45,代码来源:IndexTest.java


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