]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/pools/class_BasePool.php
Exceptions, interfaces and many classes added/rewritten:
[hub.git] / application / hub / main / pools / class_BasePool.php
index b585fc2ca4a1b624669982563daedd15071abb33..0a52e48358c78c36a6ce0b071999ce95a53ab83f 100644 (file)
  * 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 BasePool extends BaseHubSystem {
+class BasePool extends BaseHubSystem implements Visitable {
        /**
         * A list of pool entries
         */
-       private $poolEntries = array();
+       private $poolEntriesInstance = null;
 
        /**
         * Protected constructor
@@ -36,6 +36,9 @@ class BasePool extends BaseHubSystem {
        protected function __construct ($className) {
                // Call parent constructor
                parent::__construct($className);
+
+               // Init the pool entries
+               $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class');
        }
 
        /**
@@ -47,7 +50,14 @@ class BasePool extends BaseHubSystem {
         * @return      void
         */
        protected final function addInstance ($group, $poolName, Visitable $instance) {
-               $this->poolEntries[$group][$poolName][] = $instance;
+               // Is the pool group there?
+               if (!$this->poolEntriesInstance->isGroupSet($group)) {
+                       // Create the missing pool group
+                       $this->poolEntriesInstance->addGroup($group);
+               } // END - if
+
+               // Add it to given pool group
+               $this->poolEntriesInstance->addInstance($group, $poolName, $instance);
        }
 
        /**
@@ -57,7 +67,48 @@ class BasePool extends BaseHubSystem {
         * @return      void
         */
        protected final function addPoolEntry ($poolEntry) {
-               $this->poolEntries[] = $poolEntry;
+               $this->poolEntriesInstance->addEntry('generic', $poolEntry);
+       }
+
+       /**
+        * Accepts the visitor to rpocess the visit "request"
+        *
+        * @param       $visitorInstance        An instance of a Visitor class
+        * @return      void
+        */
+       public function accept (Visitor $visitorInstance) {
+               // Debug message
+               $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START');
+
+               // Visit this pool
+               $visitorInstance->visitPool($this);
+
+               // Get a new iterator instance
+               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_pool_iterator_class', array($this->poolEntriesInstance));
+
+               // Reset the counter
+               $iteratorInstance->rewind();
+
+               // Visit all registered entries
+               while ($iteratorInstance->valid()) {
+                       // Get current entry
+                       $poolEntry = $iteratorInstance->current();
+
+                       // Is this entry visitable?
+                       if ($poolEntry instanceof Visitable) {
+                               // Visit this entry as well
+                               $poolEntry->accept($visitorInstance);
+                       } else {
+                               // Cannot visit this entry
+                               $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . '.');
+                       }
+
+                       // Advance to next entry
+                       $iteratorInstance->next();
+               } // END - while
+
+               // Debug message
+               $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
        }
 }