Source Code Cross Referenced for BufferManager.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.internal.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.core;
011:
012:        import java.text.NumberFormat;
013:        import java.util.Enumeration;
014:
015:        import org.eclipse.core.resources.IFile;
016:        import org.eclipse.core.resources.IResource;
017:        import org.eclipse.jdt.core.IBuffer;
018:        import org.eclipse.jdt.core.IJavaElement;
019:        import org.eclipse.jdt.core.IOpenable;
020:
021:        /**
022:         * The buffer manager manages the set of open buffers.
023:         * It implements an LRU cache of buffers.
024:         */
025:        public class BufferManager {
026:
027:            protected static BufferManager DEFAULT_BUFFER_MANAGER;
028:            protected static boolean VERBOSE;
029:
030:            /**
031:             * LRU cache of buffers. The key and value for an entry
032:             * in the table is the identical buffer.
033:             */
034:            private BufferCache openBuffers = new BufferCache(60);
035:
036:            /**
037:             * @deprecated
038:             */
039:            protected org.eclipse.jdt.core.IBufferFactory defaultBufferFactory = new org.eclipse.jdt.core.IBufferFactory() {
040:                /**
041:                 * @deprecated
042:                 */
043:                public IBuffer createBuffer(IOpenable owner) {
044:                    return BufferManager.createBuffer(owner);
045:                }
046:            };
047:
048:            /**
049:             * Adds a buffer to the table of open buffers.
050:             */
051:            protected void addBuffer(IBuffer buffer) {
052:                if (VERBOSE) {
053:                    String owner = ((Openable) buffer.getOwner())
054:                            .toStringWithAncestors();
055:                    System.out.println("Adding buffer for " + owner); //$NON-NLS-1$
056:                }
057:                synchronized (this .openBuffers) {
058:                    this .openBuffers.put(buffer.getOwner(), buffer);
059:                }
060:                // close buffers that were removed from the cache if space was needed
061:                this .openBuffers.closeBuffers();
062:                if (VERBOSE) {
063:                    System.out
064:                            .println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this .openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$
065:                }
066:            }
067:
068:            public static IBuffer createBuffer(IOpenable owner) {
069:                IJavaElement element = (IJavaElement) owner;
070:                IResource resource = element.getResource();
071:                return new Buffer(resource instanceof  IFile ? (IFile) resource
072:                        : null, owner, element.isReadOnly());
073:            }
074:
075:            public static IBuffer createNullBuffer(IOpenable owner) {
076:                IJavaElement element = (IJavaElement) owner;
077:                IResource resource = element.getResource();
078:                return new NullBuffer(
079:                        resource instanceof  IFile ? (IFile) resource : null,
080:                        owner, element.isReadOnly());
081:            }
082:
083:            /**
084:             * Returns the open buffer associated with the given owner,
085:             * or <code>null</code> if the owner does not have an open
086:             * buffer associated with it.
087:             */
088:            public IBuffer getBuffer(IOpenable owner) {
089:                synchronized (this .openBuffers) {
090:                    return (IBuffer) this .openBuffers.get(owner);
091:                }
092:            }
093:
094:            /**
095:             * Returns the default buffer manager.
096:             */
097:            public synchronized static BufferManager getDefaultBufferManager() {
098:                if (DEFAULT_BUFFER_MANAGER == null) {
099:                    DEFAULT_BUFFER_MANAGER = new BufferManager();
100:                }
101:                return DEFAULT_BUFFER_MANAGER;
102:            }
103:
104:            /**
105:             * Returns the default buffer factory.
106:             * @deprecated
107:             */
108:            public org.eclipse.jdt.core.IBufferFactory getDefaultBufferFactory() {
109:                return this .defaultBufferFactory;
110:            }
111:
112:            /**
113:             * Returns an enumeration of all open buffers.
114:             * <p> 
115:             * The <code>Enumeration</code> answered is thread safe.
116:             *
117:             * @see OverflowingLRUCache
118:             * @return Enumeration of IBuffer
119:             */
120:            public Enumeration getOpenBuffers() {
121:                Enumeration result;
122:                synchronized (this .openBuffers) {
123:                    this .openBuffers.shrink();
124:                    result = this .openBuffers.elements();
125:                }
126:                // close buffers that were removed from the cache if space was needed
127:                this .openBuffers.closeBuffers();
128:                return result;
129:            }
130:
131:            /**
132:             * Removes a buffer from the table of open buffers.
133:             */
134:            protected void removeBuffer(IBuffer buffer) {
135:                if (VERBOSE) {
136:                    String owner = ((Openable) buffer.getOwner())
137:                            .toStringWithAncestors();
138:                    System.out.println("Removing buffer for " + owner); //$NON-NLS-1$
139:                }
140:                synchronized (this .openBuffers) {
141:                    this .openBuffers.remove(buffer.getOwner());
142:                }
143:                // close buffers that were removed from the cache (should be only one)
144:                this .openBuffers.closeBuffers();
145:                if (VERBOSE) {
146:                    System.out
147:                            .println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this .openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$
148:                }
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.