熔断器调用

@param mixed $callback 回调函数
@param array $params 参数
@param mixed $fallback 失败回调

@return mixed 返回结果
336772
public function doCall($callback, $params = [], $fallback = null)
    {
        $data = $this->circuitBreaker->fallback();

        App::trace($this->getServiceName() . "服务，当前[开启状态]，执行服务fallback服务降级容错处理");
        // 开启定时器
        $nowTime = time();

        if ($this->circuitBreaker->isOpen()
            && $nowTime > $this->circuitBreaker->getSwitchOpenToHalfOpenTime()
        ) {
            $delayTime = $this->circuitBreaker->getDelaySwitchTimer();

            // 定时器不是严格的，新增3s,容错时间
            $switchToHalfStateTime = $nowTime + ($delayTime / 1000) + 3;
            App::getTimer()->addAfterTimer('openState', $delayTime, [$this, 'delayCallback']);
            $this->circuitBreaker->setSwitchOpenToHalfOpenTime($switchToHalfStateTime);

            App::trace($this->getServiceName() . "服务，当前[开启状态]，创建延迟触发器，一段时间后状态切换为半开状态");
        }

        return $data;
    }
229490
public function call($callback, array $parameters = [])
    {
        $this->_events[] = $event = new CallbackEvent($callback, $parameters);

        return $event;
    }
670627
private static function execCallback(array $callback)
    {
        if (count($callback) >= 2 && count($callback) <= 3) {
            try {
                if (count($callback) == 2) {
                    return call_user_func_array(array($callback[0], $callback[1]));
                }
                if (count($callback) == 3) {
                    return call_user_func_array(array($callback[0], $callback[1]), (array) $callback[2]);
                }
            } catch (\Exception $e) {
                unset($e);
            }
        }
    }
552722
public function doCall($callback, $params = [], $fallback = null)
    {
        // 加锁
        $lock = $this->circuitBreaker->getHalfOpenLock();
        $lock->lock();
        list($class, $method) = $callback;

        try {
            if ($class === null) {
                throw new \Exception($this->getServiceName() . '服务, 建立连接失败(null)');
            }

            if (
                ($class instanceof Client && $class->isConnected() == false) ||
                ($class instanceof ConnectionInterface && $class->check() == false)
            ) {
                throw new \Exception($this->circuitBreaker->serviceName . '服务,当前连接已断开');
            }

            $data = $class->$method(...$params);
            $this->circuitBreaker->incSuccessCount();
            App::trace($this->getServiceName() . '服务，当前[半开状态]，尝试执行成');
        } catch (\Exception $e) {
            $this->circuitBreaker->incFailCount();
            $data = $this->circuitBreaker->fallback($fallback);
            App::error($this->getServiceName() . '服务，当前[半开状态]，尝试执行失败, error=' . $e->getMessage());
        }

        $failCount = $this->circuitBreaker->getFailCounter();
        $successCount = $this->circuitBreaker->getSuccessCounter();
        $switchToFailCount = $this->circuitBreaker->getSwitchToFailCount();
        $switchToSuccessCount = $this->circuitBreaker->getSwitchToSuccessCount();

        if ($failCount >= $switchToFailCount && $this->circuitBreaker->isHalfOpen()) {
            $this->circuitBreaker->switchToOpenState();
            App::trace($this->getServiceName() . '服务，当前[半开状态]，失败次数达到上限，开始切换到开启状态');
        }

        if ($successCount >= $switchToSuccessCount) {
            $this->circuitBreaker->switchToCloseState();
            App::trace($this->getServiceName() . '服务，当前[半开状态]，成功次数达到上限，服务以及恢复，开始切换到关闭状态');
        }

        // 释放锁
        $lock->unlock();

        App::trace($this->getServiceName() . '服务，当前[半开状态], failCount=' . $failCount . ' successCount=' . $successCount);

        return $data;
    }
540496
public function getValue( $key, $fallback = null ) {
		return array_key_exists( $key, $this->state )
			? $this->state[ $key ]
			: $fallback;
	}
596315
protected function executeCallback($callback, $args)
    {
        if (is_string($callback)) {
            return $this->callStringCallback($callback, $args);
        } elseif ($callback instanceof Closure) {
            return call_user_func_array($callback, $args);
        }

        return '';
    }
691540
public function first($callback = null, $default = null)
        {
            if (is_null($callback)) {
                return count($this->_items) > 0 ? Arrays::first($this->_items) : $default;
            } else {
                foreach ($this->_items as $key => $value) {
                    if (call_user_func($callback, $key, $value)) {
                        return $value;
                    }
                }

                return value($default);
            }
        }
1144027
public function filter($callback = null)
    {
        if (is_null($callback)) {
            return new static(array_filter($this->array)); 
        }
        return new static(array_filter($this->array, $callback));
    }
335339
protected static function call( $callbacks, $params, $pass = false ) {
		
		$response = array();
		
		if ( $pass ) {
			$response = $params;
		}
		
		foreach ( $callbacks as $callback ) {
			if ( $pass ) {
				$response = call_user_func_array( $callback, array( $response ) );
			}
			else {
				$response[] = call_user_func_array( $callback, $params );
			}
		}
		
		return $response;
	}
141471
public function findCallback(Closure $callback, $columns = ['*'])
    {
        return $this->postProcess( parent::findCallback($callback, $columns) );
    }
53276
public function get($identifier = null, $fallback = null) {
		return $this->arrayGet($this->_data, $identifier, $fallback);
	}
996219
public function callback($function, $params = null)
    {
        $callback = new Callback($function, $params);
        $this->register($callback);

        return $callback;
    }
763287
public function post($key = null, $fallback = null)
    {
        return $key
            ? $this->request->request->get($key, $fallback)
            : $this->request->request;
    }
1107908
public static function capture( $callback, $params = array() )
	{
		if ( is_string( $callback ) )
		{
			return $callback;
		}

		if ( !is_closure( $callback ) )
		{
			return "";
		}

		if ( !is_array( $params ) ) 
		{
			$params = array( $params );
		}

		ob_start();
		$return = call_user_func_array( $callback,  $params );
		$buffer = ob_get_clean();

		if ( !is_null( $return ) )
		{
			return $return;
		}

		return $buffer;
	}
1248746
public function open($callback = null)
    {
        $result = $this->redis->connect($this->config['host'] ?? '127.0.0.1', $this->config['port'] ?? 6379, $this->config['serialize'] ?? true);
        if(isset($this->config['password']))
        {
            $result = $result && $this->redis->auth($this->config['password']);
        }
        if(isset($this->config['db']))
        {
            $r = $this->redis->select($this->config['db']);
            $result = $result && $r;
        }
        return $result;
    }
1238081
public function filter($callback = null)
    {
        $test = array_filter($this->data, $callback);
        $clone = clone $this;
        return $clone->reset($test);
    }
1347878
public function filter($callback = null)
    {
        $callback = $callback ?: [$this, 'valueIsEmpty'];
        $output = clone $this;
        $output->exchangeArray([]);

        foreach ($this as $key => $value) {
            if ($callback($value, $key)) {
                $output[$key] = $value;
            }
        }

        return $output;
    }