field level field data cache should take into account a null listener

also, cleanup the onRemoval code
This commit is contained in:
Shay Banon 2013-11-20 09:31:19 -08:00
parent 1608ccc373
commit f465a6b589
2 changed files with 20 additions and 13 deletions

View File

@ -75,18 +75,22 @@ public interface IndexFieldDataCache {
this.fieldNames = fieldNames;
this.fieldDataType = fieldDataType;
cache.removalListener(this);
//noinspection unchecked
this.cache = cache.build();
}
@Override
public void onRemoval(RemovalNotification<Key, AtomicFieldData> notification) {
if (notification.getKey() != null) {
long sizeInBytes = notification.getKey().sizeInBytes;
if (sizeInBytes == -1 && notification.getValue() != null) {
sizeInBytes = notification.getValue().getMemorySizeInBytes();
}
notification.getKey().listener.onUnload(fieldNames, fieldDataType, notification.wasEvicted(), sizeInBytes, notification.getValue());
Key key = notification.getKey();
if (key == null || key.listener == null) {
return; // we can't do anything here...
}
AtomicFieldData value = notification.getValue();
long sizeInBytes = key.sizeInBytes;
if (sizeInBytes == -1 && value != null) {
sizeInBytes = value.getMemorySizeInBytes();
}
key.listener.onUnload(fieldNames, fieldDataType, notification.wasEvicted(), sizeInBytes, value);
}
@Override

View File

@ -99,14 +99,17 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL
@Override
public void onRemoval(RemovalNotification<Key, AtomicFieldData> notification) {
if (notification.getKey() != null && notification.getKey().listener != null) {
IndexFieldCache indexCache = notification.getKey().indexCache;
long sizeInBytes = notification.getKey().sizeInBytes;
if (sizeInBytes == -1 && notification.getValue() != null) {
sizeInBytes = notification.getValue().getMemorySizeInBytes();
}
notification.getKey().listener.onUnload(indexCache.fieldNames, indexCache.fieldDataType, notification.wasEvicted(), sizeInBytes, notification.getValue());
Key key = notification.getKey();
if (key == null || key.listener == null) {
return; // nothing to do here really...
}
IndexFieldCache indexCache = key.indexCache;
long sizeInBytes = key.sizeInBytes;
AtomicFieldData value = notification.getValue();
if (sizeInBytes == -1 && value != null) {
sizeInBytes = value.getMemorySizeInBytes();
}
key.listener.onUnload(indexCache.fieldNames, indexCache.fieldDataType, notification.wasEvicted(), sizeInBytes, value);
}
public static class FieldDataWeigher implements Weigher<Key, AtomicFieldData> {