OF-1125: StreamID should be Cacheable.

parent baa79d57
...@@ -23,6 +23,9 @@ package org.jivesoftware.openfire.spi; ...@@ -23,6 +23,9 @@ package org.jivesoftware.openfire.spi;
import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringEscapeUtils;
import org.jivesoftware.openfire.StreamID; import org.jivesoftware.openfire.StreamID;
import org.jivesoftware.openfire.StreamIDFactory; import org.jivesoftware.openfire.StreamIDFactory;
import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
import org.jivesoftware.util.cache.CannotCalculateSizeException;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.SecureRandom; import java.security.SecureRandom;
...@@ -54,7 +57,7 @@ public class BasicStreamIDFactory implements StreamIDFactory { ...@@ -54,7 +57,7 @@ public class BasicStreamIDFactory implements StreamIDFactory {
return new BasicStreamID(name); return new BasicStreamID(name);
} }
private static class BasicStreamID implements StreamID { private static class BasicStreamID implements StreamID, Cacheable {
String id; String id;
public BasicStreamID(String id) { public BasicStreamID(String id) {
...@@ -86,5 +89,15 @@ public class BasicStreamIDFactory implements StreamIDFactory { ...@@ -86,5 +89,15 @@ public class BasicStreamIDFactory implements StreamIDFactory {
if ( o == null || getClass() != o.getClass() ) return false; if ( o == null || getClass() != o.getClass() ) return false;
return id.equals( ((BasicStreamID) o).id ); return id.equals( ((BasicStreamID) o).id );
} }
@Override
public int getCachedSize() throws CannotCalculateSizeException
{
// 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(id); // id
return size;
}
} }
} }
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