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

l0co commented on COLLECTIONS-467:
----------------------------------

Hello, thanks for answering.

Yes, I've seen removeLRU() but it looked not so well for me because it is 
triggered only for LRU removal, not for all possible removals. This forces the 
user to write the cleanup code when the item is removed for other reasons 
separately. Much better would be to have single onRemove() / onAdd() for all 
usages.

However, the tracking collection concept looks very nice. It's should be 
extended to maps, though.

Anyway, for my purpose I needed to rewrite some of concepts contained in apache 
collection, and it looks that the best architecture to achieve various Map 
extension is a wrapper/delegate pattern. You can work on a simple base Map 
instance (eg. HashMap, LinkedHashMap - depending on what you need exactly) and 
use the AbstractMapDecorator to add some behavior. Currently I can see 
following useful decorators:
 * TrackingMapDecorator - would be nice to implemented onAdd() / onRemove() 
callbacks to any Map (what we discuss here, like the tracking collection 
concept)
 * LRUMapDecorator - provides the LRU cache function
 * TimeoutMapDecorator - another useful implementation for caches, removing the 
items from base Map after some timeout
                
> 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