Example #1
0
 /**
  * Returns a Group by name.
  *
  * @param name The name of the group to retrieve
  * @return The group corresponding to that name
  * @throws GroupNotFoundException if the group does not exist.
  */
 public Group getGroup(String name) throws GroupNotFoundException {
   Group group = (Group) groupCache.get(name);
   // If ID wan't found in cache, load it up and put it there.
   if (group == null) {
     synchronized (name.intern()) {
       group = (Group) groupCache.get(name);
       // If ID wan't found in cache, load it up and put it there.
       if (group == null) {
         group = provider.getGroup(name);
         groupCache.put(name, group);
       }
     }
   }
   return group;
 }
Example #2
0
 /**
  * Returns the roster for the given username.
  *
  * @param username the username to search for.
  * @return the roster associated with the ID.
  * @throws org.jivesoftware.messenger.user.UserNotFoundException if the ID does not correspond to
  *     a known entity on the server.
  */
 public Roster getRoster(String username) throws UserNotFoundException {
   if (rosterCache == null) {
     rosterCache = CacheManager.getCache("username2roster");
   }
   if (rosterCache == null) {
     throw new UserNotFoundException("Could not load caches");
   }
   Roster roster = (Roster) rosterCache.get(username);
   if (roster == null) {
     // Not in cache so load a new one:
     roster = new Roster(username);
     rosterCache.put(username, roster);
   }
   if (roster == null) {
     throw new UserNotFoundException(username);
   }
   return roster;
 }
Example #3
0
  /**
   * Deletes a group from the system.
   *
   * @param group the group to delete.
   */
  public void deleteGroup(Group group) {
    // Fire event.
    GroupEventDispatcher.dispatchEvent(
        group, GroupEventDispatcher.EventType.group_deleting, Collections.emptyMap());

    // Delete the group.
    provider.deleteGroup(group.getName());

    // Expire all relevant caches.
    groupCache.remove(group.getName());
  }
Example #4
0
  /**
   * Factory method for creating a new Group. A unique name is the only required field.
   *
   * @param name the new and unique name for the group.
   * @return a new Group.
   * @throws GroupAlreadyExistsException if the group name already exists in the system.
   */
  public Group createGroup(String name) throws GroupAlreadyExistsException {
    synchronized (name.intern()) {
      Group newGroup = null;
      try {
        getGroup(name);
        // The group already exists since now exception, so:
        throw new GroupAlreadyExistsException();
      } catch (GroupNotFoundException unfe) {
        // The group doesn't already exist so we can create a new group
        newGroup = provider.createGroup(name);
        groupCache.put(name, newGroup);

        // Fire event.
        GroupEventDispatcher.dispatchEvent(
            newGroup, GroupEventDispatcher.EventType.group_created, Collections.emptyMap());
      }
      return newGroup;
    }
  }