Java Doc for ObjectCache.java in  » Test-Coverage » GroboUtils » net » sourceforge » groboutils » util » datastruct » v1 » 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 » Test Coverage » GroboUtils » net.sourceforge.groboutils.util.datastruct.v1 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.sourceforge.groboutils.util.datastruct.v1.ObjectCache

ObjectCache
public class ObjectCache (Code)
An object cache which allows for objects to be added and removed. If the cache is empty when an object is requested, the object type is created and returned. There can be a maximum size specified for the pending object list - if an object is retrieved by the cache, and the list is beyond its size, then the object is thrown away. By default, the maximum size is unlimited.

If the cache should not create objects, then a ObjectCreator should not be given to the cache.

Alternatively, you can specify that the cache not create objects and instead wait for the objects to be retrieved.

Care has been taken to keep this synchronized across threads.
author:
   Matt Albrecht groboclown@users.sourceforge.net
since:
   April 11, 2001 (0.9.0 Alpha)
version:
   $Date: 2003/05/23 20:55:43 $


Inner Class :public static interface ObjectCreator
Inner Class :public static class DefaultObjectCreator implements ObjectCreator

Field Summary
final public static  intUNLIMITED_SIZE
     The size to use when you want to specify an unlimited cache size.

Constructor Summary
public  ObjectCache()
     Create a new ObjectCache without an object creator.
public  ObjectCache(int maxSize)
     Create a new ObjectCache without an object creator, and sets the maximum number of objects to keep waiting in the cache.
public  ObjectCache(ObjectCreator creator)
     Create a new ObjectCache.
public  ObjectCache(Class creator)
     Create a new ObjectCache.
public  ObjectCache(ObjectCreator creator, int maxSize)
     Create a new ObjectCache.
public  ObjectCache(Class creator, int maxSize)
     Create a new ObjectCache.
public  ObjectCache(ObjectCreator creator, int maxSize, boolean fill)
     Create a new ObjectCache.
public  ObjectCache(Class creator, int maxSize, boolean fill)
     Create a new ObjectCache.

Method Summary
public  voidaddObject()
     Create a new object and put it into the cache.
protected  ObjectcreateObject()
     Generates an Object for the cache.
public  voidfillCache()
     Fills the cache to its maximum.
public  Objectget()
     Retrieves a cached element.
public  Objectget(long millisWaitTime)
     Retrieves a cached element.
public  intgetMaxSize()
    
public  intgetOverflows()
     Retrieves the number of "overflows" encountered.
public  intgetUnderflows()
     Retrieves the number of "underflows" encountered.
public  voidputBack(Object o)
     Adds an element to the end of the queue.
public  voidsetClassCreator(Class creator)
     Creates a new DefaultObjectCreator based on the given class.
public  voidsetMaxSize(int size)
     Resets the internal maximum number of objects that the cache can hold.
public  voidsetObjectCreator(ObjectCreator creator)
     Sets the internal cache-underflow Object creator.

Field Detail
UNLIMITED_SIZE
final public static int UNLIMITED_SIZE(Code)
The size to use when you want to specify an unlimited cache size.




Constructor Detail
ObjectCache
public ObjectCache()(Code)
Create a new ObjectCache without an object creator.



ObjectCache
public ObjectCache(int maxSize)(Code)
Create a new ObjectCache without an object creator, and sets the maximum number of objects to keep waiting in the cache.



ObjectCache
public ObjectCache(ObjectCreator creator)(Code)
Create a new ObjectCache. This uses the given creator to create new objects for the cache.



ObjectCache
public ObjectCache(Class creator)(Code)
Create a new ObjectCache. This uses the given Class to create new objects for the cache, using its default constructor.



ObjectCache
public ObjectCache(ObjectCreator creator, int maxSize)(Code)
Create a new ObjectCache. This uses the given creator to create new objects for the cache, and sets the internal maximum number of elements to keep waiting.



ObjectCache
public ObjectCache(Class creator, int maxSize)(Code)
Create a new ObjectCache. This uses the given Class to create new objects for the cache, using its default constructor, and sets the internal maximum number of elements to keep waiting.



ObjectCache
public ObjectCache(ObjectCreator creator, int maxSize, boolean fill)(Code)
Create a new ObjectCache. This uses the given creator to create new objects for the cache, and sets the internal maximum number of elements to keep waiting.
Parameters:
  fill - true if the cache should be filled atconstruction time, or false if it should be emptyinitially.



ObjectCache
public ObjectCache(Class creator, int maxSize, boolean fill)(Code)
Create a new ObjectCache. This uses the given Class to create new objects for the cache, using its default constructor, and sets the internal maximum number of elements to keep waiting.
Parameters:
  fill - true if the cache should be filled atconstruction time, or false if it should be emptyinitially.




Method Detail
addObject
public void addObject()(Code)
Create a new object and put it into the cache. This follows the rules of ObjectCache.putBack(Object) .



createObject
protected Object createObject()(Code)
Generates an Object for the cache. May return null.



fillCache
public void fillCache()(Code)
Fills the cache to its maximum. If there is no maximum or there is no creator, then nothing is done.



get
public Object get()(Code)
Retrieves a cached element. If the cache is empty, and no creator is known, then null is returned. If the cache is empty, and a creator is known, then a new object is created and returned.

Synchronized so that the time between the isEmpty check and the pull does not have another thread pulling out an instance. Only the get needs to be synchronized, so as to not mess with the checks.




get
public Object get(long millisWaitTime) throws InterruptedException(Code)
Retrieves a cached element. If the cache is empty, then one of several things can happen, based on the time passed in:
  • < 0: null is immediately returned. This is the identical behavior to calling ObjectCache.get() with a null creator.
  • 0: the routine will wait indefinitely until an object is ObjectCache.putBack(Object) into the cache.
  • > 0: the routine will wait up to the given number of milliseconds for another object to be ObjectCache.putBack(Object) . If by that time the cache is still empty, then null is returned.

Important parts of the code are synchronized.




getMaxSize
public int getMaxSize()(Code)



getOverflows
public int getOverflows()(Code)
Retrieves the number of "overflows" encountered. An overflow occurs when the cache is full and a ObjectCache.putBack(Object) is called.



getUnderflows
public int getUnderflows()(Code)
Retrieves the number of "underflows" encountered. An underflow occurs when the cache is empty and a ObjectCache.get() is called.



putBack
public void putBack(Object o)(Code)
Adds an element to the end of the queue. If the list is empty, then the next waiting thread is woken up. If the list has one or fewer elements, this this method will block any access to the queue, otherwise this only blocks access to adding to the list.
Parameters:
  o - the object to place at the end of the list.



setClassCreator
public void setClassCreator(Class creator)(Code)
Creates a new DefaultObjectCreator based on the given class.



setMaxSize
public void setMaxSize(int size)(Code)
Resets the internal maximum number of objects that the cache can hold. Note that it does not immediately clear out the extra objects - that is naturally cleared by the ObjectCache.putBack(Object) ignoring overflows.



setObjectCreator
public void setObjectCreator(ObjectCreator creator)(Code)
Sets the internal cache-underflow Object creator.



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.