Commit 4d814ba2 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Made it clusterable.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8147 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1956ae16
......@@ -14,12 +14,16 @@ package org.jivesoftware.openfire.group;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.xmpp.packet.JID;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -38,7 +42,7 @@ import java.util.concurrent.ConcurrentHashMap;
*
* @author Matt Tucker
*/
public class Group implements Cacheable {
public class Group implements Cacheable, Externalizable {
private static final String LOAD_PROPERTIES =
"SELECT name, propValue FROM jiveGroupProp WHERE groupName=?";
......@@ -88,6 +92,12 @@ public class Group implements Cacheable {
return groupNames;
}
/**
* Constructor added for Externalizable. Do not use this constructor.
*/
public Group() {
}
/**
* Constructs a new group. Note: this constructor is intended for implementors of the
* {@link GroupProvider} interface. To create a new group, use the
......@@ -320,16 +330,16 @@ public class Group implements Cacheable {
}
public Iterator<JID> iterator() {
return new Iterator() {
return new Iterator<JID>() {
Iterator<JID> iter = users.iterator();
Object current = null;
JID current = null;
public boolean hasNext() {
return iter.hasNext();
}
public Object next() {
public JID next() {
current = iter.next();
return current;
}
......@@ -342,7 +352,7 @@ public class Group implements Cacheable {
if (provider.isReadOnly()) {
return;
}
JID user = (JID)current;
JID user = current;
// Remove the user from the collection in memory.
iter.remove();
// Remove the group user from the backend store.
......@@ -603,4 +613,24 @@ public class Group implements Cacheable {
DbConnectionManager.closeConnection(pstmt, con);
}
}
public void writeExternal(ObjectOutput out) throws IOException {
ExternalizableUtil.getInstance().writeSafeUTF(out, name);
if (description != null) {
ExternalizableUtil.getInstance().writeSafeUTF(out, description);
}
ExternalizableUtil.getInstance().writeExternalizableCollection(out, members);
ExternalizableUtil.getInstance().writeExternalizableCollection(out, administrators);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
name = ExternalizableUtil.getInstance().readSafeUTF(in);
if (ExternalizableUtil.getInstance().readBoolean(in)) {
description = ExternalizableUtil.getInstance().readSafeUTF(in);
}
members= new HashSet<JID>();
administrators = new HashSet<JID>();
ExternalizableUtil.getInstance().readExternalizableCollection(in, members, getClass().getClassLoader());
ExternalizableUtil.getInstance().readExternalizableCollection(in, administrators, getClass().getClassLoader());
}
}
\ No newline at end of file
......@@ -11,15 +11,15 @@
package org.jivesoftware.openfire.group;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.event.GroupEventListener;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.xmpp.packet.JID;
import java.util.Collection;
......@@ -96,22 +96,37 @@ public class GroupManager {
groupMetaCache.clear();
}
}
// Set object again in cache. This is done so that other cluster nodes
// get refreshed with latest version of the object
groupCache.put(group.getName(), group);
}
public void memberAdded(Group group, Map params) {
groupMetaCache.clear();
// Set object again in cache. This is done so that other cluster nodes
// get refreshed with latest version of the object
groupCache.put(group.getName(), group);
}
public void memberRemoved(Group group, Map params) {
groupMetaCache.clear();
// Set object again in cache. This is done so that other cluster nodes
// get refreshed with latest version of the object
groupCache.put(group.getName(), group);
}
public void adminAdded(Group group, Map params) {
groupMetaCache.clear();
// Set object again in cache. This is done so that other cluster nodes
// get refreshed with latest version of the object
groupCache.put(group.getName(), group);
}
public void adminRemoved(Group group, Map params) {
groupMetaCache.clear();
// Set object again in cache. This is done so that other cluster nodes
// get refreshed with latest version of the object
groupCache.put(group.getName(), group);
}
});
......
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