/**
  * Returns all the published publication names
  *
  * @return String Array of all publication names
  */
 public String[] getPublicationNames() {
   String[] ret = new String[publications.size()];
   for (int i = 0; i < publications.size(); i++) {
     DynPublication publication = publications.get(i);
     ret[i] = publication.getIdentifier();
   }
   return ret;
 }
 /**
  * Recall and remove the provided Publication from the System
  *
  * @param publication
  */
 public void recall(DynPublication publication) {
   // Debugger.debug(getClass(), "try to recall publication. has Subscriptions: " +
   // publication.hasSubscriptions());
   while (publication.hasSubscriptions()) {
     // Debugger.debug(getClass(), "Disconnect subscription...");
     DynSubscription subscription = publication.removeNextSubscription();
     subscription.subscriber.publicationDisonnected(name, subscription);
     subscription.set(null);
   }
   publications.remove(publication);
 }
 /**
  * Recall and remove the Publication with the provided identifier from the System
  *
  * @param publicationname
  */
 public void recall(String publicationname) {
   Iterator<DynPublication> i = publications.iterator();
   while (i.hasNext()) {
     DynPublication publication = i.next();
     if (publication.identifier.equals(publicationname)) {
       while (publication.hasSubscriptions()) {
         DynSubscription subscription = publication.removeNextSubscription();
         subscription.subscriber.publicationDisonnected(name, subscription);
         subscription.set(null);
       }
       i.remove();
     }
   }
 }
 /**
  * Subscribe and try to connect the provided Subscription.
  *
  * <p>Careful: Calling this method does NOT guarantee to have a valid connection to a publication.
  * It only means, that the request to subscribe was registered and it tries to connect if there is
  * a matching publication.
  *
  * <p>VERY Careful: If a valid connection can be established this method calls directly the
  * Subscribers publicationConnected() method and returns once that method returns.
  *
  * @param subscription
  * @return true if a successful connection to a publication could be established
  */
 public boolean subscribe(DynSubscription subscription) {
   if (!subscriptions.contains(subscription)) {
     subscriptions.add(subscription);
     if (!subscription.isConnected()) {
       Iterator<DynPublication> i = publications.iterator();
       while (i.hasNext()) {
         DynPublication publication = i.next();
         if (subscription.equalsIdentifier(publication)) {
           subscription.set(publication);
           publication.addSubscription(subscription);
           subscription.subscriber.publicationConnected(name, subscription);
           publication.publisher.subscriptionConnected(name, subscription);
           return true;
         }
       }
     }
   }
   return false;
 }
  /**
   * Publish the provided Publication
   *
   * <p>Careful: Calling this method does NOT guarantee to have a valid connection to a
   * subscription. It only means, that the publication is registered and it tries to connect if
   * there is a matching subscription.
   *
   * <p>VERY Careful: If a valid connection can be established this method calls directly the
   * Publishers subscriptionConnected() method and returns once that method returns.
   *
   * @param publication
   * @throws DynException if the Publications identifier has already been taken
   */
  public void publish(DynPublication publication) throws DynException {
    //		Debugger.debug(getClass(), "try to publish publication: " + publication.getIdentifier());
    // First check if this pointers name has been already taken
    Iterator<DynPublication> p = publications.iterator();
    while (p.hasNext()) {
      if (p.next().identifier.equals(publication.identifier))
        throw new DynException("Publication name already taken: " + publication.identifier);
    }

    publications.add(publication);

    Iterator<DynSubscription> i = subscriptions.iterator();
    while (i.hasNext()) {
      DynSubscription subscription = i.next();
      if (!subscription.isConnected() && subscription.equalsIdentifier(publication)) {
        publication.addSubscription(subscription);
        subscription.set(publication);
        publication.publisher.subscriptionConnected(name, subscription);
        subscription.subscriber.publicationConnected(name, subscription);
      }
    }
  }