T
- The return type of the function represented by this command.public abstract class CachingCommand<T> extends Command<T>
The implementing class needs to implement the runCacheable()
and the getCache()
methods. The key of
the cache is, by default in getCommandCacheKey()
, based on the current tenant and user, as well as the class
name of the executed command.
Modifier and Type | Class and Description |
---|---|
protected static class |
com.netflix.hystrix.AbstractCommand.CommandState |
protected static class |
com.netflix.hystrix.AbstractCommand.ThreadState |
protected static class |
com.netflix.hystrix.AbstractCommand.TimedOutStatus |
Modifier and Type | Field and Description |
---|---|
protected com.netflix.hystrix.HystrixCircuitBreaker |
circuitBreaker |
protected static ConcurrentHashMap<com.netflix.hystrix.HystrixCommandKey,Boolean> |
commandContainsFallback |
protected com.netflix.hystrix.HystrixCommandGroupKey |
commandGroup |
protected com.netflix.hystrix.HystrixCommandKey |
commandKey |
protected long |
commandStartTimestamp |
protected AtomicReference<com.netflix.hystrix.AbstractCommand.CommandState> |
commandState |
protected com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy |
concurrencyStrategy |
protected com.netflix.hystrix.HystrixRequestLog |
currentRequestLog |
protected rx.functions.Action0 |
endCurrentThreadExecutingCommand |
protected com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier |
eventNotifier |
protected com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook |
executionHook |
protected com.netflix.hystrix.ExecutionResult |
executionResult |
protected com.netflix.hystrix.ExecutionResult |
executionResultAtTimeOfCancellation |
protected com.netflix.hystrix.AbstractCommand.TryableSemaphore |
executionSemaphoreOverride |
protected static ConcurrentHashMap<String,com.netflix.hystrix.AbstractCommand.TryableSemaphore> |
executionSemaphorePerCircuit |
protected com.netflix.hystrix.AbstractCommand.TryableSemaphore |
fallbackSemaphoreOverride |
protected static ConcurrentHashMap<String,com.netflix.hystrix.AbstractCommand.TryableSemaphore> |
fallbackSemaphorePerCircuit |
protected AtomicReference<com.netflix.hystrix.AbstractCommand.TimedOutStatus> |
isCommandTimedOut |
protected boolean |
isResponseFromCache |
protected com.netflix.hystrix.HystrixCommandMetrics |
metrics |
protected com.netflix.hystrix.HystrixCommandProperties |
properties |
protected com.netflix.hystrix.HystrixRequestCache |
requestCache |
protected com.netflix.hystrix.HystrixThreadPool |
threadPool |
protected com.netflix.hystrix.HystrixThreadPoolKey |
threadPoolKey |
protected AtomicReference<com.netflix.hystrix.AbstractCommand.ThreadState> |
threadState |
protected AtomicReference<Reference<com.netflix.hystrix.util.HystrixTimer.TimerListener>> |
timeoutTimer |
Modifier | Constructor and Description |
---|---|
protected |
CachingCommand(com.netflix.hystrix.HystrixCommand.Setter setter) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommand.Setter setter,
boolean isCacheEnabled) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommandGroupKey group) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommandGroupKey group,
boolean isCacheEnabled) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommandGroupKey group,
com.netflix.hystrix.HystrixThreadPoolKey threadPool) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommandGroupKey group,
com.netflix.hystrix.HystrixThreadPoolKey threadPool,
boolean isCacheEnabled) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommandGroupKey group,
com.netflix.hystrix.HystrixThreadPoolKey threadPool,
int executionIsolationThreadTimeoutInMilliseconds) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommandGroupKey group,
com.netflix.hystrix.HystrixThreadPoolKey threadPool,
int executionIsolationThreadTimeoutInMilliseconds,
boolean isCacheEnabled) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommandGroupKey group,
int executionIsolationThreadTimeoutInMilliseconds) |
protected |
CachingCommand(com.netflix.hystrix.HystrixCommandGroupKey group,
int executionIsolationThreadTimeoutInMilliseconds,
boolean isCacheEnabled) |
Modifier and Type | Method and Description |
---|---|
protected Throwable |
decomposeException(Exception arg0) |
protected abstract com.google.common.cache.Cache<CacheKey,T> |
getCache()
Returns the instance of the command-specific cache.
|
protected String |
getCacheKey()
Deprecated.
Use
getCommandCacheKey() instead. |
protected CacheKey |
getCommandCacheKey()
Returns the
CacheKey that is used by this command. |
protected Exception |
getExceptionFromThrowable(Throwable arg0) |
protected com.netflix.hystrix.AbstractCommand.TryableSemaphore |
getExecutionSemaphore() |
protected com.netflix.hystrix.AbstractCommand.TryableSemaphore |
getFallbackSemaphore() |
protected String |
getLogMessagePrefix() |
protected void |
handleThreadEnd(com.netflix.hystrix.AbstractCommand<R> arg0) |
protected boolean |
isRequestCachingEnabled() |
protected T |
run() |
protected abstract T |
runCacheable()
Implements the logic to be executed within the command.
|
protected boolean |
shouldNotBeWrapped(Throwable arg0) |
protected boolean |
shouldOutputOnNextEvents() |
protected boolean |
useCache() |
protected final com.netflix.hystrix.HystrixCircuitBreaker circuitBreaker
protected final com.netflix.hystrix.HystrixThreadPool threadPool
protected final com.netflix.hystrix.HystrixThreadPoolKey threadPoolKey
protected final com.netflix.hystrix.HystrixCommandProperties properties
protected final com.netflix.hystrix.HystrixCommandMetrics metrics
protected final com.netflix.hystrix.HystrixCommandKey commandKey
protected final com.netflix.hystrix.HystrixCommandGroupKey commandGroup
protected final com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier eventNotifier
protected final com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy concurrencyStrategy
protected final com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook executionHook
protected final com.netflix.hystrix.AbstractCommand.TryableSemaphore fallbackSemaphoreOverride
protected static final ConcurrentHashMap<String,com.netflix.hystrix.AbstractCommand.TryableSemaphore> fallbackSemaphorePerCircuit
protected final com.netflix.hystrix.AbstractCommand.TryableSemaphore executionSemaphoreOverride
protected static final ConcurrentHashMap<String,com.netflix.hystrix.AbstractCommand.TryableSemaphore> executionSemaphorePerCircuit
protected final AtomicReference<Reference<com.netflix.hystrix.util.HystrixTimer.TimerListener>> timeoutTimer
protected AtomicReference<com.netflix.hystrix.AbstractCommand.CommandState> commandState
protected AtomicReference<com.netflix.hystrix.AbstractCommand.ThreadState> threadState
protected volatile com.netflix.hystrix.ExecutionResult executionResult
protected volatile boolean isResponseFromCache
protected volatile com.netflix.hystrix.ExecutionResult executionResultAtTimeOfCancellation
protected volatile long commandStartTimestamp
protected final AtomicReference<com.netflix.hystrix.AbstractCommand.TimedOutStatus> isCommandTimedOut
protected volatile rx.functions.Action0 endCurrentThreadExecutingCommand
protected final com.netflix.hystrix.HystrixRequestCache requestCache
protected final com.netflix.hystrix.HystrixRequestLog currentRequestLog
protected static ConcurrentHashMap<com.netflix.hystrix.HystrixCommandKey,Boolean> commandContainsFallback
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommandGroupKey group)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommandGroupKey group, boolean isCacheEnabled)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommandGroupKey group, @Nonnull com.netflix.hystrix.HystrixThreadPoolKey threadPool)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommandGroupKey group, @Nonnull com.netflix.hystrix.HystrixThreadPoolKey threadPool, boolean isCacheEnabled)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommandGroupKey group, int executionIsolationThreadTimeoutInMilliseconds)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommandGroupKey group, int executionIsolationThreadTimeoutInMilliseconds, boolean isCacheEnabled)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommandGroupKey group, @Nonnull com.netflix.hystrix.HystrixThreadPoolKey threadPool, int executionIsolationThreadTimeoutInMilliseconds)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommandGroupKey group, @Nonnull com.netflix.hystrix.HystrixThreadPoolKey threadPool, int executionIsolationThreadTimeoutInMilliseconds, boolean isCacheEnabled)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommand.Setter setter)
protected CachingCommand(@Nonnull com.netflix.hystrix.HystrixCommand.Setter setter, boolean isCacheEnabled)
protected boolean useCache()
true
if the cache is actually used, false
otherwise.@Nonnull protected abstract com.google.common.cache.Cache<CacheKey,T> getCache()
Example usage:
private static final Cache<CacheKey, T> cache = CacheManager.register(CacheBuilder.build(MyClass.class)); @Override protected final Cache<CacheKey, T> getCache() { return cache; }
@Deprecated @Nullable protected final String getCacheKey()
getCommandCacheKey()
instead.null
since the internal Hystrix caching mechanism is obsolete when using a CachingCommand
which introduces a cache across requests.@Nullable protected CacheKey getCommandCacheKey() throws TenantAccessException, UserAccessException
CacheKey
that is used by this command. By default, this is a
CacheKey.ofTenantAndUserIsolation()
appended with the full class name of this command.CacheKey
for this command. If null
is returned, the cache is not used.TenantAccessException
- If there is an issue while accessing the tenant.UserAccessException
- If there is an issue while accessing the user.@Nonnull protected abstract T runCacheable() throws Exception
Exception
protected boolean shouldNotBeWrapped(Throwable arg0)
protected void handleThreadEnd(com.netflix.hystrix.AbstractCommand<R> arg0)
protected boolean shouldOutputOnNextEvents()
protected com.netflix.hystrix.AbstractCommand.TryableSemaphore getFallbackSemaphore()
protected com.netflix.hystrix.AbstractCommand.TryableSemaphore getExecutionSemaphore()
protected boolean isRequestCachingEnabled()
protected String getLogMessagePrefix()
Copyright © 2019 SAP SE. All rights reserved.