use of org.jivesoftware.openfire.muc.cluster.ServiceRemovedEvent in project Openfire by igniterealtime.
the class MultiUserChatManager method unregisterMultiUserChatService.
/**
* Unregisters a MultiUserChatService from the manager.
*
* It can be used to explicitly unregister services, and is also used internally to unregister database stored services.
*
* Triggers the service to shut down.
*
* This method has a boolean parameter that controls whether a 'service removed' event is to be sent to all other
* cluster nodes. This generally is desirable when a pre-existing service is being removed. 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 shutting down this instance (as the service might continue to live on
* other cluster nodes).
*
* @param subdomain The subdomain of the service to be unregistered.
* @param allNodes true if a 'service removed' event needs to be sent to other cluster nodes.
* @see #removeMultiUserChatService(String)
*/
public void unregisterMultiUserChatService(@Nonnull final String subdomain, final boolean allNodes) {
Log.debug("Unregistering MUC service '{}'", subdomain);
final MultiUserChatService service = mucServices.remove(subdomain);
if (service != null) {
service.shutdown();
try {
ComponentManagerFactory.getComponentManager().removeComponent(subdomain);
} catch (ComponentException e) {
Log.error("Unable to remove MUC service '{}' from component manager.", subdomain, e);
mucServices.put(subdomain, service);
}
}
if (allNodes) {
Log.trace("Sending 'service removed' event for MUC service '{}' to all other cluster nodes.", subdomain);
CacheFactory.doClusterTask(new ServiceRemovedEvent(subdomain));
}
}
use of org.jivesoftware.openfire.muc.cluster.ServiceRemovedEvent 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);
}
}
Aggregations