KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > mbeanserver > DescriptorCache


1 /*
2  * @(#)DescriptorCache.java 1.2 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.jmx.mbeanserver;
9
10 import java.lang.ref.WeakReference JavaDoc;
11 import java.util.WeakHashMap JavaDoc;
12 import javax.management.Descriptor JavaDoc;
13 import javax.management.ImmutableDescriptor JavaDoc;
14 import javax.management.JMX JavaDoc;
15
16 public class DescriptorCache {
17     private DescriptorCache() {
18     }
19     
20     static DescriptorCache getInstance() {
21         return instance;
22     }
23     
24     public static DescriptorCache getInstance(JMX JavaDoc proof) {
25         if (proof != null)
26             return instance;
27         else
28             return null;
29     }
30     
31     public ImmutableDescriptor JavaDoc get(ImmutableDescriptor JavaDoc descriptor) {
32         WeakReference JavaDoc<ImmutableDescriptor JavaDoc> wr = map.get(descriptor);
33         ImmutableDescriptor JavaDoc got = (wr == null) ? null : wr.get();
34         if (got != null)
35             return got;
36         map.put(descriptor, new WeakReference JavaDoc<ImmutableDescriptor JavaDoc>(descriptor));
37         return descriptor;
38     }
39     
40     public ImmutableDescriptor JavaDoc union(Descriptor JavaDoc... descriptors) {
41         return get(ImmutableDescriptor.union(descriptors));
42     }
43     
44     private final static DescriptorCache instance = new DescriptorCache();
45     private final WeakHashMap JavaDoc<ImmutableDescriptor JavaDoc,
46                               WeakReference JavaDoc<ImmutableDescriptor JavaDoc>>
47         map = new WeakHashMap JavaDoc<ImmutableDescriptor JavaDoc,
48                               WeakReference JavaDoc<ImmutableDescriptor JavaDoc>>();
49 }
50
Popular Tags