]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/nodes/class_BaseHubNode.php
New factory method createPackageInstance introduced to ease creating a singleton...
[hub.git] / application / hub / main / nodes / class_BaseHubNode.php
index f9d1cdf9c6425fe44b6d21b902650faf98457242..5cbe9033932da030ed312af67a24d7526613703f 100644 (file)
@@ -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]