@SuppressWarnings("unchecked")
  public List<StockBook> getBooks() throws BookStoreException {
    ContentExchange exchange = new ContentExchange();
    String urlString = serverAddress + "/" + BookStoreMessageTag.LISTBOOKS;

    exchange.setURL(urlString);

    return (List<StockBook>) BookStoreUtility.SendAndRecv(this.client, exchange);
  }
  public void addBooks(Set<StockBook> bookSet) throws BookStoreException {
    ContentExchange exchange = new ContentExchange();
    String urlString;
    urlString = serverAddress + "/" + BookStoreMessageTag.ADDBOOKS;

    String listBooksxmlString = BookStoreUtility.serializeObjectToXMLString(bookSet);
    exchange.setMethod("POST");
    exchange.setURL(urlString);
    Buffer requestContent = new ByteArrayBuffer(listBooksxmlString);
    exchange.setRequestContent(requestContent);

    BookStoreUtility.SendAndRecv(this.client, exchange);
  }
  public void removeAllBooks() throws BookStoreException {
    ContentExchange exchange = new ContentExchange();
    String urlString;
    urlString = serverAddress + "/" + BookStoreMessageTag.REMOVEALLBOOKS;

    String test = "test";
    exchange.setMethod("POST");
    exchange.setURL(urlString);
    Buffer requestContent = new ByteArrayBuffer(test);
    exchange.setRequestContent(requestContent);

    BookStoreUtility.SendAndRecv(this.client, exchange);
  }
  @SuppressWarnings("unchecked")
  public List<StockBook> getBooksByISBN(Set<Integer> isbns) throws BookStoreException {
    ContentExchange exchange = new ContentExchange();
    String urlString;
    urlString = serverAddress + "/" + BookStoreMessageTag.GETSTOCKBOOKSBYISBN;

    String listBooksxmlString = BookStoreUtility.serializeObjectToXMLString(isbns);
    exchange.setMethod("POST");
    exchange.setURL(urlString);
    Buffer requestContent = new ByteArrayBuffer(listBooksxmlString);
    exchange.setRequestContent(requestContent);

    return (List<StockBook>) BookStoreUtility.SendAndRecv(this.client, exchange);
  }
  @SuppressWarnings("unchecked")
  public List<StockBook> getBooks() throws BookStoreException {

    BookStoreResult result = null;
    do {
      ContentExchange exchange = new ContentExchange();
      String urlString = getReplicaAddress() + "/" + BookStoreMessageTag.LISTBOOKS;

      exchange.setURL(urlString);
      result = BookStoreUtility.SendAndRecv(this.client, exchange);
    } while (result.getSnapshotId() < this.getSnapshotId());
    this.setSnapshotId(result.getSnapshotId());
    return (List<StockBook>) result.getResultList();
  }
  public void addCopies(Set<BookCopy> bookCopiesSet) throws BookStoreException {

    String listBookCopiesxmlString = BookStoreUtility.serializeObjectToXMLString(bookCopiesSet);
    Buffer requestContent = new ByteArrayBuffer(listBookCopiesxmlString);
    BookStoreResult result = null;

    ContentExchange exchange = new ContentExchange();
    String urlString = getMasterServerAddress() + "/" + BookStoreMessageTag.ADDCOPIES;
    exchange.setMethod("POST");
    exchange.setURL(urlString);
    exchange.setRequestContent(requestContent);
    result = BookStoreUtility.SendAndRecv(this.client, exchange);
    this.setSnapshotId(result.getSnapshotId());
  }
  public void updateEditorPicks(Set<BookEditorPick> editorPicksValues) throws BookStoreException {
    ContentExchange exchange = new ContentExchange();
    String urlString = serverAddress + "/" + BookStoreMessageTag.UPDATEEDITORPICKS + "?";

    String xmlStringEditorPicksValues =
        BookStoreUtility.serializeObjectToXMLString(editorPicksValues);

    exchange.setMethod("POST");
    exchange.setURL(urlString);
    Buffer requestContent = new ByteArrayBuffer(xmlStringEditorPicksValues);

    exchange.setRequestContent(requestContent);

    BookStoreUtility.SendAndRecv(this.client, exchange);
  }