Search in sources :

Example 1 with ServiceAddedEvent

use of org.jivesoftware.openfire.muc.cluster.ServiceAddedEvent 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)

Example 2 with ServiceAddedEvent

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

the class MultiUserChatManager method registerMultiUserChatService.

/**
 * Registers a new MultiUserChatService implementation to the manager.
 *
 * This is typically used if you have a custom MUC implementation that you want to register with the manager. In
 * other words, it may not be database stored and may follow special rules, implementing MultiUserChatService.
 * It is also used internally to register services from the database.
 *
 * Triggers the service to start up.
 *
 * This method has a boolean parameter that controls whether a 'new service added' event is to be sent to all other
 * cluster nodes. This generally is desirable when a new service is being created. A reason to _not_ send such an
 * event is when this method is being invoked as a result of receiving/processing such an event that was received
 * from another cluster node, or when initializing this instance from database content (which will occur on all
 * cluster nodes).
 *
 * @param service The MultiUserChatService to be registered.
 * @param allNodes true if a 'service added' event needs to be sent to other cluster nodes.
 * @see #createMultiUserChatService(String, String, boolean)
 */
public void registerMultiUserChatService(@Nonnull final MultiUserChatService service, final boolean allNodes) {
    Log.debug("Registering MUC service '{}'", service.getServiceName());
    try {
        ComponentManagerFactory.getComponentManager().addComponent(service.getServiceName(), service);
        mucServices.put(service.getServiceName(), service);
    } catch (ComponentException e) {
        Log.error("Unable to register MUC service '{}' as a component.", service.getServiceName(), e);
    }
    if (allNodes) {
        Log.trace("Sending 'service added' event for MUC service '{}' to all other cluster nodes.", service.getServiceName());
        CacheFactory.doClusterTask(new ServiceAddedEvent(service.getServiceName(), service.getDescription(), service.isHidden()));
    }
}
Also used : ServiceAddedEvent(org.jivesoftware.openfire.muc.cluster.ServiceAddedEvent) ComponentException(org.xmpp.component.ComponentException)

Aggregations

ServiceAddedEvent (org.jivesoftware.openfire.muc.cluster.ServiceAddedEvent)2 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 ComponentException (org.xmpp.component.ComponentException)1