application/hub/debug.php -text
application/hub/exceptions.php -text
application/hub/exceptions/.htaccess -text
+application/hub/exceptions/lists/.htaccess -text
+application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php -text
+application/hub/exceptions/lists/class_NoListGroupException.php -text
application/hub/init.php -text
application/hub/interfaces/.htaccess -text
application/hub/interfaces/connectors/.htaccess -text
application/hub/interfaces/connectors/class_Connectable.php -text
application/hub/interfaces/listener/.htaccess -text
application/hub/interfaces/listener/class_Listenable.php -text
+application/hub/interfaces/lists/.htaccess -text
+application/hub/interfaces/lists/class_Listable.php -text
application/hub/interfaces/nodes/.htaccess -text
application/hub/interfaces/nodes/class_NodeHelper.php -text
application/hub/interfaces/pool/.htaccess -text
application/hub/interfaces/states/hub/class_HubStateable.php -text
application/hub/interfaces/visitor/.htaccess -text
application/hub/interfaces/visitor/class_Visitable.php -text
+application/hub/interfaces/visitor/class_Visitor.php -text
+application/hub/interfaces/visitor/pool/.htaccess -text
+application/hub/interfaces/visitor/pool/class_PoolVisitor.php -text
application/hub/loader.php -text
application/hub/main/.htaccess -text
application/hub/main/class_ -text
application/hub/main/filter/shutdown/class_HubShutdownFlushNodeListFilter.php -text
application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php -text
application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php -text
+application/hub/main/iterator/.htaccess -text
+application/hub/main/iterator/class_ -text
+application/hub/main/iterator/class_BaseIterator.php -text
+application/hub/main/iterator/pool/.htaccess -text
+application/hub/main/iterator/pool/class_ShutdownPoolIterator.php -text
application/hub/main/listener/.htaccess -text
application/hub/main/listener/class_ -text
application/hub/main/listener/class_BaseListener.php -text
application/hub/main/listener/udp/decorators/.htaccess -text
application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php -text
application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php -text
+application/hub/main/lists/.htaccess -text
+application/hub/main/lists/class_ -text
+application/hub/main/lists/class_BaseList.php -text
+application/hub/main/lists/groups/.htaccess -text
+application/hub/main/lists/groups/class_ListGroupList.php -text
+application/hub/main/lists/pool/.htaccess -text
+application/hub/main/lists/pool/class_PoolEntriesList.php -text
application/hub/main/nodes/.htaccess -text
application/hub/main/nodes/boot/.htaccess -text
application/hub/main/nodes/boot/class_HubBootNode.php -text
application/hub/main/states/client/class_BaseClientState.php -text
application/hub/main/states/hub/.htaccess -text
application/hub/main/states/hub/class_BaseHubState.php -text
+application/hub/main/visitor/.htaccess -text
+application/hub/main/visitor/class_ -text
+application/hub/main/visitor/class_BaseVisitor.php -text
+application/hub/main/visitor/shutdown/.htaccess -text
+application/hub/main/visitor/shutdown/class_Shutdown -text
+application/hub/main/visitor/shutdown/class_ShutdownListenerPoolVisitor.php -text
application/hub/starter.php -text
/clear-cache.sh -text
db/.htaccess -text
// CFG: CLIENT-POOL-CLASS
$cfg->setConfigEntry('client_pool_class', 'DefaultClientPool');
+// CFG: POOL-ENTRIES-LIST-CLASS
+$cfg->setConfigEntry('pool_entries_list_class', 'PoolEntriesList');
+
+// CFG: LISTENER-POOL-VISITOR-CLASS
+$cfg->setConfigEntry('listener_pool_visitor_class', 'ShutdownListenerPoolVisitor');
+
+// CFG: SHUTDOWN-POOL-ITERATOR-CLASS
+$cfg->setConfigEntry('shutdown_pool_iterator_class', 'ShutdownPoolIterator');
+
+// CFG: LIST-GROUP-CLASS
+$cfg->setConfigEntry('list_group_class', 'ListGroupList');
+
// CFG: DEFAULT-CONSOLE-COMMAND
$cfg->setConfigEntry('default_console_command', 'main');
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * This exception is thrown when a list group is already added
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 ListGroupAlreadyAddedException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $messageArray Error message array
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (array $messageArray, $code) {
+ // Construct the message
+ $message = sprintf("[%s] List group <span class=\"exception_reason\">%s</span> has already been added.",
+ $messageArray[0]->__toString(),
+ $messageArray[1]
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * This exception is thrown when a list group is not found
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 NoListGroupException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $messageArray Error message array
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (array $messageArray, $code) {
+ // Construct the message
+ $message = sprintf("[%s] List group <span class=\"exception_reason\">%s</span> was not found.",
+ $messageArray[0]->__toString(),
+ $messageArray[1]
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-interface Listenable {
+interface Listenable extends FrameworkInterface {
/**
* Initializes the listener by setting up the required socket server
*
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for lists
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Listable extends FrameworkInterface, IteratorAggregate {
+ /**
+ * Checks wether the given group is set
+ *
+ * @param $groupName Group to check if found in list
+ * @return $isset Wether the group is valid
+ */
+ function isGroupSet ($groupName);
+
+ /**
+ * Adds the given group or if already added issues a ListGroupAlreadyAddedException
+ *
+ * @param $groupName Group to add
+ * @return void
+ * @throws ListGroupAlreadyAddedException If the given group is already added
+ */
+ function addGroup ($groupName);
+
+ /**
+ * Adds the given instance to list group and sub group
+ *
+ * @param $groupName Group to add instance to
+ * @param $subGroup Sub group to add instance to
+ * @param $instance An instance of Visitable
+ * @return void
+ * @throws NoListGroupException If the given group is not found
+ */
+ function addInstance ($groupName, $subGroup, Visitable $instance);
+
+ /**
+ * Adds the given entry to list group
+ *
+ * @param $groupName Group to add instance to
+ * @param $entry An entry of any type
+ * @return void
+ * @throws NoListGroupException If the given group is not found
+ */
+ function addEntry ($groupName, $entry);
+}
+
+//
+?>
<?php
/**
- * An interface for the visitor pattern
+ * An interface for a visitable class that 'accepts' visitors
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface Visitable extends FrameworkInterface {
+ /**
+ * Accepts the visitor to rpocess the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ function accept (Visitor $visitorInstance);
}
//
--- /dev/null
+<?php
+/**
+ * An interface for the visitor implementation
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Visitor extends FrameworkInterface {
+}
+
+//
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for the visitor implementation for pools
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface PoolVisitor extends Visitor {
+ /**
+ * Visits the given pool instance
+ *
+ * @param $poolInstance A Poolable instance
+ * @return void
+ */
+ function visitPool (Poolable $poolInstance);
+}
+
+//
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? iterator
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 ???Iterator extends BaseIterator implements Iterator {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public final static function create???Iterator () {
+ // Get new instance
+ $iteratorInstance = new ???Iterator();
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ */
+ public function current () {
+ // Default is null
+ $current = null;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $key Current key in iteration
+ */
+ public function key () {
+ // Default is null
+ $key = null;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $key;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Checks wether the current entry is valid (not at the end of the list)
+ *
+ * @return void
+ */
+ public function valid () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general iterator
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 BaseIterator extends BaseHubSystem {
+ /**
+ * Instance of the list
+ */
+ private $listInstance = null;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Setter for the list instance
+ *
+ * @param $listInstance A list of IteratorAggregate
+ * @return void
+ */
+ protected final function setListInstance (IteratorAggregate $listInstance) {
+ $this->listInstance = $listInstance;
+ }
+
+ /**
+ * Getter for the list instance
+ *
+ * @return $listInstance A list of IteratorAggregate
+ */
+ protected final function getListInstance () {
+ return $this->listInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ShutdownPool iterator
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 ShutdownPoolIterator extends BaseIterator implements Iterator {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listInstance A list of a IteratorAggregate
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public final static function createShutdownPoolIterator (IteratorAggregate $listInstance) {
+ // Get new instance
+ $iteratorInstance = new ShutdownPoolIterator();
+
+ // Set the list
+ $iteratorInstance->setListInstance($listInstance);
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ */
+ public function current () {
+ // Default is null
+ $current = null;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $key Current key in iteration
+ */
+ public function key () {
+ // Default is null
+ $key = null;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $key;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Checks wether the current entry is valid (not at the end of the list)
+ *
+ * @return void
+ */
+ public function valid () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
protected final function getPoolInstance () {
return $this->poolInstance;
}
+
+ /**
+ * 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('LISTENER: ' . $visitorInstance->__toString() . ' has visited - START');
+
+ // Visit this listener
+ $visitorInstance->visitListener($this);
+
+ // Visit the pool
+ $this->getPoolInstance()->accept($visitor);
+
+ // Debug message
+ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
+ }
}
// [EOF]
public final function getProtocol () {
return $this->getListenerInstance()->getProtocol();
}
+
+ /**
+ * 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('DECO-LISTENER: ' . $visitorInstance->__toString() . ' has visited - START');
+
+ // Visit this decorator
+ $visitorInstance->visitDecorator($this);
+
+ // Visit the covered class
+ $this->getListenerInstance()->accept($visitorInstance);
+
+ // Debug message
+ $this->debugOutput('DECO-LISTENER: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
+ }
}
// [EOF]
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? list
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 ???List extends BaseList implements Listable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $listInstance An instance a Listable class
+ */
+ public final static function create???List () {
+ // Get new instance
+ $listInstance = new ???List();
+
+ // Return the prepared instance
+ return $listInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general list class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 BaseList extends BaseHubSystem implements IteratorAggregate {
+ // Exception constants
+ const EXCEPTION_GROUP_ALREADY_ADDED = 0xf20;
+ const EXCEPTION_GROUP_NOT_FOUND = 0xf21;
+
+ /**
+ * List groups array
+ */
+ private $listGroups = array();
+
+ /**
+ * List entries array
+ */
+ private $listEntries = array();
+
+ /**
+ * List index array
+ */
+ private $listIndex = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Remove some attributes
+ $this->removeNumberFormaters();
+ $this->removeSystemArray();
+ }
+
+ /**
+ * Getter for iterator instance from this list
+ *
+ * @return $iteratorInstance An instance of a Iterator class
+ */
+ public function getIterator () {
+ // Prepare a default iterator
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('default_iterator_class');
+
+ // And return it
+ return $iteratorInstance;
+ }
+
+ /**
+ * Checks wether the given group is set
+ *
+ * @param $groupName Group to check if found in list
+ * @return $isset Wether the group is valid
+ */
+ public function isGroupSet ($groupName) {
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName);
+ return isset($this->listGroups[$groupName]);
+ }
+
+ /**
+ * Adds the given group or if already added issues a ListGroupAlreadyAddedException
+ *
+ * @param $groupName Group to add
+ * @return void
+ * @throws ListGroupAlreadyAddedException If the given group is already added
+ */
+ public function addGroup ($groupName) {
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . ' - START');
+ // Is the group already added?
+ if ($this->isGroupSet($groupName)) {
+ // Throw the exception here
+ throw new ListGroupAlreadyAddedException(array($this, $groupName), self::EXCEPTION_GROUP_ALREADY_ADDED);
+ } // END - if
+
+ // Add the group which is a simple array
+ $this->listGroups[$groupName] = ObjectFactory::createObjectByConfiguredName('list_group_class');
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . ' - FINISHED');
+ }
+
+ /**
+ * Adds the given instance to list group and sub group
+ *
+ * @param $groupName Group to add instance to
+ * @param $subGroup Sub group to add instance to
+ * @param $instance An instance of Visitable
+ * @return void
+ * @throws NoListGroupException If the given group is not found
+ */
+ public function addInstance ($groupName, $subGroup, Visitable $instance) {
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START');
+ // Is the group there?
+ if (!$this->isGroupSet($groupName)) {
+ // Throw the exception here
+ throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
+ } // END - if
+
+ // Is the sub group there?
+ if (!$this->listGroups[$groupName]->isGroupSet($subGroup)) {
+ // Automatically add it
+ $this->listGroups[$groupName]->addGroup($subGroup);
+ } // END - if
+
+ // Generate the hash
+ $hash = $this->generateHash($groupName, $subGroup, $instance);
+
+ // Now add it to the group list and hash it
+ $this->listGroups[$groupName]->addEntry($subGroup, $hash);
+
+ // Add the hash to the index
+ $this->listIndex[] = $hash;
+
+ // Add the instance itself to the list
+ $this->listEntries[$hash] = $instance;
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START');
+ }
+
+ /**
+ * Adds the given entry to list group
+ *
+ * @param $groupName Group to add instance to
+ * @param $entry An entry of any type
+ * @return void
+ * @throws NoListGroupException If the given group is not found
+ */
+ public function addEntry ($groupName, $entry) {
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . ' - START');
+ // Is the group already added?
+ if (!$this->isGroupSet($groupName)) {
+ // Throw the exception here
+ throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
+ } // END - if
+
+ // Generate hash
+ $hash = $this->generateHash($groupName, $groupName, $entry);
+
+ // Add the hash to the index
+ $this->listIndex[] = $hash;
+
+ // Now add the entry to the list
+ $this->listEntries[$hash] = $entry;
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . ' - FINISHED');
+ }
+
+ /**
+ * Generates a hash from given group, sub group and entry
+ *
+ * @param $groupName Group to add instance to
+ * @param $subGroup Sub group to add instance to
+ * @param $entry An entry of any type
+ * @return $hash The generated
+ */
+ private function generateHash ($groupName, $subGroup, $entry) {
+ // Created entry, 'null' is default
+ $entry2 = 'null';
+
+ // Determine type of entry
+ if (is_null($entry)) {
+ // Ignore this
+ } elseif ($entry instanceof FrameworkInterface) {
+ // Own instance detected
+ $entry2 = $entry->hashCode();
+ } elseif (!is_array($entry)) {
+ // Non-array found, use it directly with type
+ $entry2 = gettype($entry) . ':' . $entry2;
+ } else {
+ // Arrays are unsupported at the momement
+ $this->debugOutut(__METHOD__ . ': entry is an array. UNSUPPORTED!');
+
+ // @TODO Extend this somehow?
+ $entry2 = gettype($entry);
+ }
+
+ // Construct string which we shall hash
+ $hashString = $groupName . ':' . $subGroup . ':' . $entry2;
+
+ // Hash it with fastest hasher
+ $hash = crc32($hashString);
+
+ // And return it
+ return $hash;
+ }
+}
+
+//
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ListGroup list
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 ListGroupList extends BaseList implements Listable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $listInstance An instance a Listable class
+ */
+ public final static function createListGroupList () {
+ // Get new instance
+ $listInstance = new ListGroupList();
+
+ // Return the prepared instance
+ return $listInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A list for pool entries
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 PoolEntriesList extends BaseList implements Listable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $listInstance An instance a Listable class
+ */
+ public final static function createPoolEntriesList () {
+ // Get new instance
+ $listInstance = new PoolEntriesList();
+
+ // Add generic group
+ $listInstance->addGroup('generic');
+
+ // Return the prepared instance
+ return $listInstance;
+ }
+}
+
+//
+?>
* 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');
}
}
$listenerInstance->getListenPort() . ' added to listener pool.'
);
}
+
+ /**
+ * Run the shutdown seqeuence by a Visitor Pattern
+ *
+ * @return void
+ */
+ public function doShutdown () {
+ // Debug message
+ $this->debugOutput('POOL: Shutting down listener pool - START');
+
+ // Get a new visitor
+ $visitorInstance = ObjectFactory::createObjectByConfiguredName('listener_pool_visitor_class');
+
+ // Start visiting
+ $this->accept($visitorInstance);
+
+ // Debug message
+ $this->debugOutput('POOL: Shutting down listener pool - FINISHED');
+ }
}
// [EOF]
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? visitor
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 ???Visitor extends BaseVisitor implements Visitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public final static function create???Visitor () {
+ // Get new instance
+ $visitorInstance = new ???Visitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general visitor class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 BaseVisitor extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Remove some attributes
+ $this->removeNumberFormaters();
+ $this->removeSystemArray();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? shutdown visitor
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 Shutdown???Visitor extends BaseVisitor implements PoolVisitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public final static function createShutdown???Visitor () {
+ // Get new instance
+ $visitorInstance = new Shutdown???Visitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ListenerPool shutdown visitor
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 ShutdownListenerPoolVisitor extends BaseVisitor implements PoolVisitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public final static function createShutdownListenerPoolVisitor () {
+ // Get new instance
+ $visitorInstance = new ShutdownListenerPoolVisitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * Visits the given pool instance
+ *
+ * @param $poolInstance A Poolable instance
+ * @return void
+ */
+ public function visitPool (Poolable $poolInstance) {
+ // Debug message
+ $this->debugOutput('VISITOR: Visit of ' . $poolInstance->__toString() . ' - START');
+
+ // Pre-shutdown the pool
+ $poolInstance->preShutdown();
+
+ // Debug message
+ $this->debugOutput('VISITOR: Visit of ' . $poolInstance->__toString() . ' - FINISHED');
+ }
+}
+
+//
+?>