1 11 package org.eclipse.debug.internal.ui.views.variables; 12 13 import java.util.HashMap ; 14 import java.util.HashSet ; 15 import java.util.Map ; 16 import java.util.Set ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.debug.core.ILogicalStructureType; 22 import org.eclipse.debug.core.model.IValue; 23 import org.eclipse.debug.internal.ui.DebugUIPlugin; 24 25 33 public class LogicalStructureCache { 34 35 38 private Map fCacheForType = new HashMap (); 39 40 48 public IValue getLogicalStructure(ILogicalStructureType type, IValue value) throws CoreException { 49 synchronized (fCacheForType) { 50 LogicalStructureTypeCache cache = getCacheForType(type); 51 return cache.getLogicalStructure(value); 52 } 53 } 54 55 58 public void clear(){ 59 synchronized (fCacheForType) { 60 fCacheForType.clear(); 61 } 62 } 63 64 71 protected LogicalStructureTypeCache getCacheForType(ILogicalStructureType type){ 72 LogicalStructureTypeCache cache = (LogicalStructureTypeCache)fCacheForType.get(type); 73 if (cache == null){ 74 cache = new LogicalStructureTypeCache(type); 75 fCacheForType.put(type, cache); 76 } 77 return cache; 78 } 79 80 84 class LogicalStructureTypeCache{ 85 86 private ILogicalStructureType fType; 87 88 91 private Map fKnownValues = new HashMap (); 92 93 96 private Set fPendingValues = new HashSet (); 97 98 public LogicalStructureTypeCache(ILogicalStructureType type){ 99 fType = type; 100 } 101 102 110 public IValue getLogicalStructure(IValue value) throws CoreException { 111 synchronized (fKnownValues) { 113 IValue logical = (IValue)fKnownValues.get(value); 114 if (logical != null){ 115 return logical; 116 } 117 } 118 synchronized (fPendingValues) { 120 if (fPendingValues.contains(value)){ 121 try { 122 fPendingValues.wait(); 123 return getLogicalStructure(value); 124 } catch (InterruptedException e) { 125 throw new CoreException(new Status(IStatus.CANCEL, DebugUIPlugin.getUniqueIdentifier(), 126 VariablesViewMessages.LogicalStructureCache_0, e)); 127 } 128 } else { 129 fPendingValues.add(value); 130 } 131 } 132 try { 134 IValue result = fType.getLogicalStructure(value); 135 synchronized (fKnownValues) { 136 fKnownValues.put(value, result); 137 } 138 synchronized (fPendingValues) { 139 fPendingValues.remove(value); 140 fPendingValues.notifyAll(); 141 } 142 return result; 143 } catch (CoreException e) { 144 synchronized (fPendingValues) { 145 fPendingValues.remove(value); 146 fPendingValues.notifyAll(); 147 } 148 throw e; 149 } 150 } 151 152 } 153 } 154 | Popular Tags |