field level field data cache should take into account a null listener
also, cleanup the onRemoval code
This commit is contained in:
parent
1608ccc373
commit
f465a6b589
|
@ -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();
|
||||
Key key = notification.getKey();
|
||||
if (key == null || key.listener == null) {
|
||||
return; // we can't do anything here...
|
||||
}
|
||||
notification.getKey().listener.onUnload(fieldNames, fieldDataType, notification.wasEvicted(), sizeInBytes, notification.getValue());
|
||||
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
|
||||
|
|
|
@ -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();
|
||||
Key key = notification.getKey();
|
||||
if (key == null || key.listener == null) {
|
||||
return; // nothing to do here really...
|
||||
}
|
||||
notification.getKey().listener.onUnload(indexCache.fieldNames, indexCache.fieldDataType, notification.wasEvicted(), sizeInBytes, notification.getValue());
|
||||
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> {
|
||||
|
|
Loading…
Reference in New Issue