* 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
protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
+
+ // Init the pool entries
+ $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class');
}
/**
* @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);
}
/**
* @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');
}
}