/**
  * Stores the received subscription and notifies all waiting on this object
  *
  * @param evt the SubscriptionEvent containing the corresponding contact
  */
 public void subscriptionResolved(SubscriptionEvent evt) {
   synchronized (this) {
     logger.debug("Collected evt(" + collectedEvents.size() + ")= " + evt);
     collectedEvents.add(evt);
     notifyAll();
   }
 }
 /**
  * Stores the received subscription and notifies all waiting on this object
  *
  * @param evt the SubscriptionEvent containing the corresponding contact
  */
 public void contactModified(ContactPropertyChangeEvent evt) {
   synchronized (this) {
     logger.debug("Collected evt(" + collectedEvents.size() + ")= " + evt);
     collectedEvents.add(evt);
     notifyAll();
   }
 }
 public void providerStatusMessageChanged(PropertyChangeEvent evt) {
   synchronized (this) {
     logger.debug("Collected stat.msg. evt(" + collectedPresEvents.size() + ")= " + evt);
     collectedStatMsgEvents.add(evt);
     notifyAll();
   }
 }
 public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt) {
   synchronized (this) {
     logger.debug("Collected evt(" + collectedPresEvents.size() + ")= " + evt);
     collectedPresEvents.add(evt);
     notifyAll();
   }
 }
    /**
     * Stores the received status change event and notifies all waiting on this object
     *
     * @param evt the SubscriptionEvent containing the corresponding contact
     */
    public void contactPresenceStatusChanged(ContactPresenceStatusChangeEvent evt) {
      synchronized (this) {
        // if the user has specified event details and the received
        // event does not match - then ignore it.
        if (this.trackedScreenName != null
            && !evt.getSourceContact().getAddress().equals(trackedScreenName)) return;
        if (status != null && status != evt.getNewStatus()) return;

        logger.debug("Collected evt(" + collectedEvents.size() + ")= " + evt);
        collectedEvents.add(evt);
        notifyAll();
      }
    }
    /**
     * Blocks until at least one status message event is received or until waitFor milliseconds pass
     * (whichever happens first).
     *
     * @param waitFor the number of milliseconds that we should be waiting for a status message
     *     event before simply bailing out.
     */
    public void waitForStatMsgEvent(long waitFor) {
      logger.trace("Waiting for a provider status message event.");
      synchronized (this) {
        if (collectedStatMsgEvents.size() > 0) {
          logger.trace("Stat msg. evt already received. " + collectedStatMsgEvents);
          return;
        }

        try {
          wait(waitFor);
          if (collectedStatMsgEvents.size() > 0) logger.trace("Received a prov. stat. msg. evt.");
          else logger.trace("No prov. stat msg. received for " + waitFor + "ms.");
        } catch (InterruptedException ex) {
          logger.debug("Interrupted while waiting for a status msg evt", ex);
        }
      }
    }
    /**
     * Blocks until at least one event is received or until waitFor milliseconds pass (whichever
     * happens first).
     *
     * @param waitFor the number of milliseconds that we should be waiting for an event before
     *     simply bailing out.
     */
    public void waitForPresEvent(long waitFor) {
      logger.trace("Waiting for a change in provider status.");
      synchronized (this) {
        if (collectedPresEvents.size() > 0) {
          logger.trace("Change already received. " + collectedPresEvents);
          return;
        }

        try {
          wait(waitFor);
          if (collectedPresEvents.size() > 0) logger.trace("Received a change in provider status.");
          else logger.trace("No change received for " + waitFor + "ms.");
        } catch (InterruptedException ex) {
          logger.debug("Interrupted while waiting for a provider evt", ex);
        }
      }
    }
    /**
     * Blocks until at least one event is received or until waitFor milliseconds pass (whichever
     * happens first).
     *
     * @param waitFor the number of milliseconds that we should be waiting for an event before
     *     simply bailing out.
     */
    public void waitForEvent(long waitFor) {
      synchronized (this) {
        if (collectedEvents.size() > 0) return;

        try {
          wait(waitFor);
        } catch (InterruptedException ex) {
          logger.debug("Interrupted while waiting for a subscription evt", ex);
        }
      }
    }