/**
   * Stops this <tt>ContactSourceService</tt> implementation and prepares it for garbage collection.
   *
   * @see AsyncContactSourceService#stop()
   */
  public void stop() {
    boolean interrupted = false;

    synchronized (queries) {
      while (!queries.isEmpty()) {
        queries.get(0).cancel();
        try {
          queries.wait();
        } catch (InterruptedException iex) {
          interrupted = true;
        }
      }
    }
    if (interrupted) Thread.currentThread().interrupt();
  }
  /**
   * Creates query for the given <tt>searchPattern</tt>.
   *
   * @param queryPattern the pattern to search for
   * @param count maximum number of contact returned
   * @return the created query
   */
  public ContactQuery createContactQuery(Pattern queryPattern, int count) {
    GoogleContactsQuery query = new GoogleContactsQuery(this, queryPattern, count);

    synchronized (queries) {
      queries.add(query);
    }

    return query;
  }
 /**
  * Notifies this <tt>GoogleContactsSourceService</tt> that a specific <tt>GoogleContactsQuery</tt>
  * has stopped.
  *
  * @param query the <tt>GoogleContactsQuery</tt> which has stopped
  */
 void stopped(GoogleContactsQuery query) {
   synchronized (queries) {
     if (queries.remove(query)) queries.notify();
   }
 }
 /**
  * Removes query from the list of queries.
  *
  * @param query the query that will be removed.
  */
 public synchronized void removeQuery(ContactQuery query) {
   if (queries.remove(query)) queries.notify();
 }