|
Lines 15-20
Link Here
|
| 15 |
import org.eclipse.core.resources.IFile; |
15 |
import org.eclipse.core.resources.IFile; |
| 16 |
import org.eclipse.core.resources.IResource; |
16 |
import org.eclipse.core.resources.IResource; |
| 17 |
import org.eclipse.dltk.core.IBuffer; |
17 |
import org.eclipse.dltk.core.IBuffer; |
|
|
18 |
import org.eclipse.dltk.core.IBufferFactory; |
| 18 |
import org.eclipse.dltk.core.IModelElement; |
19 |
import org.eclipse.dltk.core.IModelElement; |
| 19 |
import org.eclipse.dltk.core.IOpenable; |
20 |
import org.eclipse.dltk.core.IOpenable; |
| 20 |
|
21 |
|
|
Lines 31-37
Link Here
|
| 31 |
* LRU cache of buffers. The key and value for an entry in the table is the |
32 |
* LRU cache of buffers. The key and value for an entry in the table is the |
| 32 |
* identical buffer. |
33 |
* identical buffer. |
| 33 |
*/ |
34 |
*/ |
| 34 |
protected OverflowingLRUCache openBuffers = new BufferCache(60); |
35 |
private BufferCache openBuffers = new BufferCache(60); |
|
|
36 |
|
| 37 |
/** |
| 38 |
* @deprecated |
| 39 |
*/ |
| 40 |
protected IBufferFactory defaultBufferFactory = new IBufferFactory() { |
| 41 |
/** |
| 42 |
* @deprecated |
| 43 |
*/ |
| 44 |
public IBuffer createBuffer(IOpenable owner) { |
| 45 |
return BufferManager.createBuffer(owner); |
| 46 |
} |
| 47 |
}; |
| 35 |
|
48 |
|
| 36 |
/** |
49 |
/** |
| 37 |
* Adds a buffer to the table of open buffers. |
50 |
* Adds a buffer to the table of open buffers. |
|
Lines 42-48
Link Here
|
| 42 |
.toStringWithAncestors(); |
55 |
.toStringWithAncestors(); |
| 43 |
System.out.println("Adding buffer for " + owner); //$NON-NLS-1$ |
56 |
System.out.println("Adding buffer for " + owner); //$NON-NLS-1$ |
| 44 |
} |
57 |
} |
|
|
58 |
synchronized (this.openBuffers) { |
| 45 |
this.openBuffers.put(buffer.getOwner(), buffer); |
59 |
this.openBuffers.put(buffer.getOwner(), buffer); |
|
|
60 |
} |
| 61 |
// close buffers that were removed from the cache if space was needed |
| 62 |
this.openBuffers.closeBuffers(); |
| 46 |
if (VERBOSE) { |
63 |
if (VERBOSE) { |
| 47 |
System.out |
64 |
System.out |
| 48 |
.println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$ |
65 |
.println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$ |
|
Lines 50-68
Link Here
|
| 50 |
} |
67 |
} |
| 51 |
|
68 |
|
| 52 |
public static IBuffer createBuffer(IOpenable owner) { |
69 |
public static IBuffer createBuffer(IOpenable owner) { |
| 53 |
IModelElement element = owner; |
70 |
IModelElement element = (IModelElement) owner; |
| 54 |
IResource resource = element.getResource(); |
71 |
IResource resource = element.getResource(); |
| 55 |
return new Buffer(resource instanceof IFile ? (IFile) resource : null, |
72 |
return new Buffer(resource instanceof IFile ? (IFile) resource : null, |
| 56 |
owner, element.isReadOnly()); |
73 |
owner, element.isReadOnly()); |
| 57 |
} |
74 |
} |
| 58 |
|
75 |
|
|
|
76 |
public static IBuffer createNullBuffer(IOpenable owner) { |
| 77 |
IModelElement element = (IModelElement) owner; |
| 78 |
IResource resource = element.getResource(); |
| 79 |
return new NullBuffer(resource instanceof IFile ? (IFile) resource |
| 80 |
: null, owner, element.isReadOnly()); |
| 81 |
} |
| 82 |
|
| 59 |
/** |
83 |
/** |
| 60 |
* Returns the open buffer associated with the given owner, or |
84 |
* Returns the open buffer associated with the given owner, or |
| 61 |
* <code>null</code> if the owner does not have an open buffer associated |
85 |
* <code>null</code> if the owner does not have an open buffer associated |
| 62 |
* with it. |
86 |
* with it. |
| 63 |
*/ |
87 |
*/ |
| 64 |
public IBuffer getBuffer(IOpenable owner) { |
88 |
public IBuffer getBuffer(IOpenable owner) { |
| 65 |
return (IBuffer) this.openBuffers.get(owner); |
89 |
synchronized (this.openBuffers) { |
|
|
90 |
return (IBuffer) this.openBuffers.get(owner); |
| 91 |
} |
| 66 |
} |
92 |
} |
| 67 |
|
93 |
|
| 68 |
/** |
94 |
/** |
|
Lines 71-81
Link Here
|
| 71 |
public synchronized static BufferManager getDefaultBufferManager() { |
97 |
public synchronized static BufferManager getDefaultBufferManager() { |
| 72 |
if (DEFAULT_BUFFER_MANAGER == null) { |
98 |
if (DEFAULT_BUFFER_MANAGER == null) { |
| 73 |
DEFAULT_BUFFER_MANAGER = new BufferManager(); |
99 |
DEFAULT_BUFFER_MANAGER = new BufferManager(); |
| 74 |
} |
100 |
} |
| 75 |
return DEFAULT_BUFFER_MANAGER; |
101 |
return DEFAULT_BUFFER_MANAGER; |
| 76 |
} |
102 |
} |
| 77 |
|
103 |
|
| 78 |
/** |
104 |
/** |
|
|
105 |
* Returns the default buffer factory. |
| 106 |
* |
| 107 |
* @deprecated |
| 108 |
*/ |
| 109 |
public IBufferFactory getDefaultBufferFactory() { |
| 110 |
return this.defaultBufferFactory; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 79 |
* Returns an enumeration of all open buffers. |
114 |
* Returns an enumeration of all open buffers. |
| 80 |
* <p> |
115 |
* <p> |
| 81 |
* The <code>Enumeration</code> answered is thread safe. |
116 |
* The <code>Enumeration</code> answered is thread safe. |
|
Lines 84-93
Link Here
|
| 84 |
* @return Enumeration of IBuffer |
119 |
* @return Enumeration of IBuffer |
| 85 |
*/ |
120 |
*/ |
| 86 |
public Enumeration getOpenBuffers() { |
121 |
public Enumeration getOpenBuffers() { |
|
|
122 |
Enumeration result; |
| 87 |
synchronized (this.openBuffers) { |
123 |
synchronized (this.openBuffers) { |
| 88 |
this.openBuffers.shrink(); |
124 |
this.openBuffers.shrink(); |
| 89 |
return this.openBuffers.elements(); |
125 |
result = this.openBuffers.elements(); |
| 90 |
} |
126 |
} |
|
|
127 |
// close buffers that were removed from the cache if space was needed |
| 128 |
this.openBuffers.closeBuffers(); |
| 129 |
return result; |
| 91 |
} |
130 |
} |
| 92 |
|
131 |
|
| 93 |
/** |
132 |
/** |
|
Lines 98-105
Link Here
|
| 98 |
String owner = ((Openable) buffer.getOwner()) |
137 |
String owner = ((Openable) buffer.getOwner()) |
| 99 |
.toStringWithAncestors(); |
138 |
.toStringWithAncestors(); |
| 100 |
System.out.println("Removing buffer for " + owner); //$NON-NLS-1$ |
139 |
System.out.println("Removing buffer for " + owner); //$NON-NLS-1$ |
| 101 |
} |
140 |
} |
|
|
141 |
synchronized (this.openBuffers) { |
| 102 |
this.openBuffers.remove(buffer.getOwner()); |
142 |
this.openBuffers.remove(buffer.getOwner()); |
|
|
143 |
} |
| 144 |
// close buffers that were removed from the cache (should be only one) |
| 145 |
this.openBuffers.closeBuffers(); |
| 103 |
if (VERBOSE) { |
146 |
if (VERBOSE) { |
| 104 |
System.out |
147 |
System.out |
| 105 |
.println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$ |
148 |
.println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$ |