/** * Retrieve remote instance for a given DSN. Invoking this method * twice with the same dsn will result in the same instance. * * @param string dsn * @return remote.Remote * @throws remote.RemoteException in case of setup failure */ public static function forName($dsn) { static $instances = array(); $pool = HandlerInstancePool::getInstance(); $list = explode(',', $dsn); shuffle($list); foreach ($list as $key) { $key = trim($key); if (isset($instances[$key])) { return $instances[$key]; } // No instance yet, so get it $e = $instance = NULL; try { $instance = new self(); $instance->_handler = $pool->acquire($key, TRUE); } catch (RemoteException $e) { continue; // try next } catch (XPException $e) { $e = new RemoteException($e->getMessage(), $e); continue; // try next } // Success, cache instance and return $instances[$key] = $instance; return $instance; } // No more active hosts throw $e; }
/** * Setup method * */ public function setUp() { $pool = HandlerInstancePool::getInstance(); foreach (array(REMOTE_SPEC_ONE => TRUE, REMOTE_SPEC_TWO => FALSE, REMOTE_SPEC_THREE => FALSE, REMOTE_SPEC_OTHER => TRUE) as $spec => $avail) { $this->handler[$spec] = $pool->acquire($spec); $this->handler[$spec]->server['available'] = $avail; } }