'hub' continued:
authorRoland Häder <roland@mxchange.org>
Sun, 12 Feb 2012 22:40:48 +0000 (22:40 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 12 Feb 2012 22:40:48 +0000 (22:40 +0000)
- New chunk handler class + factory added (no interface yet)
- FinalChunkVerificationException simplified (to make usage of it in chunk
  handler)
- TODOs.txt updated

.gitattributes
application/hub/config.php
application/hub/exceptions/package/class_FinalChunkVerificationException.php
application/hub/main/factories/chunks/.htaccess [new file with mode: 0644]
application/hub/main/factories/chunks/class_ChunkHandlerFactory.php [new file with mode: 0644]
application/hub/main/handler/chunks/.htaccess [new file with mode: 0644]
application/hub/main/handler/chunks/class_ChunkHandler.php [new file with mode: 0644]
application/hub/main/package/assembler/class_PackageAssembler.php
docs/TODOs.txt

index b6aa3f2cc8da06db4bf30e166049f44b4e6fce72..aba2aab5730f378ddc8532b40ef4340d72efb3dd 100644 (file)
@@ -193,6 +193,8 @@ application/hub/main/discovery/package/class_PackageRecipientDiscovery.php svneo
 application/hub/main/discovery/socket/.htaccess -text svneol=unset#text/plain
 application/hub/main/discovery/socket/class_PackageSocketDiscovery.php svneol=native#text/plain
 application/hub/main/factories/.htaccess -text svneol=unset#text/plain
+application/hub/main/factories/chunks/.htaccess -text svneol=unset#text/plain
+application/hub/main/factories/chunks/class_ChunkHandlerFactory.php svneol=native#text/plain
 application/hub/main/factories/discovery/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/discovery/class_PackageDiscoveryFactory.php svneol=native#text/plain
 application/hub/main/factories/discovery/class_SocketDiscoveryFactory.php svneol=native#text/plain
@@ -292,6 +294,8 @@ application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFi
 application/hub/main/filter/task/node/.htaccess svneol=native#text/plain
 application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php svneol=native#text/plain
 application/hub/main/handler/.htaccess -text svneol=unset#text/plain
+application/hub/main/handler/chunks/.htaccess -text svneol=unset#text/plain
+application/hub/main/handler/chunks/class_ChunkHandler.php svneol=native#text/plain
 application/hub/main/handler/class_ svneol=native#text/plain
 application/hub/main/handler/class_BaseHandler.php svneol=native#text/plain
 application/hub/main/handler/network/.htaccess -text svneol=unset#text/plain
index 7a0d2f0404a9cddc20fe19a6b409688fe50c1acd..09d31a7936f2776a51fa15f1c0e2beb1f4bffb52 100644 (file)
@@ -531,6 +531,9 @@ $cfg->setConfigEntry('socket_timeout_seconds', 3);
 // CFG: SOCKET-TIMEOUT-MICROSECONDS
 $cfg->setConfigEntry('socket_timeout_microseconds', 0);
 
+// CFG: CHUNK-HANDLER-CLASS
+$cfg->setConfigEntry('chunk_handler_class', 'ChunkHandler');
+
 ///////////////////////////////////////////////////////////////////////////////
 //                              Peer states
 ///////////////////////////////////////////////////////////////////////////////
index e08647d999aae528d3bc46338342d82c372daa71..51beaf6b324b365d0deb51128e15fec29c3500f2 100644 (file)
@@ -32,13 +32,12 @@ class FinalChunkVerificationException extends FrameworkException {
         */
        public function __construct (array $messageArray, $code) {
                // Construct the message
-               $message = sprintf("[%s:%d] The final chunk %s is not a valid EOP (%s) chunk. Raw content: %s, total chunks: %s",
+               $message = sprintf("[%s:%d] The final chunk %s is not a valid EOP (%s) chunk. Total chunks: %s",
                        $messageArray[0]->__toString(),
                        $this->getLine(),
-                       $messageArray[2][count($messageArray[2]) - 1],
+                       $messageArray[1][count($messageArray[2]) - 1],
                        PackageFragmenter::END_OF_PACKAGE_IDENTIFIER,
-                       $messageArray[1][BaseRawDataHandler::PACKAGE_DECODED_DATA]
-                       count($messageArray[2])
+                       count($messageArray[1])
                );
 
                // Call parent exception constructor
diff --git a/application/hub/main/factories/chunks/.htaccess b/application/hub/main/factories/chunks/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/factories/chunks/class_ChunkHandlerFactory.php b/application/hub/main/factories/chunks/class_ChunkHandlerFactory.php
new file mode 100644 (file)
index 0000000..621b024
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * A factory class for chunk handler
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 ChunkHandlerFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Returns a singleton (registry-based) chunk handler instance
+        *
+        * @return      $handlerInstance        An instance of a chunk handler class
+        */
+       public static final function createChunkHandlerInstance () {
+               // If there is no handler?
+               if (Registry::getRegistry()->instanceExists('chunk_handler')) {
+                       // Get handler from registry
+                       $handlerInstance = Registry::getRegistry()->getInstance('chunk_handler');
+               } else {
+                       // Get the handler instance
+                       $handlerInstance = self::createObjectByConfiguredName('chunk_handler_class');
+
+                       // Add it to the registry
+                       Registry::getRegistry()->addInstance('chunk_handler', $handlerInstance);
+               }
+
+               // Return the instance
+               return $handlerInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/handler/chunks/.htaccess b/application/hub/main/handler/chunks/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/handler/chunks/class_ChunkHandler.php b/application/hub/main/handler/chunks/class_ChunkHandler.php
new file mode 100644 (file)
index 0000000..1c753a3
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/**
+ * A Chunk handler
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 ChunkHandler extends BaseHandler implements Registerable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set handler name
+               $this->setHandlerName('chunk');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $handlerInstance        An instance of a chunk Handler class
+        */
+       public final static function createChunkHandler () {
+               // Get new instance
+               $handlerInstance = new ChunkHandler();
+
+               // Return the prepared instance
+               return $handlerInstance;
+       }
+
+       /**
+        * Adds all chunks if the last one verifies as a 'final chunk'.
+        *
+        * @param       $chunks         An array with chunks, the last one should be a 'final'
+        * @return      void
+        * @throws      FinalChunkVerificationException         If the final chunk does not start with 'EOP:'
+        */
+       public function addAllChunksWithFinal (array $chunks) {
+               // Validate final chunk
+               if (substr($chunks[count($chunks) - 1], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) {
+                       // Last chunk is not valid
+                       throw new FinalChunkVerificationException(array($this, $chunks), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION);
+               } // END - if
+
+               // Not yet finished
+               $this->partialStub('Not yet implemented.');
+       }
+}
+
+// [EOF]
+?>
index 04195d0c56c6ec2142efd76020e0fff63bb8b917..430ed71090ac35b22d74b6b03f05eaa2970faadc 100644 (file)
@@ -101,10 +101,14 @@ class PackageAssembler extends BaseFrameworkSystem implements Assembler, Registe
                // Validate final chunk
                if (substr($chunks[count($chunks) - 1], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) {
                        // Last chunk is not valid
-                       throw new FinalChunkVerificationException(array($this, $packageContent, $chunks), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION);
+                       throw new FinalChunkVerificationException(array($this, $chunks), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION);
                } // END - if
 
-               die('chunks='.print_r($chunks,true));
+               // Now get a chunk handler instance
+               $handlerInstance = ChunkHandlerFactory::createChunkHandlerInstance();
+
+               // Add all chunks because the last final chunk is found
+               $handlerInstance->addAllChunksWithFinal($chunks);
        }
 }
 
index 7e88dab528fe030b7baf42959037bf07371cfdbb..ae4c6baead1387bd65b97e05a2362cf2b504a82f 100644 (file)
 ./application/hub/main/package/class_NetworkPackage.php:222:           // @TODO crc32() is very weak, but it needs to be fast
 ./application/hub/main/package/class_NetworkPackage.php:23: * @todo            Needs to add functionality for handling the object's type
 ./application/hub/main/package/class_NetworkPackage.php:386:                   // @TODO We may want to do somthing more here?
-./application/hub/main/package/class_NetworkPackage.php:486:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:512:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:616:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:695:           // @TODO Add some content here
-./application/hub/main/package/class_NetworkPackage.php:745:    * @todo        This may be enchanced for outgoing packages?
+./application/hub/main/package/class_NetworkPackage.php:492:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:518:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:622:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:716:           // @TODO Add some content here
+./application/hub/main/package/class_NetworkPackage.php:766:    * @todo        This may be enchanced for outgoing packages?
 ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:427:      * @todo        $helperInstance is unused
 ./application/hub/main/pools/peer/class_DefaultPeerPool.php:160:                       // @TODO Check for IP
 ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106:                       // @TODO Do something with it
 ./application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php:2:// @DEPRECATED
 ./application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php:2:// @DEPRECATED
 ./application/hub/main/database/wrapper/states/class_NodeStateLookupDatabaseWrapper.php:2:// @DEPRECATED
+./application/hub/main/factories/fragmenter/class_FragmenterFactory.php:2:// @DEPRECATED
 ./application/hub/main/factories/states/class_StateFactory.php:2:// @DEPRECATED
 ./application/hub/main/filter/activation/class_HubActivationSelfAnnouncementFilter.php:2:// @DEPRECATED
 ./application/hub/main/filter/bootstrap/class_HubBootstrapAquireHubIdFilter.php:2:// @DEPRECATED
 ./inc/classes/exceptions/language/class_MissingLanguageHandlerException.php:2:// @DEPRECATED
 ./inc/classes/exceptions/main/class_ClassNotFoundException.php:2:// @DEPRECATED
 ./inc/classes/exceptions/main/class_ConfigEntryNotFoundException.php:2:// @DEPRECATED
+./inc/classes/exceptions/main/class_MissingDecimalsThousandsSeperatorException.php:2:// @DEPRECATED
 ./inc/classes/exceptions/main/class_MissingMethodException.php:14: * @deprecated       Please do no longer use this exception
 ./inc/classes/exceptions/state/class_InvalidStateException.php:2:// @DEPRECATED
 ./inc/classes/interfaces/helper/class_HelpableLogin.php:2:// @DEPRECATED