public function startRequest($function, array $params = array(), $cache = null)
    {
        if ($cache !== null && !is_string($cache)) {
            throw new \RuntimeException('$cache is an id for the request and should be a string or null.');
        }

        $request = new Request($function, $params);
        $prioritizedManagerList = $this->managerList->toPrioritizedArray();

        foreach ($prioritizedManagerList as $manager) {
            try {
                $response = $this->sendExecuteRequest($manager, $request, $cache);

                $request->setManager($manager);
                $request->setRequestId($response->getRequestId());
                $this->managerList->flag($manager, ManagerList::FLAG_AVAILABLE);

                $this->getLogger()->debug($manager.' accepted request '.$response->getRequestId().' '.$request->getFunction());

                return $request;
            } catch (TimeoutException $ex) {
                $this->managerList->flag($manager, ManagerList::FLAG_UNAVAILABLE);

                $this->getLogger()->notice($manager.': '.$ex->getMessage());
            }
        }

        throw new RuntimeException('AlphaRPC ('.implode(', ', $prioritizedManagerList).') did not respond in time.');
    }
public function startRequest($function, array $params = array(), $cache = null)
    {
        if ($cache !== null && !is_string($cache)) {
            throw new \RuntimeException('$cache is an id for the request and should be a string or null.');
        }

        $request = new Request($function, $params);
        $prioritizedManagerList = $this->managerList->toPrioritizedArray();

        foreach ($prioritizedManagerList as $manager) {
            try {
                $response = $this->sendExecuteRequest($manager, $request, $cache);

                $request->setManager($manager);
                $request->setRequestId($response->getRequestId());
                $this->managerList->flag($manager, ManagerList::FLAG_AVAILABLE);

                $this->getLogger()->debug($manager.' accepted request '.$response->getRequestId().' '.$request->getFunction());

                return $request;
            } catch (TimeoutException $ex) {
                $this->managerList->flag($manager, ManagerList::FLAG_UNAVAILABLE);

                $this->getLogger()->notice($manager.': '.$ex->getMessage());
            }
        }

        throw new RuntimeException('AlphaRPC ('.implode(', ', $prioritizedManagerList).') did not respond in time.');
    }
public function startRequest ( $ function , array $ params = array ( ) , $ cache = null ) { if ( $ cache !== null && ! is_string ( $ cache ) ) { throw new \ RuntimeException ( '$cache is an id for the request and should be a string or null.' ) ; } $ request = new Request ( $ function , $ params ) ; $ prioritizedManagerList = $ this -> managerList -> toPrioritizedArray ( ) ; foreach ( $ prioritizedManagerList as $ manager ) { try { $ response = $ this -> sendExecuteRequest ( $ manager , $ request , $ cache ) ; $ request -> setManager ( $ manager ) ; $ request -> setRequestId ( $ response -> getRequestId ( ) ) ; $ this -> managerList -> flag ( $ manager , ManagerList :: FLAG_AVAILABLE ) ; $ this -> getLogger ( ) -> debug ( $ manager . ' accepted request ' . $ response -> getRequestId ( ) . ' ' . $ request -> getFunction ( ) ) ; return $ request ; } catch ( TimeoutException $ ex ) { $ this -> managerList -> flag ( $ manager , ManagerList :: FLAG_UNAVAILABLE ) ; $ this -> getLogger ( ) -> notice ( $ manager . ': ' . $ ex -> getMessage ( ) ) ; } } throw new RuntimeException ( 'AlphaRPC (' . implode ( ', ' , $ prioritizedManagerList ) . ') did not respond in time.' ) ; }
Starts a request.

@param string $function
@param array  $params
@param string $cache

@return Request
@throws \RuntimeException
Starts a request .