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