]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php
State pattern added, hub continued (sorry, I let it lay around uncommitted for long...
[hub.git] / application / hub / main / helper / hub / announcement / class_HubDescriptorHelper.php
index 3ff692aa37379445fef2b7ce6d61af3b2b7bd841..91812d27dc90b10e7bd482ae28a4cc5a21d70c8b 100644 (file)
@@ -69,6 +69,10 @@ class HubDescriptorHelper extends BaseHubHelper {
                // Disable language support
                $templateInstance->enableLanguageSupport(false);
 
+               // Enable compacting/rewriting of the  XML to save bandwidth from XML
+               // comments. This is expensive and should be avoided in general.
+               $templateInstance->enableXmlCompacting();
+
                // Set it for later use
                $this->setTemplateInstance($templateInstance);
 
@@ -78,11 +82,47 @@ class HubDescriptorHelper extends BaseHubHelper {
                // Read the XML descriptor
                $this->getTemplateInstance()->loadAnnouncementTemplate('self_announcement');
 
-               // Get the prepared content
-               $announcementContent = $this->getTemplateInstance()->getRawTemplateData();
+               // Render the XML content
+               $this->getTemplateInstance()->renderXmlContent();
+       }
+
+       /**
+        * Publishes the node's descriptor XML to all found upper nodes when the
+        * node has not yet published it's descriptor to a bootstrap node. This is
+        * done by getting the raw XML content and inserting all variables into
+        * the code. After this wents fine, the rendered content got "packaged"
+        * for network delivery.
+        *
+        * @return      void
+        */
+       public function publishAnnouncementDescriptor () {
+               // Is the node in the approx state? (active)
+               $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive();
+
+               // Compile the template, this inserts the loaded node data into the gaps.
+               $this->getTemplateInstance()->compileTemplate();
+
+               // Prepare the compressor for our package, GZIP should be fine but we
+               // keep it open here so you can experiment with the settings and don't
+               // need to touch any code.
+               $compressorInstance = ObjectFactory::createObjectByConfiguredName('raw_package_compressor_class');
+
+               // Prepare the decorator compressor (for later flawless and easy updates)
+               $compressorInstance = ObjectFactory::createObjectByConfiguredName('deco_package_compressor_class', array($compressorInstance));
+
+               // Now prepare the network package for delivery so only need to do this
+               // once just before the "big announcement loop".
+               $packageInstance = ObjectFactory::createObjectByConfiguredName('network_package_class', array($compressorInstance));
+
+               // Enable re-queue support which re-queues the below feeded content
+               // into the delivery method all over again.
+               $packageInstance->enableDataReQueueing();
+
+               // Next, feed the content in. The network package class is a pipe-through class.
+               $packageInstance->queueRawDataFromTemplate($this->getTemplateInstance());
 
-               // Render it here
-               $this->getTemplateInstance()->renderXmlContent($announcementContent);
+               // Debug only:
+               /* DEBUG: */ die(print_r($this->getTemplateInstance(), true));
        }
 }