]> git.mxchange.org Git - hub.git/commitdiff
Rewrote endless creation of iterator instances to registry-based 'caching'
authorRoland Häder <roland@mxchange.org>
Mon, 25 Apr 2011 19:48:14 +0000 (19:48 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 25 Apr 2011 19:48:14 +0000 (19:48 +0000)
application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php
application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php
application/hub/main/pools/class_BasePool.php

index 67a0f2319d99472d5575161ab3a74958fb5b7751..72a2c2d866a7a37ab7fab0d6b0a52dee1f5238b9 100644 (file)
@@ -23,7 +23,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class MonitorPoolIterator extends BaseIterator implements Iterator {
+class MonitorPoolIterator extends BaseIterator implements Iterator, Registerable {
        /**
         * Key for the global list index
         */
index 3cee6a26d4dde347a6f6eed9dcdca33d1178a5bf..f82dbf3eaa64eeb906b2c7def1cc732311b57d1f 100644 (file)
@@ -23,7 +23,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class TaskPoolIterator extends BaseIterator implements Iterator {
+class TaskPoolIterator extends BaseIterator implements Iterator, Registerable {
        /**
         * Key for the global list index
         */
index 462d3ad1f6c9e06a42d36bc14a5da402f9a45d0a..2e6c5c8955163af171e06a0cb0569d26bd9b2aed 100644 (file)
@@ -92,8 +92,17 @@ class BasePool extends BaseHubSystem implements Visitable {
                // Visit this pool
                $visitorInstance->visitPool($this);
 
-               // Get a new iterator instance
-               $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
+               // Do we have a registry instance for this visitor's iterator?
+               if (Registry::getRegistry()->instanceExists($visitorInstance->getVisitorMode() . '_pool_iterator')) {
+                       // Get the instance from registry
+                       $iteratorInstance = Registry::getRegistry()->getInstance($visitorInstance->getVisitorMode() . '_pool_iterator');
+               } else {
+                       // Get a new iterator instance
+                       $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
+
+                       // Add it to the registry
+                       Registry::getRegistry()->addInstance($visitorInstance->getVisitorMode() . '_pool_iterator', $iteratorInstance);
+               }
 
                // Reset the counter
                $iteratorInstance->rewind();