]> git.mxchange.org Git - hub.git/commitdiff
Decorators for hub/client listeners added
authorRoland Häder <roland@mxchange.org>
Tue, 7 Jul 2009 20:50:23 +0000 (20:50 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 7 Jul 2009 20:50:23 +0000 (20:50 +0000)
.gitattributes
application/hub/config.php
application/hub/main/listener/class_BaseListenerDecorator.php [new file with mode: 0644]
application/hub/main/listener/tcp/decorators/.htaccess [new file with mode: 0644]
application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php [new file with mode: 0644]
application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php [new file with mode: 0644]
application/hub/main/listener/udp/decorators/.htaccess [new file with mode: 0644]
application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php [new file with mode: 0644]
application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php [new file with mode: 0644]
application/hub/main/nodes/class_BaseHubNode.php

index f8514f59f62d8e6e66eef754c2bba64b07da88b8..0cff0ffc158bb56f24ebd5c618eeb540c5a2c50c 100644 (file)
@@ -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
index 243bd3ac4e5b851f5b789650c77cbcfa64b8647a..1b1f04a28a2a419383ce1bfca7320f112f70bd3f 100644 (file)
@@ -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 (file)
index 0000000..07d4bea
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/**
+ * A decorator for the TcpListener to communicate to hubs
+ *
+ * @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 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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..a474ccb
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * A decorator for the TcpListener to communicate to clients
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..f621b30
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * A decorator for the TcpListener to communicate to hubs
+ *
+ * @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 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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..554fac9
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * A decorator for the UdpListener to communicate to clients
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..387eb9c
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * A decorator for the UdpListener to communicate to hubs
+ *
+ * @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 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]
+?>
index 1f39c2decb9a0147a07d26283011b1c129b33032..c76e89776964fe7213137609aa79383a7c7d5ae9 100644 (file)
@@ -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);
        }
 }