Reputation: 9349
Can any one point to a good implementation, if one exists, of what I call Ticking collection/Map
in Java. Where the elements in the collection has some expiry time. When a particular element of the collection is expired then collection raises a certain kind of alarm or call a handler.
I saw a Guava implementation of an expiring map which automatically removes the key which has been expired.
Upvotes: 2
Views: 1525
Reputation: 913
guava supports a callback on eviction:
Cache<String, String> cache = CacheBuilder.newBuilder()
.expireAfterAccess(100, TimeUnit.SECONDS)
.removalListener(new RemovalListener<Object, Object>() {
public void onRemoval(RemovalNotification<Object, Object> objectObjectRemovalNotification) {
//do something
}
})
.build();
Upvotes: 4