From 3b6424d165b0ce01a11121d7a1f97757ba9549ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 27 Mar 2010 03:23:56 +0000 Subject: [PATCH] New factory method createPackageInstance introduced to ease creating a singleton netowork package instance --- .../class_HubDescriptorHelper.php | 24 ++----------- .../hub/main/nodes/class_BaseHubNode.php | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php index ea2253336..83b13ad6c 100644 --- a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php @@ -96,35 +96,17 @@ class HubDescriptorHelper extends BaseHubHelper { * @return void */ public function publishAnnouncementDescriptor () { - // Is the node in the approx state? (active) + // Sanity check: 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)); - - // Do we have an instance in the registry? - if (Registry::getRegistry()->instanceExists('network_package')) { - // Then use this instance - $packageInstance = Registry::getRegistry()->getInstance('network_package'); - } else { - // 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)); - } + // Get a package instance + $packageInstance = $this->getNodeInstance()->createPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. $packageInstance->enqueueRawDataFromTemplate($this); - - // Set the instance in registry for further use - Registry::getRegistry()->addInstance('network_package', $packageInstance); } } diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index f9d1cdf9c..5cbe90339 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -614,6 +614,42 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Return value return $isActive; } + + /** + * Returns a singleton network package instance. If an instance is found in + * the registry it will be returned, else a new instance is created and + * stored in the same registry entry. + * + * @param $compressorInstance A Compressor instance + * @return $packageInstance A network package instance + */ + public function createPackageInstance (Compressor $compressorInstance) { + // Do we have an instance in the registry? + if (Registry::getRegistry()->instanceExists('network_package')) { + // Then use this instance + $packageInstance = Registry::getRegistry()->getInstance('network_package'); + } else { + /** + * 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)); + + // Set the instance in registry for further use + Registry::getRegistry()->addInstance('network_package', $packageInstance); + } + + // Return the instance + return $packageInstance; + } } // [EOF] -- 2.39.5