[ 
https://issues.apache.org/jira/browse/COLLECTIONS-467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13655585#comment-13655585
 ] 

Thomas Neidhart commented on COLLECTIONS-467:
---------------------------------------------

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

{noformat}
     * 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>
{noformat}

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: https://issues.apache.org/jira/browse/COLLECTIONS-467
>             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: http://www.atlassian.com/software/jira

Reply via email to