Commit 8bdad43b 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@8174 b35dd754-fafc-0310-a699-88a17e54d16e
parent e35a4cea
...@@ -12,10 +12,6 @@ ...@@ -12,10 +12,6 @@
package org.jivesoftware.openfire.roster; package org.jivesoftware.openfire.roster;
import org.jivesoftware.database.JiveID; import org.jivesoftware.database.JiveID;
import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.*; import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.group.Group; import org.jivesoftware.openfire.group.Group;
...@@ -26,10 +22,19 @@ import org.jivesoftware.openfire.session.ClientSession; ...@@ -26,10 +22,19 @@ import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.user.UserAlreadyExistsException; import org.jivesoftware.openfire.user.UserAlreadyExistsException;
import org.jivesoftware.openfire.user.UserNameManager; import org.jivesoftware.openfire.user.UserNameManager;
import org.jivesoftware.openfire.user.UserNotFoundException; import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -45,7 +50,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -45,7 +50,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
@JiveID(JiveConstants.ROSTER) @JiveID(JiveConstants.ROSTER)
public class Roster implements Cacheable { public class Roster implements Cacheable, Externalizable {
/** /**
* Roster item cache - table: key jabberid string; value roster item. * Roster item cache - table: key jabberid string; value roster item.
...@@ -69,6 +74,12 @@ public class Roster implements Cacheable { ...@@ -69,6 +74,12 @@ public class Roster implements Cacheable {
private RosterManager rosterManager; private RosterManager rosterManager;
/**
* Constructor added for Externalizable. Do not use this constructor.
*/
public Roster() {
}
/** /**
* Create a roster for the given user, pulling the existing roster items * Create a roster for the given user, pulling the existing roster items
* out of the backend storage provider. The roster will also include items that * out of the backend storage provider. The roster will also include items that
...@@ -87,6 +98,7 @@ public class Roster implements Cacheable { ...@@ -87,6 +98,7 @@ public class Roster implements Cacheable {
presenceManager = XMPPServer.getInstance().getPresenceManager(); presenceManager = XMPPServer.getInstance().getPresenceManager();
rosterManager = XMPPServer.getInstance().getRosterManager(); rosterManager = XMPPServer.getInstance().getRosterManager();
sessionManager = SessionManager.getInstance(); sessionManager = SessionManager.getInstance();
routingTable = XMPPServer.getInstance().getRoutingTable();
this.username = username; this.username = username;
// Get the shared groups of this user // Get the shared groups of this user
...@@ -553,9 +565,6 @@ public class Roster implements Cacheable { ...@@ -553,9 +565,6 @@ public class Roster implements Cacheable {
* @param packet The presence packet to broadcast * @param packet The presence packet to broadcast
*/ */
public void broadcastPresence(Presence packet) { public void broadcastPresence(Presence packet) {
if (routingTable == null) {
routingTable = XMPPServer.getInstance().getRoutingTable();
}
if (routingTable == null) { if (routingTable == null) {
return; return;
} }
...@@ -1092,4 +1101,22 @@ public class Roster implements Cacheable { ...@@ -1092,4 +1101,22 @@ public class Roster implements Cacheable {
private JID getUserJID() { private JID getUserJID() {
return XMPPServer.getInstance().createJID(getUsername(), null); return XMPPServer.getInstance().createJID(getUsername(), null);
} }
public void writeExternal(ObjectOutput out) throws IOException {
ExternalizableUtil.getInstance().writeSafeUTF(out, username);
ExternalizableUtil.getInstance().writeExternalizableMap(out, rosterItems);
ExternalizableUtil.getInstance().writeStringsMap(out, implicitFrom);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
presenceManager = XMPPServer.getInstance().getPresenceManager();
rosterManager = XMPPServer.getInstance().getRosterManager();
sessionManager = SessionManager.getInstance();
rosterItemProvider = RosterItemProvider.getInstance();
routingTable = XMPPServer.getInstance().getRoutingTable();
username = ExternalizableUtil.getInstance().readSafeUTF(in);
ExternalizableUtil.getInstance().readExternalizableMap(in, rosterItems, getClass().getClassLoader());
ExternalizableUtil.getInstance().readStringsMap(in, implicitFrom);
}
} }
\ No newline at end of file
...@@ -11,17 +11,22 @@ ...@@ -11,17 +11,22 @@
package org.jivesoftware.openfire.roster; package org.jivesoftware.openfire.roster;
import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
import org.jivesoftware.util.IntEnum;
import org.jivesoftware.openfire.SharedGroupException; import org.jivesoftware.openfire.SharedGroupException;
import org.jivesoftware.openfire.group.Group; import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager; import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException; import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.jivesoftware.openfire.user.UserNameManager; import org.jivesoftware.openfire.user.UserNameManager;
import org.jivesoftware.openfire.user.UserNotFoundException; import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.IntEnum;
import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.*; import java.util.*;
/** /**
...@@ -39,7 +44,7 @@ import java.util.*; ...@@ -39,7 +44,7 @@ import java.util.*;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class RosterItem implements Cacheable { public class RosterItem implements Cacheable, Externalizable {
public static class SubType extends IntEnum { public static class SubType extends IntEnum {
protected SubType(String name, int value) { protected SubType(String name, int value) {
...@@ -137,6 +142,12 @@ public class RosterItem implements Cacheable { ...@@ -137,6 +142,12 @@ public class RosterItem implements Cacheable {
*/ */
private long rosterID; private long rosterID;
/**
* Constructor added for Externalizable. Do not use this constructor.
*/
public RosterItem() {
}
public RosterItem(long id, public RosterItem(long id,
JID jid, JID jid,
SubType subStatus, SubType subStatus,
...@@ -168,9 +179,9 @@ public class RosterItem implements Cacheable { ...@@ -168,9 +179,9 @@ public class RosterItem implements Cacheable {
} }
/** /**
* <p>Create a roster item from the data in another one.</p> * Create a roster item from the data in another one.
* *
* @param item * @param item Item that contains the info of the roster item.
*/ */
public RosterItem(org.xmpp.packet.Roster.Item item) { public RosterItem(org.xmpp.packet.Roster.Item item) {
this(item.getJID(), this(item.getJID(),
...@@ -317,9 +328,10 @@ public class RosterItem implements Cacheable { ...@@ -317,9 +328,10 @@ public class RosterItem implements Cacheable {
} }
/** /**
* <p>Set the current groups for the item.</p> * Set the current groups for the item.
* *
* @param groups The new lists of groups the item belongs to. * @param groups The new lists of groups the item belongs to.
* @throws org.jivesoftware.openfire.SharedGroupException if trying to remove shared group.
*/ */
public void setGroups(List<String> groups) throws SharedGroupException { public void setGroups(List<String> groups) throws SharedGroupException {
if (groups == null) { if (groups == null) {
...@@ -507,6 +519,7 @@ public class RosterItem implements Cacheable { ...@@ -507,6 +519,7 @@ public class RosterItem implements Cacheable {
* <p>A convenience for getting the item and setting each attribute.</p> * <p>A convenience for getting the item and setting each attribute.</p>
* *
* @param item The item who's settings will be copied into the cached copy * @param item The item who's settings will be copied into the cached copy
* @throws org.jivesoftware.openfire.SharedGroupException if trying to remove shared group.
*/ */
public void setAsCopyOf(org.xmpp.packet.Roster.Item item) throws SharedGroupException { public void setAsCopyOf(org.xmpp.packet.Roster.Item item) throws SharedGroupException {
setGroups(new LinkedList<String>(item.getGroups())); setGroups(new LinkedList<String>(item.getGroups()));
...@@ -522,4 +535,34 @@ public class RosterItem implements Cacheable { ...@@ -522,4 +535,34 @@ public class RosterItem implements Cacheable {
size += CacheSizes.sizeOfLong(); // id size += CacheSizes.sizeOfLong(); // id
return size; return size;
} }
public void writeExternal(ObjectOutput out) throws IOException {
ExternalizableUtil.getInstance().writeSafeUTF(out, jid.toString());
ExternalizableUtil.getInstance().writeBoolean(out, nickname != null);
if (nickname != null) {
ExternalizableUtil.getInstance().writeSafeUTF(out, nickname);
}
ExternalizableUtil.getInstance().writeStrings(out, groups);
ExternalizableUtil.getInstance().writeStrings(out, sharedGroups);
ExternalizableUtil.getInstance().writeStrings(out, invisibleSharedGroups);
ExternalizableUtil.getInstance().writeInt(out, recvStatus.getValue());
ExternalizableUtil.getInstance().writeInt(out, subStatus.getValue());
ExternalizableUtil.getInstance().writeInt(out, askStatus.getValue());
ExternalizableUtil.getInstance().writeLong(out, rosterID);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
jid = new JID(ExternalizableUtil.getInstance().readSafeUTF(in));
if (ExternalizableUtil.getInstance().readBoolean(in)) {
nickname = ExternalizableUtil.getInstance().readSafeUTF(in);
}
this.groups = new LinkedList<String>();
ExternalizableUtil.getInstance().readStrings(in, groups);
ExternalizableUtil.getInstance().readStrings(in, sharedGroups);
ExternalizableUtil.getInstance().readStrings(in, invisibleSharedGroups);
recvStatus = RecvType.getTypeFromInt(ExternalizableUtil.getInstance().readInt(in));
subStatus = SubType.getTypeFromInt(ExternalizableUtil.getInstance().readInt(in));
askStatus = AskType.getTypeFromInt(ExternalizableUtil.getInstance().readInt(in));
rosterID = ExternalizableUtil.getInstance().readLong(in);
}
} }
\ No newline at end of file
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