Search in sources :

Example 1 with ServiceUpdatedEvent

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

the class MultiUserChatManager method updateMultiUserChatService.

/**
 * Updates the configuration of a MUC service.
 *
 * This is more involved than it may seem.
 *
 * If the subdomain is changed, we need to shut down the old service and start up the new one, registering
 * the new subdomain and cleaning up the old one.
 *
 * Properties are tied to the ID, which will not change.
 *
 * @param serviceID The ID of the service to be updated.
 * @param subdomain New subdomain to assign to the service.
 * @param description New description to assign to the service.
 * @throws NotFoundException if service was not found.
 */
public void updateMultiUserChatService(final long serviceID, @Nonnull final String subdomain, @Nullable final String description) throws NotFoundException {
    final MultiUserChatServiceImpl muc = (MultiUserChatServiceImpl) getMultiUserChatService(serviceID);
    if (muc == null) {
        // A NotFoundException is thrown if the specified service was not found.
        Log.info("Unable to find service to update for {}", serviceID);
        throw new NotFoundException();
    }
    Log.info("Updating MUC service '{}'", subdomain);
    final String oldSubdomain = muc.getServiceName();
    if (!mucServices.containsKey(oldSubdomain)) {
        // This should never occur, but just in case...
        throw new NotFoundException();
    }
    if (oldSubdomain.equals(subdomain)) {
        // Alright, all we're changing is the description. This is easy.
        updateService(serviceID, subdomain, description);
        // Update the existing service's description.
        muc.setDescription(description);
        // Broadcast change to other cluster nodes (OF-2164)
        CacheFactory.doSynchronousClusterTask(new ServiceUpdatedEvent(subdomain), false);
    } else {
        // Changing the subdomain, here's where it   gets complex.
        // Unregister existing muc service
        unregisterMultiUserChatService(subdomain, false);
        // Update the information stored about the MUC service
        updateService(serviceID, subdomain, description);
        // Create new MUC service with new settings
        final MultiUserChatService replacement = new MultiUserChatServiceImpl(subdomain, description, muc.isHidden());
        // Register to new service
        registerMultiUserChatService(replacement, false);
        // Broadcast change(s) to other cluster nodes (OF-2164)
        CacheFactory.doSynchronousClusterTask(new ServiceAddedEvent(subdomain, description, muc.isHidden()), false);
        CacheFactory.doSynchronousClusterTask(new ServiceRemovedEvent(oldSubdomain), false);
    }
}
Also used : ServiceAddedEvent(org.jivesoftware.openfire.muc.cluster.ServiceAddedEvent) ServiceRemovedEvent(org.jivesoftware.openfire.muc.cluster.ServiceRemovedEvent) ServiceUpdatedEvent(org.jivesoftware.openfire.muc.cluster.ServiceUpdatedEvent) MultiUserChatServiceImpl(org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl) NotFoundException(org.jivesoftware.util.NotFoundException)

Aggregations

ServiceAddedEvent (org.jivesoftware.openfire.muc.cluster.ServiceAddedEvent)1 ServiceRemovedEvent (org.jivesoftware.openfire.muc.cluster.ServiceRemovedEvent)1 ServiceUpdatedEvent (org.jivesoftware.openfire.muc.cluster.ServiceUpdatedEvent)1 MultiUserChatServiceImpl (org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl)1 NotFoundException (org.jivesoftware.util.NotFoundException)1