• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Filter + java.util.Map or java.util.List

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

any ideas on this would be great,

I need to do some checking on requests that are going through a web application,
The checks are to see if the User-Agent header has changed for a specific user id within the last 30 minutes,

So I'm thinking of creating a filter and with some logic in the filter for checking to see if the User-Agent header has changed for the user id,

I'm thinking of creating a Map with the key being the userId and the value being a DTO that contains a list of the userIds that a userId has used,

But is there a way of setting the value to be against a timestamp and if the user hasnt used different User-Agents over a certain amount of time then that userId is removed from the Map or List,

Thanks in Advance for any and all advice :)

Cheers,

Niall
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There isn't a built in way, so you will have to build your own. The basic strategy would be to have a Map that had a java.util.Timer running in it. Each DTO is immutable, so every change requires a replacement in the Map (instead of an in-place modification). Each new change adds a task to the timer to remove the DTO from the Map at the expiry time. Removing an item from the Map would also need to cancel the associated task from the Timer (and each replacement would need to be a delete from the Map followed by an Add).

This sounds a lot like a time-sensitive Cache. You can look at this article on JavaRanch discussing caching, which also links to pre-made implementations. Maybe it would be helpful.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic