]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/pools/class_BasePool.php
Added a new task for listener pools and network package readers (for abstract Network...
[hub.git] / application / hub / main / pools / class_BasePool.php
index efa9aa9da21c325be497c96c860477499129fa51..458dc656dac16e5d977308a95d64dfb866403ff3 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
  * 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,18 @@ 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');
+       }
+
+       /**
+        * Getter for pool entries instance
+        *
+        * @return      $poolEntriesInstance    An instance for pool entries (list)
+        */
+       public final function getPoolEntriesInstance () {
+               return $this->poolEntriesInstance;
        }
 
        /**
@@ -45,10 +57,16 @@ class BasePool extends BaseHubSystem {
         * @param       $poolSegment    Name of the pool segment
         * @param       $instance               An instance of a class we should add to the pool
         * @return      void
-        * @todo        Can we use Listenable instead of FrameworkInterface ?
         */
-       protected final function addInstance($group, $poolName, FrameworkInterface $instance) {
-               $this->poolEntries[$group][$poolName][] = $instance;
+       protected final function addInstance ($group, $poolName, Visitable $instance) {
+               // Is the pool group there?
+               if (!$this->getPoolEntriesInstance()->isGroupSet($group)) {
+                       // Create the missing pool group
+                       $this->getPoolEntriesInstance()->addGroup($group);
+               } // END - if
+
+               // Add it to given pool group
+               $this->getPoolEntriesInstance()->addInstance($group, $poolName, $instance);
        }
 
        /**
@@ -58,7 +76,62 @@ class BasePool extends BaseHubSystem {
         * @return      void
         */
        protected final function addPoolEntry ($poolEntry) {
-               $this->poolEntries[] = $poolEntry;
+               $this->getPoolEntriesInstance()->addEntry('generic', $poolEntry);
+       }
+
+       /**
+        * Accepts the visitor to process the visit "request"
+        *
+        * @param       $visitorInstance        An instance of a Visitor class
+        * @return      void
+        */
+       public function accept (Visitor $visitorInstance) {
+               // Debug message
+               //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START');
+
+               // Visit this pool
+               $visitorInstance->visitPool($this);
+
+               // Get a new iterator instance
+               $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
+
+               // 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
+               //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
+       }
+
+       /**
+        * Gets the array from specified list
+        *
+        * @param       $list   The list identifier we should return
+        * @return      $array  The requested array
+        */
+       protected final function getArrayFromList ($list) {
+               // Get the array
+               $array = $this->getPoolEntriesInstance()->getArrayFromList($list);
+
+               // Return it
+               return $array;
        }
 }