Search in sources :

Example 1 with RoomAvailableEvent

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

the class MultiUserChatServiceImpl method getChatRoom.

@Override
public MUCRoom getChatRoom(String roomName) {
    boolean loaded = false;
    LocalMUCRoom room = localMUCRoomManager.getRoom(roomName);
    if (room == null) {
        // Check if the room exists in the databclase and was not present in memory
        synchronized (roomName.intern()) {
            room = localMUCRoomManager.getRoom(roomName);
            if (room == null) {
                room = new LocalMUCRoom(this, roomName, router);
                // If the room is persistent load the configuration values from the DB
                try {
                    // Try to load the room's configuration from the database (if the room is
                    // persistent but was added to the DB after the server was started up or the
                    // room may be an old room that was not present in memory)
                    MUCPersistenceManager.loadFromDB(room);
                    loaded = true;
                    localMUCRoomManager.addRoom(roomName, room);
                } catch (IllegalArgumentException e) {
                    // The room does not exist so do nothing
                    room = null;
                }
            }
        }
    }
    if (loaded) {
        // Notify other cluster nodes that a new room is available
        CacheFactory.doClusterTask(new RoomAvailableEvent(room));
    }
    return room;
}
Also used : RoomAvailableEvent(org.jivesoftware.openfire.muc.cluster.RoomAvailableEvent)

Example 2 with RoomAvailableEvent

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

the class MultiUserChatServiceImpl method getChatRoom.

@Override
public MUCRoom getChatRoom(String roomName, JID userjid) throws NotAllowedException {
    LocalMUCRoom room;
    boolean loaded = false;
    boolean created = false;
    synchronized (roomName.intern()) {
        room = localMUCRoomManager.getRoom(roomName);
        if (room == null) {
            room = new LocalMUCRoom(this, roomName, router);
            // If the room is persistent load the configuration values from the DB
            try {
                // Try to load the room's configuration from the database (if the room is
                // persistent but was added to the DB after the server was started up or the
                // room may be an old room that was not present in memory)
                MUCPersistenceManager.loadFromDB(room);
                loaded = true;
            } catch (IllegalArgumentException e) {
                // (or was deleted somehow and is expected to exist by a delegate).
                if (mucEventDelegate != null && mucEventDelegate.shouldRecreate(roomName, userjid)) {
                    if (mucEventDelegate.loadConfig(room)) {
                        loaded = true;
                        if (room.isPersistent()) {
                            MUCPersistenceManager.saveToDB(room);
                        }
                    } else {
                        // not allow room creation
                        throw new NotAllowedException();
                    }
                } else {
                    // The room does not exist so check for creation permissions
                    // Room creation is always allowed for sysadmin
                    final JID bareJID = userjid.asBareJID();
                    if (isRoomCreationRestricted() && !sysadmins.includes(bareJID)) {
                        // The room creation is only allowed for certain JIDs
                        if (!allowedToCreate.includes(bareJID)) {
                            // an exception
                            throw new NotAllowedException();
                        }
                    }
                    room.addFirstOwner(userjid);
                    created = true;
                }
            }
            localMUCRoomManager.addRoom(roomName, room);
        }
    }
    if (created) {
        // Fire event that a new room has been created
        MUCEventDispatcher.roomCreated(room.getRole().getRoleAddress());
    }
    if (loaded || created) {
        // Notify other cluster nodes that a new room is available
        CacheFactory.doClusterTask(new RoomAvailableEvent(room));
        for (MUCRole role : room.getOccupants()) {
            if (role instanceof LocalMUCRole) {
                CacheFactory.doClusterTask(new OccupantAddedEvent(room, role));
            }
        }
    }
    return room;
}
Also used : MUCRole(org.jivesoftware.openfire.muc.MUCRole) NotAllowedException(org.jivesoftware.openfire.muc.NotAllowedException) GroupJID(org.jivesoftware.openfire.group.GroupJID) RoomAvailableEvent(org.jivesoftware.openfire.muc.cluster.RoomAvailableEvent) OccupantAddedEvent(org.jivesoftware.openfire.muc.cluster.OccupantAddedEvent)

Aggregations

RoomAvailableEvent (org.jivesoftware.openfire.muc.cluster.RoomAvailableEvent)2 GroupJID (org.jivesoftware.openfire.group.GroupJID)1 MUCRole (org.jivesoftware.openfire.muc.MUCRole)1 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)1 OccupantAddedEvent (org.jivesoftware.openfire.muc.cluster.OccupantAddedEvent)1