Commit 34a68512 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-1430] Finished up cluster support of new muc services.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10774 b35dd754-fafc-0310-a699-88a17e54d16e
parent 59bfb699
...@@ -755,7 +755,6 @@ public class MultiUserChatManager extends BasicModule implements ClusterEventLis ...@@ -755,7 +755,6 @@ public class MultiUserChatManager extends BasicModule implements ClusterEventLis
XMPPServer.getInstance().getMultiUserChatManager().registerMultiUserChatService(service); XMPPServer.getInstance().getMultiUserChatManager().registerMultiUserChatService(service);
} }
// TODO: How do we handle non-default service implemtations properly here?
MultiUserChatServiceImpl serviceImpl = (MultiUserChatServiceImpl)service; MultiUserChatServiceImpl serviceImpl = (MultiUserChatServiceImpl)service;
for (RoomInfo roomInfo : serviceInfo.getRooms()) { for (RoomInfo roomInfo : serviceInfo.getRooms()) {
...@@ -789,7 +788,6 @@ public class MultiUserChatManager extends BasicModule implements ClusterEventLis ...@@ -789,7 +788,6 @@ public class MultiUserChatManager extends BasicModule implements ClusterEventLis
if (result != null) { if (result != null) {
for (RoomInfo roomInfo : result) { for (RoomInfo roomInfo : result) {
LocalMUCRoom remoteRoom = roomInfo.getRoom(); LocalMUCRoom remoteRoom = roomInfo.getRoom();
// TODO: How do we handle non-default service implemtations properly here?
MultiUserChatServiceImpl service = (MultiUserChatServiceImpl)remoteRoom.getMUCService(); MultiUserChatServiceImpl service = (MultiUserChatServiceImpl)remoteRoom.getMUCService();
LocalMUCRoom localRoom = service.getLocalChatRoom(remoteRoom.getName()); LocalMUCRoom localRoom = service.getLocalChatRoom(remoteRoom.getName());
if (localRoom == null) { if (localRoom == null) {
......
/**
* $RCSfile$
* $Revision: $
* $Date: $
*
* Copyright (C) 2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license
* agreement with Jive.
*/
package org.jivesoftware.openfire.muc.cluster;
import org.jivesoftware.util.cache.ClusterTask;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.jivesoftware.openfire.muc.spi.MUCPersistenceManager;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/**
* This task updates or deletes a property in a cluster node's muc service property map.
* {@link org.jivesoftware.openfire.muc.spi.MUCServicePropertyEventListener} of each cluster node will be alerted of the event.
*
* @author Daniel Henninger
*/
public class MUCServicePropertyClusterEventTask implements ClusterTask {
private Type event;
private String service;
private String key;
private String value;
public static MUCServicePropertyClusterEventTask createPutTask(String service, String key, String value) {
MUCServicePropertyClusterEventTask task = new MUCServicePropertyClusterEventTask();
task.event = Type.put;
task.service = service;
task.key = key;
task.value = value;
return task;
}
public static MUCServicePropertyClusterEventTask createDeleteTask(String service, String key) {
MUCServicePropertyClusterEventTask task = new MUCServicePropertyClusterEventTask();
task.event = Type.deleted;
task.service = service;
task.key = key;
return task;
}
public Object getResult() {
return null;
}
public void run() {
if (Type.put == event) {
MUCPersistenceManager.setLocalProperty(service, key, value);
}
else if (Type.deleted == event) {
MUCPersistenceManager.deleteLocalProperty(service, key);
}
}
public void writeExternal(ObjectOutput out) throws IOException {
ExternalizableUtil.getInstance().writeInt(out, event.ordinal());
ExternalizableUtil.getInstance().writeSafeUTF(out, service);
ExternalizableUtil.getInstance().writeSafeUTF(out, key);
ExternalizableUtil.getInstance().writeBoolean(out, value != null);
if (value != null) {
ExternalizableUtil.getInstance().writeSafeUTF(out, value);
}
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
event = Type.values()[ExternalizableUtil.getInstance().readInt(in)];
service = ExternalizableUtil.getInstance().readSafeUTF(in);
key = ExternalizableUtil.getInstance().readSafeUTF(in);
if (ExternalizableUtil.getInstance().readBoolean(in)) {
value = ExternalizableUtil.getInstance().readSafeUTF(in);
}
}
private static enum Type {
/**
* Event triggered when a muc service property was added or updated in the system.
*/
put,
/**
* Event triggered when a muc service property was deleted from the system.
*/
deleted
}
}
...@@ -1216,6 +1216,15 @@ public class MUCPersistenceManager { ...@@ -1216,6 +1216,15 @@ public class MUCPersistenceManager {
propertyMaps.put(subdomain, properties); propertyMaps.put(subdomain, properties);
} }
public static void setLocalProperty(String subdomain, String name, String value) {
MUCServiceProperties properties = propertyMaps.get(subdomain);
if (properties == null) {
properties = new MUCServiceProperties(subdomain);
}
properties.localPut(name, value);
propertyMaps.put(subdomain, properties);
}
/** /**
* Sets multiple Jive properties at once. If a property doesn't already exists, a new * Sets multiple Jive properties at once. If a property doesn't already exists, a new
* one will be created. * one will be created.
...@@ -1248,6 +1257,15 @@ public class MUCPersistenceManager { ...@@ -1248,6 +1257,15 @@ public class MUCPersistenceManager {
propertyMaps.put(subdomain, properties); propertyMaps.put(subdomain, properties);
} }
public static void deleteLocalProperty(String subdomain, String name) {
MUCServiceProperties properties = propertyMaps.get(subdomain);
if (properties == null) {
properties = new MUCServiceProperties(subdomain);
}
properties.localRemove(name);
propertyMaps.put(subdomain, properties);
}
/** /**
* Resets (reloads) the properties for a specified subdomain. * Resets (reloads) the properties for a specified subdomain.
* *
......
...@@ -14,7 +14,9 @@ package org.jivesoftware.openfire.muc.spi; ...@@ -14,7 +14,9 @@ package org.jivesoftware.openfire.muc.spi;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.muc.cluster.MUCServicePropertyClusterEventTask;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -158,7 +160,8 @@ public class MUCServiceProperties implements Map<String, String> { ...@@ -158,7 +160,8 @@ public class MUCServiceProperties implements Map<String, String> {
Map<String, Object> params = Collections.emptyMap(); Map<String, Object> params = Collections.emptyMap();
MUCServicePropertyEventDispatcher.dispatchEvent(subdomain, (String)key, MUCServicePropertyEventDispatcher.EventType.property_deleted, params); MUCServicePropertyEventDispatcher.dispatchEvent(subdomain, (String)key, MUCServicePropertyEventDispatcher.EventType.property_deleted, params);
// TODO: Send cluster update. // Send update to other cluster members.
CacheFactory.doClusterTask(MUCServicePropertyClusterEventTask.createDeleteTask(subdomain, (String) key));
return value; return value;
} }
...@@ -206,7 +209,8 @@ public class MUCServiceProperties implements Map<String, String> { ...@@ -206,7 +209,8 @@ public class MUCServiceProperties implements Map<String, String> {
params.put("value", value); params.put("value", value);
MUCServicePropertyEventDispatcher.dispatchEvent(subdomain, key, MUCServicePropertyEventDispatcher.EventType.property_set, params); MUCServicePropertyEventDispatcher.dispatchEvent(subdomain, key, MUCServicePropertyEventDispatcher.EventType.property_set, params);
// TODO: Send cluster update. // Send update to other cluster members.
CacheFactory.doClusterTask(MUCServicePropertyClusterEventTask.createPutTask(subdomain, key, value));
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment