Package com.alibaba.ttl
Class TtlCallable<V>
- java.lang.Object
-
- com.alibaba.ttl.TtlCallable<V>
-
- All Implemented Interfaces:
TtlAttachments,TtlEnhanced,TtlWrapper<Callable<V>>,Callable<V>
public final class TtlCallable<V> extends Object implements Callable<V>, TtlWrapper<Callable<V>>, TtlEnhanced, TtlAttachments
TtlCallabledecorateCallable, so as to getTransmittableThreadLocaland transmit it to the time ofCallableexecution, needed when useCallableto thread pool.Use factory method
get(Callable)to get decorated instance.Other TTL Wrapper for common
Functional InterfaceseeTtlWrappers.- Since:
- 0.9.0
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
TtlExecutors,TtlWrappers,Executor,ExecutorService,ThreadPoolExecutor,ScheduledThreadPoolExecutor,Executors,CompletionService,ExecutorCompletionService
-
-
Field Summary
-
Fields inherited from interface com.alibaba.ttl.spi.TtlAttachments
KEY_IS_AUTO_WRAPPER
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vcall()wrap methodCallable.call().booleanequals(Object o)static <T> TtlCallable<T>get(Callable<T> callable)Factory method, wrap inputCallabletoTtlCallable.static <T> TtlCallable<T>get(Callable<T> callable, boolean releaseTtlValueReferenceAfterCall)Factory method, wrap inputCallabletoTtlCallable.static <T> TtlCallable<T>get(Callable<T> callable, boolean releaseTtlValueReferenceAfterCall, boolean idempotent)Factory method, wrap inputCallabletoTtlCallable.Callable<V>getCallable()return the original/underneathCallable.static <T> List<TtlCallable<T>>gets(Collection<? extends Callable<T>> tasks)wrap inputCallableCollection toTtlCallableCollection.static <T> List<TtlCallable<T>>gets(Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall)wrap inputCallableCollection toTtlCallableCollection.static <T> List<TtlCallable<T>>gets(Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall, boolean idempotent)wrap inputCallableCollection toTtlCallableCollection.<T> TgetTtlAttachment(String key)inthashCode()voidsetTtlAttachment(String key, Object value)StringtoString()Callable<V>unwrap()unwrap to the original/underneathCallable.static <T> Callable<T>unwrap(Callable<T> callable)UnwrapTtlCallableto the original/underneath one.static <T> List<Callable<T>>unwraps(Collection<? extends Callable<T>> tasks)UnwrapTtlCallableto the original/underneath one.
-
-
-
Method Detail
-
call
public V call() throws Exception
wrap methodCallable.call().
-
unwrap
@NonNull public Callable<V> unwrap()
unwrap to the original/underneathCallable.- Specified by:
unwrapin interfaceTtlWrapper<V>- Since:
- 2.11.4
- See Also:
TtlUnwrap.unwrap(Object)
-
get
@Nullable public static <T> TtlCallable<T> get(@Nullable Callable<T> callable)
-
get
@Nullable public static <T> TtlCallable<T> get(@Nullable Callable<T> callable, boolean releaseTtlValueReferenceAfterCall)
- Parameters:
callable- inputCallablereleaseTtlValueReferenceAfterCall- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.- Returns:
- Wrapped
Callable
-
get
@Nullable public static <T> TtlCallable<T> get(@Nullable Callable<T> callable, boolean releaseTtlValueReferenceAfterCall, boolean idempotent)
- Parameters:
callable- inputCallablereleaseTtlValueReferenceAfterCall- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.idempotent- is idempotent or not.truewill cover up bugs! DO NOT set, only when you know why.- Returns:
- Wrapped
Callable
-
gets
@NonNull public static <T> List<TtlCallable<T>> gets(@Nullable Collection<? extends Callable<T>> tasks)
wrap inputCallableCollection toTtlCallableCollection.- Parameters:
tasks- task to be wrapped- Returns:
- Wrapped
Callable
-
gets
@NonNull public static <T> List<TtlCallable<T>> gets(@Nullable Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall)
wrap inputCallableCollection toTtlCallableCollection.- Parameters:
tasks- task to be wrappedreleaseTtlValueReferenceAfterCall- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.- Returns:
- Wrapped
Callable
-
gets
@NonNull public static <T> List<TtlCallable<T>> gets(@Nullable Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall, boolean idempotent)
wrap inputCallableCollection toTtlCallableCollection.- Parameters:
tasks- task to be wrappedreleaseTtlValueReferenceAfterCall- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.idempotent- is idempotent or not.truewill cover up bugs! DO NOT set, only when you know why.- Returns:
- Wrapped
Callable
-
unwrap
@Nullable public static <T> Callable<T> unwrap(@Nullable Callable<T> callable)
UnwrapTtlCallableto the original/underneath one.this method is
null-safe, when inputCallableparameter isnull, returnnull; if inputCallableparameter is not aTtlCallablejust return inputCallable.so
TtlCallable.unwrap(TtlCallable.get(callable))will always return the same inputcallableobject.- Since:
- 2.10.2
- See Also:
get(Callable),TtlUnwrap.unwrap(Object)
-
unwraps
@NonNull public static <T> List<Callable<T>> unwraps(@Nullable Collection<? extends Callable<T>> tasks)
UnwrapTtlCallableto the original/underneath one.Invoke
unwrap(Callable)for each element in input collection.This method is
null-safe, when inputCallablecollection parameter isnull, return a empty list.- Since:
- 2.10.2
- See Also:
gets(Collection),unwrap(Callable)
-
setTtlAttachment
public void setTtlAttachment(@NonNull String key, Object value)
- Specified by:
setTtlAttachmentin interfaceTtlAttachments- Parameters:
key- attachment keyvalue- attachment value- Since:
- 2.11.0
-
getTtlAttachment
public <T> T getTtlAttachment(@NonNull String key)
- Specified by:
getTtlAttachmentin interfaceTtlAttachments- Parameters:
key- attachment key- Since:
- 2.11.0
-
-