Java Doc for ObjectPool.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » minerva » pool » 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 » ERP CRM Financial » SourceTap CRM » org.ofbiz.minerva.pool 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.ofbiz.minerva.pool.ObjectPool

ObjectPool
public class ObjectPool implements PoolEventListener(Code)
A generic object pool. You must provide a PoolObjectFactory (or the class of a Java Bean) so the pool knows what kind of objects to create. It has many configurable parameters, such as the minimum and maximum size of the pool, whether to enable idle timeouts, etc. If the pooled objects implement PooledObject, they will automatically be returned to the pool at the appropriate times.

In general, the appropriate way to use a pool is:

  1. Create it
  2. Configure it (set factory, name, parameters, etc.)
  3. Initialize it (once done, further configuration is not allowed)
  4. Use it
  5. Shut it down

See Also:   org.ofbiz.minerva.pool.PooledObject
author:
   Aaron Mulder (ammulder@alumni.princeton.edu)
author:
   danch (Dan Christopherson)
author:
   Revision:
author:
   20010701 danch added code for timeout in blocking.



Constructor Summary
public  ObjectPool()
     Creates a new pool.
public  ObjectPool(PoolObjectFactory factory, String poolName)
     Creates a new pool with the specified parameters.
public  ObjectPool(Class javaBeanClass, String poolName)
     Creates a new pool with the specified parameters.

Method Summary
public  voidfillToMin()
    
public  intgetBlockingTimeout()
    
public  longgetGCInterval()
     Gets the length of time between garbage collection and idle timeout runs.
public  longgetGCMinIdleTime()
     Gets the minimum idle time to make an object eligible for garbage collection.
public  longgetIdleTimeout()
     Gets the minimum idle time to release an unused object from the pool.
public  floatgetMaxIdleTimeoutPercent()
     Gets the idle timeout percent as a fraction between 0 and 1.
public  intgetMaxSize()
     Gets the maximum size of the pool.
public  intgetMinSize()
     Gets the minimum size of the pool.
public  StringgetName()
     Gets the name of the pool.
 longgetNextGCMillis(long now)
    
public  ObjectgetObject()
     Gets an object from the pool.
public  ObjectgetObject(Object parameters)
     Gets an object that fits the specified parameters from the pool. If all the objects in the pool are in use or don't fit, creates a new object, adds it to the pool, and returns it.
public  voidinitialize()
     Prepares the pool for use.
public  booleanisBlocking()
     Gets whether a request for an object will block if the pool size is maxed out and no objects are available.
public  booleanisGCEnabled()
     Gets whether garbage collection is enabled.
public  booleanisIdleTimeoutEnabled()
     Gets whether the pool releases instances that have not been used recently.
public  booleanisInvalidateOnError()
     Gets whether objects are removed from the pool in case of errors.
 booleanisTimeToGC()
    
public  booleanisTimestampUsed()
     Gets whether object clients can update the last used time.
public  voidmarkObjectAsInvalid(Object object)
     Indicates that an object is no longer valid, and should be removed from the pool entirely.
public  voidobjectClosed(PoolEvent evt)
     If the object has been closed, release it.
public  voidobjectError(PoolEvent evt)
     If the invalidateOnError flag is set, the object will be removed from the pool entirely when the client has finished with it.
public  voidobjectUsed(PoolEvent evt)
     If we're tracking the last used times, update the last used time for the specified object.
public  voidreleaseObject(Object object)
     Returns an object to the pool.
 voidrunGCandShrink()
    
public  voidsetBlocking(boolean blocking)
     Sets whether a request for an object will block if the pool size is maxed out and no objects are available.
public  voidsetBlockingTimeout(int blockingTimeout)
     sets how long to wait for a free object when blocking, -1 indicating forever.
public  voidsetGCEnabled(boolean enabled)
     Sets whether garbage collection is enabled.
public  voidsetGCInterval(long millis)
     Sets the length of time between garbage collection and idle timeout runs. This is inexact - if there are many pools with garbage collection and/or the idle timeout enabled, there will not be a thread for each one, and several nearby actions may be combined.
public  voidsetGCMinIdleTime(long millis)
     Sets the minimum idle time to make an object eligible for garbage collection.
public  voidsetIdleTimeout(long millis)
     Sets the minimum idle time to release an unused object from the pool.
public  voidsetIdleTimeoutEnabled(boolean enableTimeout)
     Sets whether the pool should release instances that have not been used recently.
public  voidsetInvalidateOnError(boolean invalidate)
     Sets the response for object errors.
public  voidsetLastUsed(Object object)
     Sets the last used time for an object in the pool that is currently in use.
public  voidsetMaxIdleTimeoutPercent(float percent)
     Sets the idle timeout percent as a fraction between 0 and 1.
public  voidsetMaxSize(int size)
     Sets the maximum size of the pool.
public  voidsetMinSize(int size)
     Sets the minimum size of the pool.
public  voidsetName(String name)
     Sets the name of the pool.
public  voidsetObjectFactory(PoolObjectFactory factory)
     Sets the object factory for the pool.
public  voidsetObjectFactory(Class javaBeanClass)
     Sets the object factory as a new factory for Java Beans.
public  voidsetTimestampUsed(boolean timestamp)
     Sets whether object clients can update the last used time.
public  voidshutDown()
     Shuts down the pool.
public  StringtoString()
     Returns the pool name and status.


Constructor Detail
ObjectPool
public ObjectPool()(Code)
Creates a new pool. It cannot be used until you specify a name and object factory or bean class, and initialize it.
See Also:   ObjectPool.setName
See Also:   ObjectPool.setObjectFactory
See Also:   ObjectPool.initialize



ObjectPool
public ObjectPool(PoolObjectFactory factory, String poolName)(Code)
Creates a new pool with the specified parameters. It cannot be used until you initialize it.
Parameters:
  factory - The object factory that will create the objects to go inthe pool.
Parameters:
  poolName - The name of the pool. This does not have to be uniqueacross all pools, but it is strongly recommended (and it may be arequirement for certain uses of the pool).
See Also:   ObjectPool.initialize



ObjectPool
public ObjectPool(Class javaBeanClass, String poolName)(Code)
Creates a new pool with the specified parameters. It cannot be used until you initialize it.
Parameters:
  javaBeanClass - The Class of a Java Bean. New instances for thepool will be created with the no-argument constructor, and noparticular initialization or cleanup will be performed on theinstances. Use a PoolObjectFactory if you want more control overthe instances.
Parameters:
  poolName - The name of the pool. This does not have to be uniqueacross all pools, but it is strongly recommended (and it may be arequirement for certain uses of the pool).
See Also:   ObjectPool.initialize




Method Detail
fillToMin
public void fillToMin()(Code)



getBlockingTimeout
public int getBlockingTimeout()(Code)
get how long this pool will wait for a free object while blocking



getGCInterval
public long getGCInterval()(Code)
Gets the length of time between garbage collection and idle timeout runs.
See Also:   ObjectPool.setGCInterval



getGCMinIdleTime
public long getGCMinIdleTime()(Code)
Gets the minimum idle time to make an object eligible for garbage collection.
See Also:   ObjectPool.setGCMinIdleTime



getIdleTimeout
public long getIdleTimeout()(Code)
Gets the minimum idle time to release an unused object from the pool.
See Also:   ObjectPool.setIdleTimeout



getMaxIdleTimeoutPercent
public float getMaxIdleTimeoutPercent()(Code)
Gets the idle timeout percent as a fraction between 0 and 1.
See Also:   ObjectPool.setMaxIdleTimeoutPercent



getMaxSize
public int getMaxSize()(Code)
Gets the maximum size of the pool.
See Also:   ObjectPool.setMaxSize



getMinSize
public int getMinSize()(Code)
Gets the minimum size of the pool.
See Also:   ObjectPool.setMinSize



getName
public String getName()(Code)
Gets the name of the pool.



getNextGCMillis
long getNextGCMillis(long now)(Code)



getObject
public Object getObject()(Code)
Gets an object from the pool. If all the objects in the pool are in use, creates a new object, adds it to the pool, and returns it. If all objects are in use and the pool is at maximum size, will block or return null.
See Also:   ObjectPool.setBlocking



getObject
public Object getObject(Object parameters)(Code)
Gets an object that fits the specified parameters from the pool. If all the objects in the pool are in use or don't fit, creates a new object, adds it to the pool, and returns it. If all objects are in use or don't fit and the pool is at maximum size, will block or return null.
See Also:   ObjectPool.setBlocking



initialize
public void initialize()(Code)
Prepares the pool for use. This must be called exactly once before getObject is even called. The pool name and object factory must be set before this call will succeed.
throws:
  java.lang.IllegalStateException - Occurs when you try to initialize the pool without setting the objectfactory or name, or you initialize the pool more than once.



isBlocking
public boolean isBlocking()(Code)
Gets whether a request for an object will block if the pool size is maxed out and no objects are available.
See Also:   ObjectPool.setBlocking



isGCEnabled
public boolean isGCEnabled()(Code)
Gets whether garbage collection is enabled.
See Also:   ObjectPool.setGCEnabled



isIdleTimeoutEnabled
public boolean isIdleTimeoutEnabled()(Code)
Gets whether the pool releases instances that have not been used recently. This is different than garbage collection, which returns instances to the pool if a client checked an instance out but has not used it and not returned it to the pool.
See Also:   ObjectPool.setIdleTimeoutEnabled



isInvalidateOnError
public boolean isInvalidateOnError()(Code)
Gets whether objects are removed from the pool in case of errors.



isTimeToGC
boolean isTimeToGC()(Code)



isTimestampUsed
public boolean isTimestampUsed()(Code)
Gets whether object clients can update the last used time.



markObjectAsInvalid
public void markObjectAsInvalid(Object object)(Code)
Indicates that an object is no longer valid, and should be removed from the pool entirely. This should be called before the object is returned to the pool (specifically, before factory.returnObject returns), or else the object may be given out again by the time this is called! Also, you still need to actually return the object to the pool by calling releaseObject, if you aren't calling this during that process already.
Parameters:
  object - The object to invalidate, which must be the exact objectreturned by getObject



objectClosed
public void objectClosed(PoolEvent evt)(Code)
If the object has been closed, release it.



objectError
public void objectError(PoolEvent evt)(Code)
If the invalidateOnError flag is set, the object will be removed from the pool entirely when the client has finished with it.



objectUsed
public void objectUsed(PoolEvent evt)(Code)
If we're tracking the last used times, update the last used time for the specified object.



releaseObject
public void releaseObject(Object object)(Code)
Returns an object to the pool. This must be the exact object that was given out by getObject, and it must be returned to the same pool that generated it. If other clients are blocked waiting on an object, the object may be re-released immediately.
throws:
  java.lang.IllegalArgumentException - Occurs when the object is not in this pool.



runGCandShrink
void runGCandShrink()(Code)



setBlocking
public void setBlocking(boolean blocking)(Code)
Sets whether a request for an object will block if the pool size is maxed out and no objects are available. If set to block, the request will not return until an object is available. Otherwise, the request will return null immediately (and may be retried). If multiple requests block, there is no guarantee which will return first. The default is to block.
throws:
  java.lang.IllegalStateException - Occurs when you try to set the blocking parameter after thepool has been initialized.



setBlockingTimeout
public void setBlockingTimeout(int blockingTimeout)(Code)
sets how long to wait for a free object when blocking, -1 indicating forever.



setGCEnabled
public void setGCEnabled(boolean enabled)(Code)
Sets whether garbage collection is enabled. This is the process of returning objects to the pool if they have been checked out of the pool but have not been used in a long periond of time. This is meant to reclaim resources, generally caused by unexpected failures on the part of the pool client (which forestalled returning an object to the pool). This runs on the same schedule as the idle timeout (if enabled), but objects that were just garbage collected will not be eligible for the idle timeout immediately (after all, they presumably represented "active" clients). Objects that are garbage collected will be checked out again immediately if a client is blocking waiting for an object. The default value is disabled.
See Also:   ObjectPool.setGCMinIdleTime
See Also:   ObjectPool.setGCInterval
throws:
  java.lang.IllegalStateException - Occurs when you try to set the garbage collection state after the poolhas been initialized.



setGCInterval
public void setGCInterval(long millis)(Code)
Sets the length of time between garbage collection and idle timeout runs. This is inexact - if there are many pools with garbage collection and/or the idle timeout enabled, there will not be a thread for each one, and several nearby actions may be combined. Likewise if the collection process is lengthy for certain types of pooled objects (not recommended), other actions may be delayed. This is to prevend an unnecessary proliferation of threads. Note that this parameter controls both garbage collection and the idle timeout - and they will be performed together if both are enabled. The deafult value is 2 minutes.
throws:
  java.lang.IllegalStateException - Occurs when you try to set the garbage collection interval after thepool has been initialized.



setGCMinIdleTime
public void setGCMinIdleTime(long millis)(Code)
Sets the minimum idle time to make an object eligible for garbage collection. If the object is in use and has not been used for this amount of time, it may be returned to the pool. If timestamps are enabled, the client may update the last used time (this is generally recommended if garbage collection is enabled). Otherwise, the last used time is only updated when an object is acquired or released. The default value is 20 minutes.
See Also:   ObjectPool.setGCEnabled
Parameters:
  millis - The idle time, in milliseconds.
throws:
  java.lang.IllegalStateException - Occurs when you try to set the garbage collection idle time after thepool has been initialized.



setIdleTimeout
public void setIdleTimeout(long millis)(Code)
Sets the minimum idle time to release an unused object from the pool. If the object is not in use and has not been used for this amount of time, it will be released from the pool. If timestamps are enabled, the client may update the last used time. Otherwise, the last used time is only updated when an object is acquired or released. The default value is 30 minutes.
See Also:   ObjectPool.setIdleTimeoutEnabled
Parameters:
  millis - The idle time, in milliseconds.
throws:
  java.lang.IllegalStateException - Occurs when you try to set the idle timeout after the poolhas been initialized.



setIdleTimeoutEnabled
public void setIdleTimeoutEnabled(boolean enableTimeout)(Code)
Sets whether the pool should release instances that have not been used recently. This is intended to reclaim resources (memory, database connections, file handles, etc) during periods of inactivity. This runs as often as garbage collection (even if garbage collection is disabled, this uses the same timing parameter), but the required period of inactivity is different. All objects that have been unused for more than the idle timeout are closed, but if you set the MaxIdleShrinkPercent parameter, the pool may recreate some objects so the total number of pooled instances doesn't shrink as rapidly. Also, under no circumstances will the number of pooled instances fall below the minimum size.

The default is disabled.


See Also:   ObjectPool.setGCInterval
See Also:   ObjectPool.setIdleTimeout
See Also:   ObjectPool.setMaxIdleTimeoutPercent
See Also:   ObjectPool.setMinSize
throws:
  java.lang.IllegalStateException - Occurs when you try to set the idle timeout state after the pool hasbeen initialized.



setInvalidateOnError
public void setInvalidateOnError(boolean invalidate)(Code)
Sets the response for object errors. If this flag is set and an error event occurs, the object is removed from the pool entirely. Otherwise, the object is returned to the pool of available objects. For example, a SQL error may not indicate a bad database connection (flag not set), while a TCP/IP error probably indicates a bad network connection (flag set). If this flag is not set, you can still manually invalidate objects using markObjectAsInvalid.
See Also:   ObjectPool.markObjectAsInvalid
See Also:   ObjectPool.objectError



setLastUsed
public void setLastUsed(Object object)(Code)
Sets the last used time for an object in the pool that is currently in use. If the timestamp parameter is not set, this call does nothing. Otherwise, the object is marked as last used at the current time.
throws:
  java.lang.IllegalArgumentException - Occurs when the object is not recognized by the factory or notin the pool.
throws:
  java.lang.IllegalStateException - Occurs when the object is not currently in use.
See Also:   ObjectPool.setTimestampUsed



setMaxIdleTimeoutPercent
public void setMaxIdleTimeoutPercent(float percent)(Code)
Sets the idle timeout percent as a fraction between 0 and 1. If a number of objects are determined to be idle, they will all be closed and removed from the pool. However, if the ratio of objects released to objects in the pool is greater than this fraction, some new objects will be created to replace the closed objects. This prevents the pool size from decreasing too rapidly. Set to 0 to decrease the pool size by a maximum of 1 object per test, or 1 to never replace objects that have exceeded the idle timeout. The pool will always replace enough closed connections to stay at the minimum size.
See Also:   ObjectPool.setIdleTimeoutEnabled
throws:
  java.lang.IllegalStateException - Occurs when you try to set the idle timeout percent after the poolhas been initialized.
throws:
  java.lang.IllegalArgumentException - Occurs when the percent parameter is not between 0 and 1.



setMaxSize
public void setMaxSize(int size)(Code)
Sets the maximum size of the pool. Once the pool has grown to hold this number of instances, it will not add any more instances. If one of the pooled instances is available when a request comes in, it will be returned. If none of the pooled instances are available, the pool will either block until an instance is available, or return null. The default is no maximum size.
See Also:   ObjectPool.setBlocking
Parameters:
  size - The maximum size of the pool, or 0 if the pool should growindefinitely (not recommended).
throws:
  java.lang.IllegalStateException - Occurs when you try to set the maximum size after the pool has beeninitialized.



setMinSize
public void setMinSize(int size)(Code)
Sets the minimum size of the pool. The pool will create this many instances at startup, and once running, it will never shrink below this size. The default is zero.
throws:
  java.lang.IllegalStateException - Occurs when you try to set the minimum size after the pool has beeninitialized.



setName
public void setName(String name)(Code)
Sets the name of the pool. This is not required to be unique across all pools, but is strongly recommended. Certain uses of the pool (such as a JNDI object factory) may require it. This must be set exactly once for each pool (it may be set in the constructor).
throws:
  java.lang.IllegalStateException - Occurs when you try to set the name of the pool more than once.



setObjectFactory
public void setObjectFactory(PoolObjectFactory factory)(Code)
Sets the object factory for the pool. The object factory controls the instances created for the pool, and can initialize instances given out by the pool and cleanup instances returned to the pool.
throws:
  java.lang.IllegalStateException - Occurs when you try to set the object factory after the pool has beeninitialized.



setObjectFactory
public void setObjectFactory(Class javaBeanClass)(Code)
Sets the object factory as a new factory for Java Beans. New instances for the pool will be created with the no-argument constructor, and no particular initialization or cleanup will be performed on the instances.
throws:
  java.lang.IllegalStateException - Occurs when you try to set the object factory after the pool has beeninitialized.



setTimestampUsed
public void setTimestampUsed(boolean timestamp)(Code)
Sets whether object clients can update the last used time. If not, the last used time will only be updated when the object is given to a client and returned to the pool. This time is important if the idle timeout or garbage collection is enabled (particularly the latter). The default is false.
throws:
  java.lang.IllegalStateException - Occurs when you try to set the timestamp parameter after thepool has been initialized.



shutDown
public void shutDown()(Code)
Shuts down the pool. All outstanding objects are closed and all objects are released from the pool. No getObject or releaseObject calls will succeed after this method is called - and they will probably fail during this method call.



toString
public String toString()(Code)
Returns the pool name and status.



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.