* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-abstract class BaseDht extends BaseHubSystem {
+abstract class BaseDht extends BaseHubSystem implements Distributable {
+ /**
+ * "Cached" instance of a publish helper
+ */
+ private $publishHelperInstance = NULL;
+
/**
* Stacker name for "INSERT" node data
*/
// Get result instance
$resultInstance = $this->getWrapperInstance()->getUnpublishedEntriesInstance();
- // Must still be valid
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
assert($resultInstance->valid());
// "Walk" through all entries
assert(is_array($current));
// ... and push it to the next stack
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] Pushing entry with ' . count($current) . ' elements to stack ' . self::STACKER_NAME_PENDING_PUBLISHING . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] Pushing entry with ' . count($current) . ' elements to stack ' . self::STACKER_NAME_PENDING_PUBLISHING . ' ...');
$this->getStackerInstance()->pushNamed(self::STACKER_NAME_PENDING_PUBLISHING, $current);
} // END - while
}
$isPending = ($this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_PENDING_PUBLISHING) === FALSE);
// Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] isPending=' . intval($isPending));
return $isPending;
}
+ /**
+ * Whether this DHT's state is 'booting'
+ *
+ * @return $isBooting Whether this DHT is currently booting
+ */
+ public function ifDhtIsBooting () {
+ // Call state instance
+ $isBooting = $this->getStateInstance()->ifDhtIsBooting();
+
+ // Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] isBooting=' . intval($isBooting));
+ return $isBooting;
+ }
+
/**
* Publishes next entry found in stack. This method shall also update the
* corresponding dabase entry.
*
* @return void
+ * @todo Find out if loadDescriptorXml() can be called only once to avoid a lot methods working.
*/
public function publishEntry () {
- $this->partialStub('Unimplemented method.');
+ // This test must not fail
+ assert($this->hasEntriesPendingPublication());
+
+ // Is there an instance?
+ if (!$this->publishHelperInstance instanceof HelpableDht) {
+ // Get a helper instance
+ $this->publishHelperInstance = ObjectFactory::createObjectByConfiguredName('dht_publish_entry_helper_class');
+ } // END - if
+
+ // Load the announcement descriptor
+ $this->publishHelperInstance->loadDescriptorXml($this);
+
+ // "Pop" next entry
+ $entry = $this->getStackerInstance()->popNamed(self::STACKER_NAME_PENDING_PUBLISHING);
+
+ // Some sanity-checks
+ assert(is_array($entry));
+
+ // Remove any non-public data the database layer desires
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT[' . __METHOD__ . ':' . __LINE__ . ']: Calling this->getWrapperInstance()->removeNonPublicDataFromArray(data) ...');
+ $entry = $this->getWrapperInstance()->removeNonPublicDataFromArray($entry);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT[' . __METHOD__ . ':' . __LINE__ . ']: entry[]=' . gettype($entry));
+
+ // Some sanity-checks again
+ assert(is_array($entry));
+
+ // Inject variables
+ $this->publishHelperInstance->getTemplateInstance()->injectConfigVariables($entry);
+
+ // "Publish" the descriptor by sending it to the bootstrap/list nodes
+ $this->publishHelperInstance->sendPackage($this);
+ }
+
+ /**
+ * Whether the DHT has fully bootstrapped (after state 'booting')
+ *
+ * @return $isFullyBooted Whether the DHT is fully booted
+ * @todo 0% done
+ */
+ public function hasFullyBootstrapped () {
+ // Get state and check it
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Enable DHT bootstrap request acceptance for local node
+ *
+ * @return void
+ * @todo Switch flag 'accept_bootstrap'
+ */
+ public function enableAcceptDhtBootstrap () {
+ // Call method on database wrapper
+ $this->getWrapperInstance()->enableAcceptDhtBootstrap();
}
}