PHP Class Odesk\Phystrix\AbstractCommand

ファイルを表示 Open project: odesk/phystrix

Protected Properties

Property Type Description
$commandKey string Command Key, used for grouping Circuit Breakers
$config Zend\Config\Config Command configuration
$serviceLocator Zend\Di\LocatorInterface

Public Methods

Method Description
execute ( ) : mixed Executes the command Isolation and fault tolerance logic (Circuit Breaker) is built-in
getCommandKey ( ) : string Determines and returns command key, used for circuit breaker grouping and metrics tracking
getExecutionEvents ( ) : array Returns events collected
getExecutionException ( ) : Exceptio\Exception | null Returns exception thrown while executing the command, if there was any
getExecutionTimeInMilliseconds ( ) : null | integer Returns execution time in milliseconds, null if not executed
initializeConfig ( Zend\Config\Config $phystrixConfig ) Sets base command configuration from the global phystrix configuration
setCircuitBreakerFactory ( Odesk\Phystrix\CircuitBreakerFactory $circuitBreakerFactory ) Sets instance of circuit breaker factory
setCommandMetricsFactory ( Odesk\Phystrix\CommandMetricsFactory $commandMetricsFactory ) Sets instance of command metrics factory
setConfig ( Zend\Config\Config $config, boolean $merge = true ) Sets configuration for the command, allows to override config in runtime
setRequestCache ( RequestCache $requestCache ) Sets shared object for request caching
setRequestLog ( Odesk\Phystrix\RequestLog $requestLog ) Sets shared object for request logging
setServiceLocator ( Zend\Di\LocatorInterface $serviceLocator ) Sets service locator instance, for injecting custom dependencies into the command

Protected Methods

Method Description
getCacheKey ( ) : string | null Key to be used for request caching.
getFallback ( ) Code for when execution fails for whatever reason
prepare ( ) Custom preparation logic, preceding command execution
processExecutionEvent ( string $eventName ) Custom logic proceeding event generation
run ( ) : mixed The code to be executed

Private Methods

Method Description
getCircuitBreaker ( ) : Odesk\Phystrix\CircuitBreaker Circuit breaker for this command key
getFallbackOrThrowException ( Exception $originalException = null ) : mixed Attempts to retrieve fallback by calling getFallback
getMetrics ( ) : Odesk\Phystrix\CommandMetrics Command Metrics for this command key
getTimeInMilliseconds ( ) : float Returns current time on the server in milliseconds
isRequestCacheEnabled ( ) : boolean Determines whether request caching is enabled for this command
recordExecutedCommand ( ) Adds reference to the command to the current request log
recordExecutionEvent ( string $eventName ) Logic to record events and exceptions as they take place
recordExecutionTime ( ) Records command execution time if the command was executed, not short-circuited and not returned from cache

Method Details

execute() public method

Executes the command Isolation and fault tolerance logic (Circuit Breaker) is built-in
public execute ( ) : mixed
return mixed

getCacheKey() protected method

By default this return null, which means "do not cache". To enable caching, override this method and return a string key uniquely representing the state of a command instance. If multiple command instances are executed within current HTTP request, only the first one will be executed and all others returned from cache.
protected getCacheKey ( ) : string | null
return string | null

getCommandKey() public method

Determines and returns command key, used for circuit breaker grouping and metrics tracking
public getCommandKey ( ) : string
return string

getExecutionEvents() public method

Returns events collected
public getExecutionEvents ( ) : array
return array

getExecutionException() public method

Returns exception thrown while executing the command, if there was any
public getExecutionException ( ) : Exceptio\Exception | null
return Exceptio\Exception | null

getExecutionTimeInMilliseconds() public method

Returns execution time in milliseconds, null if not executed

getFallback() protected method

Code for when execution fails for whatever reason
protected getFallback ( )

initializeConfig() public method

Sets base command configuration from the global phystrix configuration
public initializeConfig ( Zend\Config\Config $phystrixConfig )
$phystrixConfig Zend\Config\Config

prepare() protected method

Custom preparation logic, preceding command execution
protected prepare ( )

processExecutionEvent() protected method

Custom logic proceeding event generation
protected processExecutionEvent ( string $eventName )
$eventName string

run() abstract protected method

The code to be executed
abstract protected run ( ) : mixed
return mixed

setCircuitBreakerFactory() public method

Sets instance of circuit breaker factory
public setCircuitBreakerFactory ( Odesk\Phystrix\CircuitBreakerFactory $circuitBreakerFactory )
$circuitBreakerFactory Odesk\Phystrix\CircuitBreakerFactory

setCommandMetricsFactory() public method

Sets instance of command metrics factory
public setCommandMetricsFactory ( Odesk\Phystrix\CommandMetricsFactory $commandMetricsFactory )
$commandMetricsFactory Odesk\Phystrix\CommandMetricsFactory

setConfig() public method

Sets configuration for the command, allows to override config in runtime
public setConfig ( Zend\Config\Config $config, boolean $merge = true )
$config Zend\Config\Config
$merge boolean

setRequestCache() public method

Sets shared object for request caching
public setRequestCache ( RequestCache $requestCache )
$requestCache RequestCache

setRequestLog() public method

Sets shared object for request logging
public setRequestLog ( Odesk\Phystrix\RequestLog $requestLog )
$requestLog Odesk\Phystrix\RequestLog

setServiceLocator() public method

Sets service locator instance, for injecting custom dependencies into the command
public setServiceLocator ( Zend\Di\LocatorInterface $serviceLocator )
$serviceLocator Zend\Di\LocatorInterface

Property Details

$commandKey protected_oe property

Command Key, used for grouping Circuit Breakers
protected string $commandKey
return string

$config protected_oe property

Command configuration
protected Config,Zend\Config $config
return Zend\Config\Config

$serviceLocator protected_oe property

protected LocatorInterface,Zend\Di $serviceLocator
return Zend\Di\LocatorInterface