X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fpools%2Fclass_BasePool.php;h=67a3ed9e50253bca9a53105d5027590a7c29911c;hb=48e83cb812bffbcb9c5f86d97aca5a2b5d0b275b;hp=458dc656dac16e5d977308a95d64dfb866403ff3;hpb=d391ecd222ae868265735539d68a2c148711b5e3;p=hub.git diff --git a/application/hub/main/pools/class_BasePool.php b/application/hub/main/pools/class_BasePool.php index 458dc656d..67a3ed9e5 100644 --- a/application/hub/main/pools/class_BasePool.php +++ b/application/hub/main/pools/class_BasePool.php @@ -2,11 +2,11 @@ /** * A general pool class * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.shipsimu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,10 +22,21 @@ * along with this program. If not, see . */ class BasePool extends BaseHubSystem implements Visitable { + /** + * Socket array elements + */ + const SOCKET_ARRAY_RESOURCE = 'resource'; + const SOCKET_ARRAY_CONN_TYPE = 'connection_type'; + /** * A list of pool entries */ - private $poolEntriesInstance = null; + private $poolEntriesInstance = NULL; + + /** + * An array with all valid connection types + */ + private $connectionTypes = array(); /** * Protected constructor @@ -39,6 +50,13 @@ class BasePool extends BaseHubSystem implements Visitable { // Init the pool entries $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class'); + + // Init array of connection types + $this->connectionTypes = array( + BaseConnectionHelper::CONNECTION_TYPE_INCOMING, + BaseConnectionHelper::CONNECTION_TYPE_OUTGOING, + BaseConnectionHelper::CONNECTION_TYPE_SERVER + ); } /** @@ -53,12 +71,12 @@ class BasePool extends BaseHubSystem implements Visitable { /** * Adds an instance to a pool segment * - * @param $group Name of the pool group - * @param $poolSegment Name of the pool segment - * @param $instance An instance of a class we should add to the pool + * @param $group Name of the pool group + * @param $poolSegment Name of the pool segment + * @param $visitableInstance An instance of a class that should bed added to the pool * @return void */ - protected final function addInstance ($group, $poolName, Visitable $instance) { + protected final function addInstance ($group, $poolName, Visitable $visitableInstance) { // Is the pool group there? if (!$this->getPoolEntriesInstance()->isGroupSet($group)) { // Create the missing pool group @@ -66,17 +84,17 @@ class BasePool extends BaseHubSystem implements Visitable { } // END - if // Add it to given pool group - $this->getPoolEntriesInstance()->addInstance($group, $poolName, $instance); + $this->getPoolEntriesInstance()->addInstance($group, $poolName, $visitableInstance); } /** * Adds an entry to the pool * - * @param $poolEntry The new pool entry we should add + * @param $poolEntry The new pool entry that should be added * @return void */ protected final function addPoolEntry ($poolEntry) { - $this->getPoolEntriesInstance()->addEntry('generic', $poolEntry); + $this->getPoolEntriesInstance()->addEntry('pool', $poolEntry); } /** @@ -87,13 +105,22 @@ class BasePool extends BaseHubSystem implements Visitable { */ public function accept (Visitor $visitorInstance) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - START'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: ' . $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())); + // 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(); @@ -106,10 +133,11 @@ class BasePool extends BaseHubSystem implements Visitable { // Is this entry visitable? if ($poolEntry instanceof Visitable) { // Visit this entry as well + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-POOL[' . __METHOD__ . ':' . __LINE__ . ']: Going to visit pooled object ' . $poolEntry->__toString() . ' with visitor ' . $visitorInstance->__toString() . ' ...'); $poolEntry->accept($visitorInstance); } else { // Cannot visit this entry - $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . '.'); + $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . ', reason: not implementing Visitable.'); } // Advance to next entry @@ -117,7 +145,7 @@ class BasePool extends BaseHubSystem implements Visitable { } // END - while // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('POOL: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); } /** @@ -133,6 +161,20 @@ class BasePool extends BaseHubSystem implements Visitable { // Return it return $array; } + + /** + * Checks whether the given connection type is valid + * + * @param $connectionType Type of connection, can be 'incoming', 'outgoing' or 'server' + * @return $isValid Whether the provided connection type is valid + */ + protected function isValidConnectionType ($connectionType) { + // Is it valid? + $isValid = in_array($connectionType, $this->connectionTypes, TRUE); + + // Return result + return $isValid; + } } // [EOF]