|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectzinger.util.recycling.ObjectRecycler
public class ObjectRecycler
Basic implementation of ObjectPool
interface.
This implementation uses an internal collection to manage pooled instances. It is not thread-safe
and does not guaranteed how large it will grow.
Field Summary | |
---|---|
protected ObjectGenerator |
generator
|
protected java.util.List |
instances
Instance cache. |
Constructor Summary | |
---|---|
ObjectRecycler(ObjectGenerator generator)
|
|
ObjectRecycler(ObjectGenerator generator,
java.util.List instances)
|
Method Summary | |
---|---|
void |
clearCache()
Clears existing cache. |
java.lang.Object |
getObject()
Calls getObject(null) . |
java.lang.Object |
getObject(java.lang.Object arg)
Gets an instance either out of the cache, or a newly generated one and asks it to be prepared for reuse. |
void |
instantiate(int nInstances)
|
boolean |
recycleObject(java.lang.Object obj)
Puts obj into the cache. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.util.List instances
protected final ObjectGenerator generator
Constructor Detail |
---|
public ObjectRecycler(ObjectGenerator generator, java.util.List instances)
public ObjectRecycler(ObjectGenerator generator)
Method Detail |
---|
public void instantiate(int nInstances)
public final java.lang.Object getObject() throws java.lang.IllegalArgumentException
getObject(null)
.
getObject
in interface ObjectPool
java.lang.IllegalArgumentException
getObject(java.lang.Object)
public java.lang.Object getObject(java.lang.Object arg) throws java.lang.IllegalArgumentException
getObject
in interface ObjectPool
arg
- Initialization parameter. If null
, default initialziation is used.
java.lang.IllegalArgumentException
ObjectGenerator.prepareObject(java.lang.Object, java.lang.Object)
public boolean recycleObject(java.lang.Object obj)
obj
into the cache. It is the user's responsibility to make sure only
the objects that were generated this instance are returned. If getObject
method encounters a bad instance from the cache, it will discard it and go on to the next one.
recycleObject
in interface ObjectPool
getObject(java.lang.Object)
public void clearCache()
ObjectPool
clearCache
in interface ObjectPool
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |