From 3e4f9004d23813a2b1445efad81e2c373813f53c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 7 Jul 2009 20:50:23 +0000 Subject: [PATCH] Decorators for hub/client listeners added --- .gitattributes | 7 ++ application/hub/config.php | 12 +++ .../listener/class_BaseListenerDecorator.php | 84 +++++++++++++++++++ .../main/listener/tcp/decorators/.htaccess | 1 + .../class_ClientTcpListenerDecorator.php | 64 ++++++++++++++ .../class_HubTcpListenerDecorator.php | 64 ++++++++++++++ .../main/listener/udp/decorators/.htaccess | 1 + .../class_ClientUdpListenerDecorator.php | 64 ++++++++++++++ .../class_HubUdpListenerDecorator.php | 64 ++++++++++++++ .../hub/main/nodes/class_BaseHubNode.php | 52 +++++++++--- 10 files changed, 401 insertions(+), 12 deletions(-) create mode 100644 application/hub/main/listener/class_BaseListenerDecorator.php create mode 100644 application/hub/main/listener/tcp/decorators/.htaccess create mode 100644 application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php create mode 100644 application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php create mode 100644 application/hub/main/listener/udp/decorators/.htaccess create mode 100644 application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php create mode 100644 application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php diff --git a/.gitattributes b/.gitattributes index f8514f59f..0cff0ffc1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -43,10 +43,17 @@ application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php - application/hub/main/listener/.htaccess -text application/hub/main/listener/class_ -text application/hub/main/listener/class_BaseListener.php -text +application/hub/main/listener/class_BaseListenerDecorator.php -text application/hub/main/listener/tcp/.htaccess -text application/hub/main/listener/tcp/class_TcpListener.php -text +application/hub/main/listener/tcp/decorators/.htaccess -text +application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php -text +application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php -text application/hub/main/listener/udp/.htaccess -text application/hub/main/listener/udp/class_UdpListener.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/nodes/.htaccess -text application/hub/main/nodes/boot/.htaccess -text application/hub/main/nodes/boot/class_HubBootNode.php -text diff --git a/application/hub/config.php b/application/hub/config.php index 243bd3ac4..1b1f04a28 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -66,5 +66,17 @@ $cfg->setConfigEntry('tcp_listener_class', "TcpListener"); // CFG: UDP-LISTENER-CLASS $cfg->setConfigEntry('udp_listener_class', "UdpListener"); +// CFG: HUB-TCP-LISTENER-CLASS +$cfg->setConfigEntry('hub_tcp_listener_class', "HubTcpListenerDecorator"); + +// CFG: HUB-UDP-LISTENER-CLASS +$cfg->setConfigEntry('hub_udp_listener_class', "HubUdpListenerDecorator"); + +// CFG: CLIENT-TCP-LISTENER-CLASS +$cfg->setConfigEntry('client_tcp_listener_class', "ClientTcpListenerDecorator"); + +// CFG: CLIENT-UDP-LISTENER-CLASS +$cfg->setConfigEntry('client_udp_listener_class', "ClientUdpListenerDecorator"); + // [EOF] ?> diff --git a/application/hub/main/listener/class_BaseListenerDecorator.php b/application/hub/main/listener/class_BaseListenerDecorator.php new file mode 100644 index 000000000..07d4beaf0 --- /dev/null +++ b/application/hub/main/listener/class_BaseListenerDecorator.php @@ -0,0 +1,84 @@ + + * @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 . + */ +class BaseListenerDecorator extends BaseFrameworkSystem { + /** + * Decorated listener instance + */ + private $listenerInstance = null; + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Setter for listener instance + * + * @param $listenerInstance A Listenable instance + * @return void + */ + protected final function setListenerInstance (Listenable $listenerInstance) { + $this->listenerInstance = $listenerInstance; + } + + /** + * Getter for listener instance + * + * @return $listenerInstance A Listenable instance + */ + protected final function getListenerInstance () { + return $this->listenerInstance; + } + + /** + * Getter for listen address + * + * @return $listenAddress The address this listener should listen on + */ + public final function getListenAddress () { + return $this->getListenerInstance()->getListenAddress(); + } + + /** + * Getter for listen port + * + * @return $listenPort The port this listener should listen on + */ + public final function getListenPort () { + return $this->getListenerInstance()->getListenPort(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/tcp/decorators/.htaccess b/application/hub/main/listener/tcp/decorators/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/listener/tcp/decorators/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php b/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php new file mode 100644 index 000000000..a474ccbca --- /dev/null +++ b/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php @@ -0,0 +1,64 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Client 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 . + */ +class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listenable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $listenerInstance A Listener instance + * @return $decoratorInstance An instance a prepared listener decorator class + */ + public final static function createClientTcpListenerDecorator (Listenable $listenerInstance) { + // Get new instance + $decoratorInstance = new ClientTcpListenerDecorator(); + + // Set the application instance + $decoratorInstance->setListenerInstance($listenerInstance); + + // Return the prepared instance + return $decoratorInstance; + } + + /** + * Initializes the listener by setting up the required socket server + * + * @return void + * @todo 0% done + */ + public function initListener() { + $this->partialStub('Need to implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php b/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php new file mode 100644 index 000000000..f621b30ba --- /dev/null +++ b/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php @@ -0,0 +1,64 @@ + + * @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 . + */ +class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $listenerInstance A Listener instance + * @return $decoratorInstance An instance a prepared listener decorator class + */ + public final static function createHubTcpListenerDecorator (Listenable $listenerInstance) { + // Get new instance + $decoratorInstance = new HubTcpListenerDecorator(); + + // Set the application instance + $decoratorInstance->setListenerInstance($listenerInstance); + + // Return the prepared instance + return $decoratorInstance; + } + + /** + * Initializes the listener by setting up the required socket server + * + * @return void + * @todo 0% done + */ + public function initListener() { + $this->partialStub('Need to implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/udp/decorators/.htaccess b/application/hub/main/listener/udp/decorators/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/listener/udp/decorators/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php b/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php new file mode 100644 index 000000000..554fac9d7 --- /dev/null +++ b/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php @@ -0,0 +1,64 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Client 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 . + */ +class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listenable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $listenerInstance A Listener instance + * @return $decoratorInstance An instance a prepared listener decorator class + */ + public final static function createClientUdpListenerDecorator (Listenable $listenerInstance) { + // Get new instance + $decoratorInstance = new ClientUdpListenerDecorator(); + + // Set the application instance + $decoratorInstance->setListenerInstance($listenerInstance); + + // Return the prepared instance + return $decoratorInstance; + } + + /** + * Initializes the listener by setting up the required socket server + * + * @return void + * @todo 0% done + */ + public function initListener() { + $this->partialStub('Need to implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php b/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php new file mode 100644 index 000000000..387eb9c23 --- /dev/null +++ b/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php @@ -0,0 +1,64 @@ + + * @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 . + */ +class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $listenerInstance A Listener instance + * @return $decoratorInstance An instance a prepared listener decorator class + */ + public final static function createHubUdpListenerDecorator (Listenable $listenerInstance) { + // Get new instance + $decoratorInstance = new HubUdpListenerDecorator(); + + // Set the application instance + $decoratorInstance->setListenerInstance($listenerInstance); + + // Return the prepared instance + return $decoratorInstance; + } + + /** + * Initializes the listener by setting up the required socket server + * + * @return void + * @todo 0% done + */ + public function initListener() { + $this->partialStub('Need to implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 1f39c2dec..c76e89776 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -342,21 +342,49 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Get a new pool instance $this->listenerPoolInstance = ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)); - // Initialize both listeners - foreach (array('tcp', 'udp') as $protocol) { - // Get an instance - $listenerInstance = ObjectFactory::createObjectByConfiguredName($protocol . '_listener_class', array($this)); + // Get an instance of the low-level listener + $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this)); - // Setup address and port - $listenerInstance->setListenAddressByConfiguration('node_listen_addr'); - $listenerInstance->setListenPortByConfiguration('node_' . $protocol . '_listen_port'); + // Setup address and port + $listenerInstance->setListenAddressByConfiguration('node_listen_addr'); + $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port'); - // Initialize the listener - $listenerInstance->initListener(); + // Initialize the listener + $listenerInstance->initListener(); - // Add this listener to the pool - $this->listenerPoolInstance->addListener($listenerInstance); - } // END - foreach + // Get a decorator class + $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_tcp_listener_class', array($listenerInstance)); + + // Add this listener to the pool + $this->listenerPoolInstance->addListener($decoratorInstance); + + // Get a decorator class + $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance)); + + // Add this listener to the pool + $this->listenerPoolInstance->addListener($decoratorInstance); + + // Get an instance of the low-level listener + $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this)); + + // Setup address and port + $listenerInstance->setListenAddressByConfiguration('node_listen_addr'); + $listenerInstance->setListenPortByConfiguration('node_udp_listen_port'); + + // Initialize the listener + $listenerInstance->initListener(); + + // Get a decorator class + $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_udp_listener_class', array($listenerInstance)); + + // Add this listener to the pool + $this->listenerPoolInstance->addListener($decoratorInstance); + + // Get a decorator class + $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance)); + + // Add this listener to the pool + $this->listenerPoolInstance->addListener($decoratorInstance); } } -- 2.39.5