Commit 2260aded authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Modified to implement the Cacheable interface. JM-726

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4074 b35dd754-fafc-0310-a699-88a17e54d16e
parent c35bff4d
......@@ -12,12 +12,13 @@
package org.jivesoftware.wildfire.privacy;
import org.dom4j.Element;
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.Cacheable;
import org.jivesoftware.wildfire.roster.Roster;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.*;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
......@@ -26,7 +27,7 @@ import java.util.Collections;
*
* @author Gaston Dombiak
*/
class PrivacyItem implements Serializable, Comparable {
class PrivacyItem implements Cacheable, Comparable {
private int order;
private boolean allow;
......@@ -225,6 +226,29 @@ class PrivacyItem implements Serializable, Comparable {
return false;
}
public int getCachedSize() {
// Approximate the size of the object in bytes by calculating the size
// of each field.
int size = 0;
size += CacheSizes.sizeOfObject(); // overhead of object
size += CacheSizes.sizeOfInt(); // order
size += CacheSizes.sizeOfBoolean(); // allow
//size += CacheSizes.sizeOfString(jidValue.toString()); // type
if (jidValue != null ) {
size += CacheSizes.sizeOfString(jidValue.toString()); // jidValue
}
//size += CacheSizes.sizeOfString(name); // subscriptionValue
if (groupValue != null) {
size += CacheSizes.sizeOfString(groupValue); // groupValue
}
size += CacheSizes.sizeOfBoolean(); // filterEverything
size += CacheSizes.sizeOfBoolean(); // filterIQ
size += CacheSizes.sizeOfBoolean(); // filterMessage
size += CacheSizes.sizeOfBoolean(); // filterPresence_in
size += CacheSizes.sizeOfBoolean(); // filterPresence_out
return size;
}
/**
* Type defines if the rule is based on JIDs, roster groups or presence subscription types.
*/
......
......@@ -13,6 +13,8 @@ package org.jivesoftware.wildfire.privacy;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.Cacheable;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.roster.Roster;
......@@ -20,7 +22,6 @@ import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -37,7 +38,7 @@ import java.util.List;
*
* @author Gaston Dombiak
*/
public class PrivacyList implements Serializable {
public class PrivacyList implements Cacheable {
private JID userJID;
private String name;
......@@ -158,6 +159,21 @@ public class PrivacyList implements Serializable {
Collections.sort(items);
}
public int getCachedSize() {
// Approximate the size of the object in bytes by calculating the size
// of each field.
int size = 0;
size += CacheSizes.sizeOfObject(); // overhead of object
size += CacheSizes.sizeOfString(userJID.toString()); // userJID
size += CacheSizes.sizeOfString(name); // name
size += CacheSizes.sizeOfBoolean(); // isDefault
size += CacheSizes.sizeOfCollection(items); // items of the list
if (roster != null) {
size += roster.getCachedSize(); // add size of roster
}
return size;
}
public int hashCode() {
return name.hashCode();
}
......
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