Java Doc for ObjectFactory.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 Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javolution.context.ObjectFactory

ObjectFactory
abstract public class ObjectFactory (Code)

This class represents an object factory; it allows for object recycling, pre-allocation and stack allocations.

Object factories are recommended over class constructors (ref. "new" keyword) to allows for custom allocation policy (see AllocatorContext ). For example:[code] static ObjectFactory BOARD_FACTORY = new ObjectFactory() { protected int[][] create() { return new int[8][8]; } }; ... int[][] board = BOARD_FACTORY.object(); // The board object might have been preallocated at start-up, // it might also be on the thread "stack/pool" for threads // executing in a StackContext. ... BOARD_FACTORY.recycle(board); // Immediate recycling of the board object (optional). [/code]

For arrays of variable length ArrayFactory is recommended.

For convenience, this class provides a static ObjectFactory.getInstance method to retrieve a factory implementation for any given class. For example:[code] ObjectFactory listFactory = ObjectFactory.getInstance(ArrayList.class); ArrayList list = listFactory.object(); ... // Do something. listFactory.recycle(list); // Optional. [/code]


author:
   Jean-Marie Dautelle
version:
   5.2, August 14, 2007



Constructor Summary
protected  ObjectFactory()
     Default constructor.

Method Summary
protected  voidcleanup(Object obj)
     Cleans-up this factory's objects for future reuse.
abstract protected  Objectcreate()
     Constructs a new object for this factory (using the new keyword).
final public  AllocatorcurrentAllocator()
     Returns the factory allocator for the current thread (equivalent to AllocatorContext.current().getAllocator(this)). the current object queue for this factory.
final protected  booleandoCleanup()
     Indicates if this factory requires cleanup.
public static  ObjectFactorygetInstance(Class forClass)
     Returns a factory implementation producing instances of the specified class.
final public  Objectobject()
     Returns a factory object possibly recycled or preallocated.
final public  voidrecycle(Object obj)
     Recycles the specified object.
public static  voidsetInstance(ObjectFactory factory, Class forClass)
     Sets explicitely the factory to be used for the specified class (see ObjectFactory.getInstance ).


Constructor Detail
ObjectFactory
protected ObjectFactory()(Code)
Default constructor.




Method Detail
cleanup
protected void cleanup(Object obj)(Code)
Cleans-up this factory's objects for future reuse. When overriden, this method is called on objects being recycled to dispose of system resources or to clear references to external objects potentially on the heap (it allows these external objects to be garbage collected immediately and therefore reduces the memory footprint). For example:[code] static ObjectFactory ARRAY_LIST_FACTORY = new ObjectFactory() { protected ArrayList create() { return new ArrayList(); } protected void cleanup(ArrayList obj) { obj.clear(); // Clears external references. } };[/code]
Parameters:
  obj - the factory object being recycled.



create
abstract protected Object create()(Code)
Constructs a new object for this factory (using the new keyword). a new factory object.



currentAllocator
final public Allocator currentAllocator()(Code)
Returns the factory allocator for the current thread (equivalent to AllocatorContext.current().getAllocator(this)). the current object queue for this factory.



doCleanup
final protected boolean doCleanup()(Code)
Indicates if this factory requires cleanup. true if ObjectFactory.cleanup is overriden and ObjectFactory.cleanup has been called at least once; false otherwise.



getInstance
public static ObjectFactory getInstance(Class forClass)(Code)
Returns a factory implementation producing instances of the specified class. By default this method returns a factory creating new objects using the class public no-arg constructor (through reflection). If that constructor is not accessible, the factory instance can be ObjectFactory.setInstance set explicitly :[code] class LogContext { public static final Class NULL = Null.class; ... private static class Null extends LogContext ... // Private. static { // Allows Null instances to be factory produced (even so the class is not accessible). ObjectFactory.setInstance(new ObjectFactory { protected Null create() { return new Null() }}, Null.class); } }[/code]
Parameters:
  forClass - the class for which an object factory is returned. an object factory producing instances of the specified class.



object
final public Object object()(Code)
Returns a factory object possibly recycled or preallocated. This method is equivalent to currentAllocator().nextInQueue(). a recycled, pre-allocated or new factory object.



recycle
final public void recycle(Object obj)(Code)
Recycles the specified object. This method is equivalent to getAllocator().recycle(obj).
Parameters:
  obj - the object to be recycled.



setInstance
public static void setInstance(ObjectFactory factory, Class forClass)(Code)
Sets explicitely the factory to be used for the specified class (see ObjectFactory.getInstance ).
Parameters:
  factory - the factory to use.
Parameters:
  forClass - the associated class.
See Also:   ObjectFactory.getInstance(Class)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.