Details
-
Type: New Feature
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 1.0-beta-5
-
Fix Version/s: 1.0-beta-4
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Number of attachments :
Issue Links
- depends upon
-
PICO-55 Use PicoContainer as a factory of transient (unmanaged) objects.
Activity
Aslak Hellesøy
made changes -
Field | Original Value | New Value |
---|---|---|
Attachment | picopool-src.zip [ 10990 ] |
Aslak Hellesøy
made changes -
Aslak Hellesøy
made changes -
Assignee | Aslak Hellesoy [ rinkrank ] |
Aslak Hellesøy
made changes -
Status | Open [ 1 ] | In Progress [ 3 ] |
Paul Hammant
made changes -
Resolution | Fixed [ 1 ] | |
Status | In Progress [ 3 ] | Closed [ 6 ] |
Aslak Hellesøy
made changes -
Resolution | Fixed [ 1 ] | |
Status | Closed [ 6 ] | Reopened [ 4 ] |
Aslak Hellesøy
made changes -
Fix Version/s | 1.0-beta-4 [ 10412 ] | |
Status | Reopened [ 4 ] | Closed [ 6 ] |
Fix Version/s | 1.0 [ 10145 ] | |
Resolution | Fixed [ 1 ] |
From Ross Mason:
I have implemented a simple component pool which uses a PicoContainer for the pool and is itself picofiable. The pool supports exhausted policies ? Fail, Grow and Block.
This is what it looks like ?
//Creates a default pool of AnotherTouchable
DefaultPicoPool pool = new DefaultPicoPool(AnotherTouchable.class);
There is another constructor that accepts a PicoPoolConfiguration, i.e.
MutablePicoContainer pico = new DefaultPicoContainer();
PicoPoolConfiguration config = new PicoPoolConfiguration(AnotherTouchable.class, ...Other pool parameters);
pico.registerComponentInstance(config);
pico.registerComponentImplementation("myPool", DefaultPicoPool.class);
DefaultPicoPool pool = (DefaultPicoPool) pico.getComponentInstance("myPool");
To obtain objects call ?
Object borrowed = pool.borrowComponent();
And to return ?
Pool.returnComponent(borrowed);
I?ve included the source with test cases. I was also going to implement a keyed Pool version, but wanted to check I was on the right track.
Also, I started playing with a PicoPoolComponentAdapter that would provide pooling transparently i.e.
MutablePicoContainer pico = new DefaultPicoContainer(new PicoPoolComponentAdapterFactory());
pico.registerComponentImplementation(AnotherTouchable.class);
AnotherTouchable component = (AnotherTouchable)pico.getComponentInstance(AnotherTouchable.class);
component.wasTouched();
AnotherTouchable component2 = (AnotherTouchable)pico.getComponentInstance(AnotherTouchable.class);
assertTrue(!component2.isTouched());
I couldn?t think of a clean way of returning the object to the pool once it had been borrowed. Any ideas??
Cheers,
Ross
Ps this uses Zohar?s NonCachingComponentAdapter, so you?ll need that code to run it.