Source Code Cross Referenced for AllocatorContext.java in  » Development » Javolution » javolution » context » 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 » Development » Javolution » javolution.context 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
003:         * Copyright (C) 2007 - Javolution (http://javolution.org/)
004:         * All rights reserved.
005:         * 
006:         * Permission to use, copy, modify, and distribute this software is
007:         * freely granted, provided that this notice is preserved.
008:         */
009:        package javolution.context;
010:
011:        import javolution.lang.Configurable;
012:
013:        /**
014:         * <p> This class represents an allocator context; it defines the 
015:         *     the allocation policy of {@link ObjectFactory} products.</p>
016:         *     
017:         * <p> The {@link #DEFAULT default} implementation is an instance of
018:         *     {@link HeapContext} context.</p>
019:         *     
020:         * <p> Specializations may allocate from local stacks ({@link StackContext}),
021:         *     specific memory areas (e.g. {@link ImmortalContext}), aging pools (where
022:         *     objects sufficiently old are recycled), switchable spaces (objects from
023:         *     a particular frame are recycled when buffers are swapped), etc.</p>
024:         *     
025:         * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
026:         * @version 5.2, August 19, 2007
027:         */
028:        public abstract class AllocatorContext extends Context {
029:
030:            /**
031:             * Holds the default allocator context instance.
032:             */
033:            private static volatile AllocatorContext _Default = new HeapContext();
034:
035:            /**
036:             * Holds the default implementation ({@link HeapContext} instance).
037:             */
038:            public static final Configurable/*<Class<? extends AllocatorContext>>*/
039:            DEFAULT = new Configurable(_Default.getClass()) {
040:                protected void notifyChange() {
041:                    _Default = (AllocatorContext) ObjectFactory.getInstance(
042:                            (Class) get()).object();
043:                }
044:            };
045:
046:            /**
047:             * Default constructor.
048:             */
049:            protected AllocatorContext() {
050:            }
051:
052:            /**
053:             * Returns the current allocator context. If the current thread has 
054:             * not entered an allocator context (e.g. new thread) then 
055:             * {@link #getDefault()} is returned.
056:             *
057:             * @return the current allocator context.
058:             */
059:            public static/*AllocatorContext*/Context getCurrent() {
060:                return Context.getCurrent().getAllocatorContext();
061:            }
062:
063:            /**
064:             * Returns the default instance ({@link #DEFAULT} implementation).
065:             * 
066:             * @return the default instance.
067:             */
068:            public static AllocatorContext getDefault() {
069:                return AllocatorContext._Default;
070:            }
071:
072:            /**
073:             * Returns the allocator for the specified factory in this context.
074:             * 
075:             * @param factory the factory for which the allocator is returned.
076:             * @return the allocator producing instances of the specified factory.
077:             */
078:            protected abstract Allocator getAllocator(ObjectFactory factory);
079:
080:            /**
081:             * Deactivates the {@link Allocator allocators} belonging to this context
082:             * for the current thread. This method is typically called when an inner 
083:             * allocator context is entered by the current thread, when exiting an 
084:             * allocator context or when a concurrent executor has completed its task
085:             * within this allocator context. Deactivated allocators have no
086:             * {@link Allocator#user user} (<code>null</code>).
087:             */
088:            protected abstract void deactivate();
089:
090:            /**
091:             * <p> This class represents a {@link javolution.lang.Reference reference}
092:             *     allocated from the current {@link AllocatorContext}. 
093:             *     The reachability level of this reference is the scope of the 
094:             *     {@link AllocatorContext} in which it has been 
095:             *     {@link #newInstance created}.</p>
096:             *     
097:             * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
098:             * @version 5.0, April 14, 2007
099:             */
100:            public static class Reference/*<T>*/implements 
101:                    javolution.lang.Reference/*<T>*/{
102:
103:                /**
104:                 * Holds the factory.
105:                 */
106:                private static final ObjectFactory FACTORY = new ObjectFactory() {
107:                    protected Object create() {
108:                        return new Reference();
109:                    }
110:
111:                    protected void cleanup(Object obj) {
112:                        ((Reference) obj)._value = null;
113:                    }
114:                };
115:
116:                /**
117:                 * Holds the reference value.
118:                 */
119:                private Object/*{T}*/_value;
120:
121:                /**
122:                 * Default constructor.
123:                 */
124:                public Reference() {
125:                }
126:
127:                /**
128:                 * Returns a new stack reference instance allocated on the current stack
129:                 * when executing in a {@link StackContext}.
130:                 * 
131:                 * @return a reference object possibly recycled.
132:                 */
133:                public static/*<T>*/Reference /*<T>*/newInstance() {
134:                    return (Reference) FACTORY.object();
135:                }
136:
137:                /**
138:                 * Returns the string representation of the current value of 
139:                 * this reference.
140:                 * 
141:                 * @return <code>String.valueOf(this.get())</code>
142:                 */
143:                public String toString() {
144:                    return String.valueOf(_value);
145:                }
146:
147:                // Implements Reference interface.
148:                public final Object/*{T}*/get() {
149:                    return _value;
150:                }
151:
152:                // Implements Reference interface.
153:                public final void set(Object/*{T}*/value) {
154:                    _value = value;
155:                }
156:            }
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.