* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core 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 . */ class PackageRecipientDiscovery extends BaseDiscovery implements DiscoverableRecipient, Registerable { /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Create an instance of this class * * @return $discoveryInstance An instance of this discovery class */ public final static function createPackageRecipientDiscovery () { // Get an instance of this class $discoveryInstance = new PackageRecipientDiscovery(); // Output debug message $discoveryInstance->debugOutput('RECIPIENT-DISCOVERY: Initialized.'); // Return the prepared instance return $discoveryInstance; } /** * Tries to discover all recipients for given package data * * @param $packageData Raw package data array * @return void */ public function discoverRecipients (array $packageData) { // Get recipients list instance $listInstance = RecipientListFactory::createRecipientListInstance(); // We do some rudimentary checks but this might be a bit ugly switch ($packageData['recipient']) { // All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes case NetworkPackage::NETWORK_TARGET_UPPER_HUBS: // Get all bootstrap nodes foreach (explode(';', $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $node) { // Add the entry $listInstance->addEntry('ip_port', $node); } // END - foreach break; // This may be a direct recipient (hub's session id) default: $this->partialStub('Please add code handling direct recipients.'); break; } // END - switch } /** * "Getter" for recipient iterator * * @return $iteratorInstance An instance of a Iterateable object */ public function getIterator () { // Get list instance $listInstance = RecipientListFactory::createRecipientListInstance(); // Get iterator from it $iteratorInstance = $listInstance->getIterator(); // Return it return $iteratorInstance; } } // [EOF] ?>