Ejemplo n.º 1
0
  /**
   * Deletes a topic, including all of its messages and TopicUsers
   *
   * @param topic The topic to delete
   * @param userRequestingDeletion The user who requested the topic be deleted
   * @throws AccessDeniedException
   */
  public void deleteTopic(JMSTopic topic, JMSUser userRequestingDeletion)
      throws AccessDeniedException {
    if (userRequestingDeletion.equals(topic.getOwner())) {
      // If the topic does not contain null fields
      if (isValidTopic(topic)) {
        try {
          Transaction transaction = TransactionHelper.getTransaction(10000l);

          space.takeIfExists(topic, transaction, 3000l);

          deleteAllTopicUsers(topic, transaction);
          MessageService.getMessageService().deleteAllTopicMessages(topic, transaction);

          // Writes a JMSTopicDeleted object so listeners know the
          // topic
          // has been removed
          space.write(new JMSTopicDeleted(topic), transaction, 1000l * 60l);

          transaction.commit();
        } catch (Exception e) {
          e.printStackTrace();
        }
      } else {
        System.err.println(
            "Attempted to delete topic with on or more null fields.  "
                + "Due to how JavaSpaces work, this will delete one at random and is not allowed.");
      }
    } else {
      throw new AccessDeniedException("Only the topic's owner can delete the topic");
    }
  }