~james-page/ubuntu/natty/tomcat6/fix-662588

« back to all changes in this revision

Viewing changes to java/org/apache/el/util/ConcurrentCache.java

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Iulian Udrea
  • Date: 2009-06-09 12:35:19 UTC
  • mfrom: (1.2.1 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090609123519-7owjbso5ttnka6ur
Tags: 6.0.20-1ubuntu1
[ Iulian Udrea ]
* Merge from debian unstable (LP: #385262), remaining changes:
  - debian/control, debian/rules: Use default-jdk to build
  - debian/control: Run using default-jre-headless by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
public final class ConcurrentCache<K,V> {
24
24
 
25
 
        private final int size;
26
 
        
27
 
        private final Map<K,V> eden;
28
 
        
29
 
        private final Map<K,V> longterm;
30
 
        
31
 
        public ConcurrentCache(int size) {
32
 
                this.size = size;
33
 
                this.eden = new ConcurrentHashMap<K,V>(size);
34
 
                this.longterm = new WeakHashMap<K,V>(size);
35
 
        }
36
 
        
37
 
        public V get(K k) {
38
 
                V v = this.eden.get(k);
39
 
                if (v == null) {
40
 
                        v = this.longterm.get(k);
41
 
                        if (v != null) {
42
 
                                this.eden.put(k, v);
43
 
                        }
44
 
                }
45
 
                return v;
46
 
        }
47
 
        
48
 
        public void put(K k, V v) {
49
 
                if (this.eden.size() >= size) {
50
 
                        this.longterm.putAll(this.eden);
51
 
                        this.eden.clear();
52
 
                }
53
 
                this.eden.put(k, v);
54
 
        }
 
25
    private final int size;
 
26
 
 
27
    private final Map<K,V> eden;
 
28
 
 
29
    private final Map<K,V> longterm;
 
30
 
 
31
    public ConcurrentCache(int size) {
 
32
        this.size = size;
 
33
        this.eden = new ConcurrentHashMap<K,V>(size);
 
34
        this.longterm = new WeakHashMap<K,V>(size);
 
35
    }
 
36
 
 
37
    public V get(K k) {
 
38
        V v = this.eden.get(k);
 
39
        if (v == null) {
 
40
            v = this.longterm.get(k);
 
41
            if (v != null) {
 
42
                this.eden.put(k, v);
 
43
            }
 
44
        }
 
45
        return v;
 
46
    }
 
47
 
 
48
    public void put(K k, V v) {
 
49
        if (this.eden.size() >= size) {
 
50
            this.longterm.putAll(this.eden);
 
51
            this.eden.clear();
 
52
        }
 
53
        this.eden.put(k, v);
 
54
    }
55
55
}