commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <>
Subject [jira] [Commented] (COLLECTIONS-467) LRUMap remove callback
Date Sun, 12 May 2013 17:17:16 GMT


Thomas Neidhart commented on COLLECTIONS-467:

The LRUMap already provides a functionality for this, see the javadoc of the removeLRU method:

     * Subclass method to control removal of the least recently used entry from the map.
     * <p>
     * This method exists for subclasses to override. A subclass may wish to
     * provide cleanup of resources when an entry is removed. For example:
     * <pre>
     * protected boolean removeLRU(LinkEntry entry) {
     *   releaseResources(entry.getValue());  // release resources held by entry
     *   return true;  // actually delete entry
     * }
     * </pre>

This method is protected and can be overriden by subclasses in the same way as your proposed
onAdd and onRemove methods.

In case you deliberately remove elements with remove / clear, you are aware of the element
removal, so you can take care of releasing the resources imho (or at least override remove/clear
in such a case if you prefer that).

There is another proposal for a TrackingCollection (see COLLECTIONS-248) which is somehow
similar, in the sense that it keeps track of all additions/removals to a collection. Maybe
it would make sense to add such a MapDecorator.
> LRUMap remove callback
> ----------------------
>                 Key: COLLECTIONS-467
>                 URL:
>             Project: Commons Collections
>          Issue Type: New Feature
>    Affects Versions: 3.2
>            Reporter: l0co
>            Priority: Minor
> If you use LRUMap with objects that require doing some disposal when they are dropped
(eg. close()) and you hold these objects only in LRUMap, you cannot do it with current implementation.
I propose to add onRemove() and onAdd() methods to the implementation, so that you can create
anonymous inherited class and be able to react to these events.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message