示例#1
0
  public LocalDocument getDocument(LocalQuery query, boolean recurring) throws IOException {
    HttpResponse response;
    if (recurring) {
      response = core.post(getRecurringUrl, query.toJson());
    } else {
      response = core.post(getUrl, query.toJson());
    }

    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      LocalDocument ld;
      try {
        ld = new LocalDocument(EntityUtils.toString(response.getEntity()));
      } catch (JsonException e) {
        throw new IOException(e);
      }
      InternalLogger.debug("Received document with ID " + ld.getID());
      currentDocument = ld;
      return ld;
    } else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
      InternalLogger.debug("No document found matching query");
      EntityUtils.consume(response.getEntity());
      return null;
    } else {
      logUnexpected(response);
      return null;
    }
  }
示例#2
0
  public Map<String, Object> getProperties() throws IOException {
    HttpResponse response = core.get(propertyUrl);

    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      Map<String, Object> map;
      try {
        map = SerializationUtils.fromJson(EntityUtils.toString(response.getEntity()));
      } catch (JsonException e) {
        throw new IOException(e);
      }
      InternalLogger.debug("Successfully retrieved propertyMap with " + map.size() + " entries");
      return map;
    } else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
      InternalLogger.debug("No document found matching query");
      EntityUtils.consume(response.getEntity());
      return null;
    } else {
      logUnexpected(response);
      return null;
    }
  }
示例#3
0
  /** Writes all outstanding updates to the last document fetched from the pipeline. */
  public boolean saveCurrentDocument() throws IOException, JsonException {
    boolean keepingLock = keepLock;
    if (currentDocument == null) {
      InternalLogger.error("There is no document to write.");
      return false;
    }
    boolean x = save(currentDocument);
    if (x && !keepingLock) {
      currentDocument = null;
    }

    return x;
  }
示例#4
0
  /**
   * Releases the most recently read document back to the pipeline
   *
   * @return true if there was a document to release
   * @throws HttpException
   * @throws IOException
   */
  public boolean releaseLastDocument() throws IOException {
    if (currentDocument == null) {
      InternalLogger.debug("There is no document to release...");
      return false;
    }
    HttpResponse response = core.post(releaseUrl, currentDocument.contentFieldsToJson(null));
    currentDocument = null;
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      EntityUtils.consume(response.getEntity());
      return true;
    }

    logUnexpected(response);

    return false;
  }
示例#5
0
 private static void logUnexpected(HttpResponse response) throws IOException {
   InternalLogger.error("Node gave an unexpected response: " + response.getStatusLine());
   InternalLogger.error("Message: " + EntityUtils.toString(response.getEntity()));
 }