本文整理汇总了Java中com.google.appengine.api.search.StatusCode类的典型用法代码示例。如果您正苦于以下问题:Java StatusCode类的具体用法?Java StatusCode怎么用?Java StatusCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StatusCode类属于com.google.appengine.api.search包,在下文中一共展示了StatusCode类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: indexApp
import com.google.appengine.api.search.StatusCode; //导入依赖的package包/类
/**
* index gallery app into search index
* @param app galleryapp
*/
public void indexApp (GalleryApp app) {
// take the title, description, and the user name and index it
// need to build up a string with all meta data
String indexWords = app.getTitle()+" "+app.getDescription() + " " + app.getDeveloperName();
// now create the doc
Document doc = Document.newBuilder()
.setId(String.valueOf(app.getGalleryAppId()))
.addField(Field.newBuilder().setName("content").setText(indexWords))
.build();
Index index = getIndex();
try {
index.put(doc);
} catch (PutException e) {
if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) {
// retry putting the document
}
}
}
示例2: indexADocument
import com.google.appengine.api.search.StatusCode; //导入依赖的package包/类
/**
* Put a given document into an index with the given indexName.
* @param indexName The name of the index.
* @param document A document to add.
* @throws InterruptedException When Thread.sleep is interrupted.
*/
// [START putting_document_with_retry]
public static void indexADocument(String indexName, Document document)
throws InterruptedException {
IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
final int maxRetry = 3;
int attempts = 0;
int delay = 2;
while (true) {
try {
index.put(document);
} catch (PutException e) {
if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())
&& ++attempts < maxRetry) { // retrying
Thread.sleep(delay * 1000);
delay *= 2; // easy exponential backoff
continue;
} else {
throw e; // otherwise throw
}
}
break;
}
}
示例3: indexADocument
import com.google.appengine.api.search.StatusCode; //导入依赖的package包/类
/**
* Put a given document into an index with the given indexName.
*
* @param indexName The name of the index.
* @param document A document to add.
* @throws InterruptedException When Thread.sleep is interrupted.
*/
// [START putting_document_with_retry]
public static void indexADocument(String indexName, Document document)
throws InterruptedException {
IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
final int maxRetry = 3;
int attempts = 0;
int delay = 2;
while (true) {
try {
index.put(document);
} catch (PutException e) {
if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())
&& ++attempts < maxRetry) { // retrying
Thread.sleep(delay * 1000);
delay *= 2; // easy exponential backoff
continue;
} else {
throw e; // otherwise throw
}
}
break;
}
}
示例4: indexDocument
import com.google.appengine.api.search.StatusCode; //导入依赖的package包/类
private static void indexDocument (String name, Document document,
int retry) {
do {
try {
getIndex(name).put(document);
retry = 0;
} catch (PutException e) {
if (StatusCode.TRANSIENT_ERROR
.equals(e.getOperationResult().getCode())) {
retry--;
} else {
// if it is not a transient error we just stop
retry = 0;
}
}
} while (retry > 0);
}
示例5: MockResults
import com.google.appengine.api.search.StatusCode; //导入依赖的package包/类
public MockResults(List<T> results) {
super(new OperationResult(StatusCode.OK, ""), results, 0, 0, null);
this.results = results;
}
示例6: index
import com.google.appengine.api.search.StatusCode; //导入依赖的package包/类
private void index(ConvFields fields, ParticipantId user, @Nullable Supplement supplement)
throws RetryableFailure, PermanentFailure {
if (!isParticipantValidForIndexing(user)) {
log.warning(fields.slobId + ": Participant not valid for indexing: " + user);
return;
}
boolean isArchived = false;
boolean isFollowed = true;
int unreadBlips = fields.blipCount;
boolean participantsUnread = true;
if (supplement != null) {
isArchived = supplement.isArchived(fields.waveletId, fields.version);
isFollowed = supplement.isFollowed(true);
unreadBlips = fields.conv == null ? 0
: countUnreadBlips(fields.conv, fields.waveletId, fields.version, supplement);
participantsUnread = isParticipantListUnread(fields.version, supplement);
}
log.info("Unread blips: " + unreadBlips + "; participants unread: " + participantsUnread
+ "; has supplement: " + (supplement != null));
Document.Builder builder = Document.newBuilder();
builder.setId(fields.slobId.getId());
builder.addField(Field.newBuilder().setName(ID_FIELD).setAtom(fields.slobId.getId()));
builder.addField(Field.newBuilder().setName(CREATOR_FIELD).setText(fields.creator));
builder.addField(Field.newBuilder().setName(TITLE_FIELD).setText(
shortenTextMaybe(fields.title)));
builder.addField(Field.newBuilder().setName(CONTENT_FIELD).setText(
shortenTextMaybe(fields.indexableText)));
builder.addField(Field.newBuilder().setName(MODIFIED_MINUTES_FIELD).setNumber(
fields.lastModifiedMillis / 1000 / 60));
builder.addField(Field.newBuilder().setName(BLIP_COUNT_FIELD).setNumber(fields.blipCount));
builder.addField(Field.newBuilder().setName(UNREAD_BLIP_COUNT_FIELD).setNumber(unreadBlips));
if (!isArchived) {
builder.addField(Field.newBuilder().setName(IN_FOLDER_FIELD).setText(IN_INBOX_TEXT));
}
builder.addField(Field.newBuilder().setName(IS_FIELD).setAtom(
unreadBlips == 0 && !participantsUnread ? IS_READ_ATOM : IS_UNREAD_ATOM));
if (isArchived) {
builder.addField(Field.newBuilder().setName(IS_FIELD).setAtom(IS_ARCHIVED_ATOM));
}
if (isFollowed) {
builder.addField(Field.newBuilder().setName(IS_FIELD).setAtom(IS_FOLLOWED_ATOM));
}
Document doc = builder.build();
Index idx = getIndex(user);
log.info("Saving index document " + describe(doc));
// TODO(danilatos): Factor out all the error handling?
AddResponse resp;
try {
resp = idx.add(doc);
} catch (AddException e) {
throw new RetryableFailure("Error indexing " + fields.slobId, e);
}
for (OperationResult result : resp) {
if (!result.getCode().equals(StatusCode.OK)) {
throw new RetryableFailure("Error indexing " + fields.slobId + ", " + result.getMessage());
}
}
}
示例7: putDocumentWithRetry
import com.google.appengine.api.search.StatusCode; //导入依赖的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);
}
}
});
}
示例8: putDocumentsWithRetry
import com.google.appengine.api.search.StatusCode; //导入依赖的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);
}
}
});
}