KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > cache > SynchronizedCache


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.cache;
9
10 import org.apache.avalon.framework.thread.ThreadSafe;
11
12 /**
13  * A thread safe version of the Cache.
14  * Provide synchronized wrapper methods for all them methods
15  * defined in the Cache interface.
16  *
17  * @author <a HREF="mailto:colus@apache.org">Eung-ju Park</a>
18  */

19 public class SynchronizedCache
20     implements ThreadSafe, Cache
21 {
22     private Cache m_cache;
23
24     public SynchronizedCache( final Cache cache )
25     {
26         m_cache = cache;
27     }
28
29     public void addListener( final CacheListener listener )
30     {
31         m_cache.addListener( listener );
32     }
33
34     public void removeListener( final CacheListener listener )
35     {
36         m_cache.removeListener( listener );
37     }
38
39     public int capacity()
40     {
41         synchronized ( m_cache )
42         {
43             return m_cache.capacity();
44         }
45     }
46    
47     public int size()
48     {
49         synchronized ( m_cache )
50         {
51             return m_cache.size();
52         }
53     }
54
55     public Object JavaDoc put( final Object JavaDoc key, final Object JavaDoc value )
56     {
57         synchronized ( m_cache )
58         {
59             return m_cache.put( key, value );
60         }
61     }
62
63     public Object JavaDoc get( final Object JavaDoc key )
64     {
65         synchronized ( m_cache )
66         {
67             return m_cache.get( key );
68         }
69     }
70
71     public Object JavaDoc remove( Object JavaDoc key )
72     {
73         synchronized ( m_cache )
74         {
75             return m_cache.remove( key );
76         }
77     }
78
79     public boolean containsKey( final Object JavaDoc key )
80     {
81         synchronized ( m_cache )
82         {
83             return m_cache.containsKey( key );
84         }
85     }
86
87     public void clear()
88     {
89         synchronized ( m_cache )
90         {
91             m_cache.clear();
92         }
93     }
94 }
95
Popular Tags