Search in sources :

Example 1 with DestroyRoomRequest

use of org.jivesoftware.openfire.muc.cluster.DestroyRoomRequest in project Openfire by igniterealtime.

the class LocalMUCRoom method destroyRoom.

public void destroyRoom(DestroyRoomRequest destroyRequest) {
    JID alternateJID = destroyRequest.getAlternateJID();
    String reason = destroyRequest.getReason();
    Collection<MUCRole> removedRoles = new ArrayList<>();
    lock.writeLock().lock();
    try {
        boolean hasRemoteOccupants = false;
        // Remove each occupant
        for (MUCRole leaveRole : occupantsByFullJID.values()) {
            if (leaveRole != null) {
                // list of removed occupants to process later outside of the lock.
                if (leaveRole.isLocal()) {
                    removedRoles.add(leaveRole);
                } else {
                    hasRemoteOccupants = true;
                }
                removeOccupantRole(leaveRole, destroyRequest.isOriginator());
            }
        }
        endTime = System.currentTimeMillis();
        // Set that the room has been destroyed
        isDestroyed = true;
        if (destroyRequest.isOriginator()) {
            if (hasRemoteOccupants) {
                // Ask other cluster nodes to remove occupants since room is being destroyed
                CacheFactory.doClusterTask(new DestroyRoomRequest(this, alternateJID, reason));
            }
            // Removes the room from the list of rooms hosted in the service
            mucService.removeChatRoom(name);
        }
    } finally {
        lock.writeLock().unlock();
    }
    // Send an unavailable presence to each removed occupant
    for (MUCRole removedRole : removedRoles) {
        try {
            // Send a presence stanza of type "unavailable" to the occupant
            Presence presence = createPresence(Presence.Type.unavailable);
            presence.setFrom(removedRole.getRoleAddress());
            // A fragment containing the x-extension for room destruction.
            Element fragment = presence.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = fragment.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            if (alternateJID != null) {
                fragment.addElement("destroy").addAttribute("jid", alternateJID.toString());
            }
            if (reason != null && reason.length() > 0) {
                Element destroy = fragment.element("destroy");
                if (destroy == null) {
                    destroy = fragment.addElement("destroy");
                }
                destroy.addElement("reason").setText(reason);
            }
            removedRole.send(presence);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    if (destroyRequest.isOriginator()) {
        // Remove the room from the DB if the room was persistent
        MUCPersistenceManager.deleteFromDB(this);
        // Fire event that the room has been destroyed
        MUCEventDispatcher.roomDestroyed(getRole().getRoleAddress());
    }
}
Also used : MUCRole(org.jivesoftware.openfire.muc.MUCRole) GroupJID(org.jivesoftware.openfire.group.GroupJID) JID(org.xmpp.packet.JID) DestroyRoomRequest(org.jivesoftware.openfire.muc.cluster.DestroyRoomRequest) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Presence(org.xmpp.packet.Presence) UpdatePresence(org.jivesoftware.openfire.muc.cluster.UpdatePresence) ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) RoomLockedException(org.jivesoftware.openfire.muc.RoomLockedException) CannotBeInvitedException(org.jivesoftware.openfire.muc.CannotBeInvitedException) NotAllowedException(org.jivesoftware.openfire.muc.NotAllowedException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) NotFoundException(org.jivesoftware.util.NotFoundException) ConflictException(org.jivesoftware.openfire.muc.ConflictException) RegistrationRequiredException(org.jivesoftware.openfire.muc.RegistrationRequiredException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) IOException(java.io.IOException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) NotAcceptableException(org.jivesoftware.openfire.muc.NotAcceptableException) ServiceUnavailableException(org.jivesoftware.openfire.muc.ServiceUnavailableException)

Example 2 with DestroyRoomRequest

use of org.jivesoftware.openfire.muc.cluster.DestroyRoomRequest in project Openfire by igniterealtime.

the class LocalMUCRoom method destroyRoom.

@Override
public void destroyRoom(JID alternateJID, String reason) {
    DestroyRoomRequest destroyRequest = new DestroyRoomRequest(this, alternateJID, reason);
    destroyRequest.setOriginator(true);
    destroyRequest.run();
}
Also used : DestroyRoomRequest(org.jivesoftware.openfire.muc.cluster.DestroyRoomRequest)

Aggregations

DestroyRoomRequest (org.jivesoftware.openfire.muc.cluster.DestroyRoomRequest)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Element (org.dom4j.Element)1 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1 GroupJID (org.jivesoftware.openfire.group.GroupJID)1 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)1 CannotBeInvitedException (org.jivesoftware.openfire.muc.CannotBeInvitedException)1 ConflictException (org.jivesoftware.openfire.muc.ConflictException)1 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)1 MUCRole (org.jivesoftware.openfire.muc.MUCRole)1 NotAcceptableException (org.jivesoftware.openfire.muc.NotAcceptableException)1 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)1 RegistrationRequiredException (org.jivesoftware.openfire.muc.RegistrationRequiredException)1 RoomLockedException (org.jivesoftware.openfire.muc.RoomLockedException)1 ServiceUnavailableException (org.jivesoftware.openfire.muc.ServiceUnavailableException)1 UpdatePresence (org.jivesoftware.openfire.muc.cluster.UpdatePresence)1 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 NotFoundException (org.jivesoftware.util.NotFoundException)1