Package com.google.walkaround.util.server.RetryHelper

Examples of com.google.walkaround.util.server.RetryHelper.RetryableFailure


                // hours, but let's hope that the connection between App Engine and Google Wave
                // is fast enough to make that irrelevant.
                HTTPResponse response = urlfetch.fetch(
                    new HTTPRequest(new URL(url), HTTPMethod.GET));
                if (response.getResponseCode() != 200) {
                  throw new RetryableFailure("Unexpected response code: "
                      + response.getResponseCode());
                }
                byte[] bytes = response.getContent();
                if (expectedBytes != null) {
                  Assert.check(expectedBytes == bytes.length, "Expected %s bytes, got %s: %s",
                      expectedBytes, bytes.length, prettyBytes(bytes));
                }
                final AppEngineFile file = dump(mimeType, filename, ByteBuffer.wrap(bytes));
                log.info("Wrote file " + file);
                BlobKey blobKey =
                    // NOTE(ohler): When running locally with unapplied jobs
                    // enabled, getBlobKey() sometimes returns null here even
                    // though it shouldn't, according to its documentation.  So
                    // we retry.  Not sure if this is needed when deployed.
                    new RetryHelper().run(
                        new RetryHelper.Body<BlobKey>() {
                          @Override public BlobKey run() throws RetryableFailure {
                            BlobKey key = getFileService().getBlobKey(file);
                            if (key != null) {
                              return key;
                            } else {
                              throw new RetryableFailure("getBlobKey(" + file + ") returned null");
                            }
                          }
                        });
                return rawAttachmentService.turnBlobIntoAttachment(blobKey);
              } catch (IOException e) {
                throw new RetryableFailure("IOException fetching " + url);
              }
            }
          });
    } catch (PermanentFailure e) {
      log.severe("Failed to fetch attachment " + url + ", skipping");
View Full Code Here


                  JSONObject data = result.getJSONObject("data");
                  if (data.length() == 0) {
                    // Apparently, the server often sends {"id":"op_id", "data":{}} when
                    // something went wrong on the server side, so we translate that to an
                    // IOException.
                    throw new RetryableFailure("Robot API response looks like an error: " + result);
                  } else {
                    return data;
                  }
                } else {
                  throw new RuntimeException("Result has neither error nor data: " + result);
View Full Code Here

          } catch (InternalFailureException e) {
            // Perhaps the fact that this is different from
            // TransientFailureException suggests that we shouldn't retry, but
            // neither the exception type nor the documentation are explicit
            // about it, so let's retry.
            throw new RetryableFailure("Internal task queue failure enqueueing " + task, e);
          } catch (TransientFailureException e) {
            throw new RetryableFailure("Transient task queue failure enqueueing " + task, e);
          }
        }
      });
    }
View Full Code Here

TOP

Related Classes of com.google.walkaround.util.server.RetryHelper.RetryableFailure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.