Source Code Cross Referenced for LinkedRangeFactory.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » texteditor » quickdiff » compare » rangedifferencer » 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 » ui workbench » org.eclipse.ui.internal.texteditor.quickdiff.compare.rangedifferencer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 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.ui.internal.texteditor.quickdiff.compare.rangedifferencer;
011:
012:        /**
013:         * Memory-monitoring factory for <code>LinkedRangeDifference</code>.
014:         *
015:         * @since 3.0
016:         */
017:        public class LinkedRangeFactory {
018:
019:            /**
020:             * Exception that is thrown after the minimal allowed free memory is reached.
021:             * <p>
022:             * This class is not intended to be serialized.
023:             * </p>
024:             *
025:             */
026:            public static class LowMemoryException extends Exception {
027:
028:                /**
029:                 * Serial version UID for this class.
030:                 * <p>
031:                 * Note: This class is not intended to be serialized.
032:                 * </p>
033:                 * @since 3.1
034:                 */
035:                private static final long serialVersionUID = 3977582493823939894L;
036:
037:                /**
038:                 * Initialize without detail message.
039:                 */
040:                public LowMemoryException() {
041:                    super ();
042:                }
043:
044:                /**
045:                 * Initialize with the given detail message.
046:                 *
047:                 * @param message the detail message
048:                 */
049:                public LowMemoryException(String message) {
050:                    super (message);
051:                }
052:            }
053:
054:            /**
055:             * Relative amount of memory that must be free in order to allow the creation of additional instances
056:             */
057:            private static final double THRESHOLD = 0.1;
058:            /**
059:             * Number of instantiations after which the amount of free memory is checked
060:             */
061:            private static final long CHECK_INTERVAL = 5000;
062:            /**
063:             * Considered maximal size of a difference object in bytes.
064:             */
065:            private static final long OBJECT_SIZE = 100;
066:            /**
067:             * The maximal memory requirement for the next round in bytes.
068:             */
069:            private static final long MAXIMAL_INTERVAL_REQUIREMENT = CHECK_INTERVAL
070:                    * OBJECT_SIZE;
071:            /**
072:             * Allowed memory consumption in bytes.
073:             */
074:            private static final long MAX_MEMORY_CONSUMPTION = 10 * 1024 * 1024;
075:            /**
076:             * The maximal number of instances.
077:             */
078:            private static final long MAX_INSTANCES = MAX_MEMORY_CONSUMPTION
079:                    / OBJECT_SIZE;
080:
081:            /**
082:             * Preallocated low memory exception
083:             */
084:            private LowMemoryException fLowMemoryException = new LowMemoryException();
085:
086:            /**
087:             * Number of instantiations
088:             */
089:            private long fCount = 0;
090:
091:            /**
092:             * Create a new linked range difference with the given next range and operation.
093:             *
094:             * @param next the next linked range difference
095:             * @param operation the operation
096:             * @return the new linked range difference
097:             * @throws LowMemoryException
098:             */
099:            public LinkedRangeDifference newRange(LinkedRangeDifference next,
100:                    int operation) throws LowMemoryException {
101:                check();
102:                return new LinkedRangeDifference(next, operation);
103:            }
104:
105:            /**
106:             * After <code>CHECK_INTERVAL</code> calls check whether at least a fraction of <code>THRESHOLD</code>
107:             * of the maximal available memory is free, otherwise throw an {@link LowMemoryException}.
108:             *
109:             * @throws LowMemoryException
110:             */
111:            private void check() throws LowMemoryException {
112:                if (fCount % CHECK_INTERVAL == 0) {
113:
114:                    Runtime runtime = Runtime.getRuntime();
115:                    long maxMemory = runtime.maxMemory();
116:                    long maxFreeMemory = maxMemory
117:                            - (runtime.totalMemory() - runtime.freeMemory());
118:
119:                    if (((float) (maxFreeMemory - MAXIMAL_INTERVAL_REQUIREMENT))
120:                            / maxMemory < THRESHOLD)
121:                        throw fLowMemoryException;
122:                }
123:                if (++fCount >= MAX_INSTANCES)
124:                    throw fLowMemoryException;
125:            }
126:        }
ww___w__.ja_v___a___2__s__.___c__o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.