Example #1
0
        if (is_null($maxAttempt)) {
            $maxAttempt = self::$_DEFAULT_MAX_ATTEMPT;
        }
        if (is_null($delayAttempt)) {
            $delayAttempt = self::$_DEFAULT_DELAY_ATTEMPT;
        }
        return $this->action('delete', NULL, $maxAttempt, $delayAttempt);
    }
    public function action($action, $parameter, $maxAttempt, $delayAttempt)
    {
        $ma = $maxAttempt;
        do {
            /**
             * @var ResponseWrapperImpl
             */
            $responseWrapper = is_null($parameter) ? parent::$action() : parent::$action($parameter);
            if ($responseWrapper->getResponseCode() != ResponseWrapperImpl::SUCCESS_RESPONSE_CODE) {
                self::$_LOG->info(sprintf("can not <%s>' the resource\n" . "response code    : %s\n" . "response message : %s", strtoupper($action), $responseWrapper->getResponseCode(), $responseWrapper->getErrorMessage()));
                usleep($delayAttempt);
            } else {
                self::$_LOG->info(sprintf("<%s> the resource in attempt n°: %d/%d, total time spent: %d µs", strtoupper($action), $maxAttempt - $ma, $maxAttempt, ($maxAttempt - $ma) * $delayAttempt));
                return $responseWrapper;
            }
        } while (--$ma >= 0);
        $errorMsg = sprintf("all attempts are used without releasing the resource (total = %s)", $maxAttempt);
        self::$_LOG->error($errorMsg);
        throw new Exception($errorMsg);
    }
}
AnyemClientImpl::init();