if (filter == null) {
filter = CacheEntryFilter.SELECT_ALL_ENTRIES;
}
InternalGroup group = null;
synchronized(this) {
// If this entry is not in the cache anymore then there is nothing
// to do.
if (!inCache) {
return false;
}
// If the filter selects this entry then remove it.
if (filter.select(this)) {
// Remember that the entry is no longer in the cache.
inCache = false;
// Remove the entry from the cache map.
cache.removeFromMap(key);
// Save away the group so that events can be dispatched.
group = this.group;
// It may be that this entry has not yet been added to a group
// before it has been removed.
if (group != null) {
// Remove the entry from the group's entry list and clear the
// group.
group.detachEntry(this);
}
}
}
// Dispatch the events outside the synchronization block so that it
// does not interfere with the normal running of the cache and prevents
// listeners from causing deadlocks, e.g. by calling back into the
// cache.
boolean removed;
if (group == null) {
removed = false;
} else {
removed = true;
// Make sure that the entryRemoved events are generated properly.
group.bubbleEntryRemovedEvent(this);
}
return removed;
}