KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > client > handler > CacheBase


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.appserv.management.client.handler;
24
25 import java.util.Set JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Collections JavaDoc;
29
30 import java.util.logging.Logger JavaDoc;
31 import com.sun.appserv.management.base.LoggerSupport;
32
33 /**
34     Cache which caches anything
35  */

36 class CacheBase<K,V>
37 {
38     private final Map JavaDoc<K,V> mCache;
39     
40     /**
41      */

42         public
43     CacheBase()
44     {
45         mCache = Collections.synchronizedMap( new HashMap JavaDoc<K,V>() );
46     }
47     
48     /**
49         Cache a proxy using any desired key.
50      */

51         public void
52     cacheItem(
53         final K key,
54         final V value )
55     {
56         mCache.put( key, value );
57     }
58     
59         public V
60     getCachedItem( K key )
61     {
62         return( mCache.get( key ) );
63     }
64     
65         public void
66     remove( final K key )
67     {
68         mCache.remove( key );
69     }
70     
71         public Set JavaDoc<K>
72     keySet()
73     {
74         return( mCache.keySet() );
75     }
76 }
77
78
79
80
81
82
Popular Tags