[picocontainer-scm] [5675] java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/containers/ReusablePicoContainer.java: Added better support for handling ComponentAdapters while flushing instances.

rimovm-yCVjj/[email protected]
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <[email protected]>
Revision 5675
Author rimovm
Date 2010-04-14 18:46:01 -0500 (Wed, 14 Apr 2010)

Log Message

Added better support for handling ComponentAdapters while flushing instances.

Modified Paths

- java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/containers/ReusablePicoContainer.java

Diff

Modified: java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/containers/ReusablePicoContainer.java (5674 => 5675)

--- java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/containers/ReusablePicoContainer.java 2010-04-13 12:56:19 UTC (rev 5674)
+++ java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/containers/ReusablePicoContainer.java 2010-04-14 23:46:01 UTC (rev 5675)
@@ -48,16 +48,28 @@
* common storage location would be ThreadLocal storage. HttpSession might be another valid
* storage location.</p>
* @author Michael Rimov
+ * @todo Convert to composition.
*/
@SuppressWarnings("serial")
public class ReusablePicoContainer extends DefaultPicoContainer {

+ /**
+ * A list of all addComponent(key, instance) calls that were made. These will be removed from the container
+ * each time the container is stopped.
+ */
private final List<ComponentAdapter<?>> instanceRegistrations = new ArrayList<ComponentAdapter<?>>();

+ /**
+ * A list of all addFlushableAdapter() calls that were made. These instances will be removed from
+ * the container each time it is stopped.
+ */
private final List<ComponentAdapter<?>> adapterRegistrations = new ArrayList<ComponentAdapter<?>>();

private final Map<ComponentAdapter<?>, Stored<?>> storedReferences = new HashMap<ComponentAdapter<?>, Stored<?>>();
-
+
+ /**
+ * Default constructor.
+ */
public ReusablePicoContainer() {
super();
}
@@ -155,10 +167,17 @@
}

@Override
- public synchronized void stop() {
+ public synchronized void stop() {
super.stop();
-
- //Remove all instance registrations.
+ flushInstances();
+ }
+
+ /**
+ * Automatically called by {@link #stop() stop()}, this method clears all instantiated
+ * instances and readies the picocontainer for reuse.
+ */
+ public void flushInstances() {
+ //Remove all instance registrations.
for (ComponentAdapter<?> eachAdapter : this.instanceRegistrations) {
this.removeComponent(eachAdapter.getComponentKey());
}
@@ -173,7 +192,7 @@
for (Stored<?> eachStoredBehavior : this.storedReferences.values()) {
eachStoredBehavior.flush();
}
- }
+ }

@Override
public MutablePicoContainer addAdapter(final ComponentAdapter<?> componentAdapter, final Properties properties) {

----------

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.