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
TtlCallable
decorate Callable
to get TransmittableThreadLocal
value
and transmit it to the time of Callable
execution, needed when use Callable
to thread pool.
Use factory method get(Callable)
to get decorated instance.
Other TTL Wrapper for common Functional Interface
see TtlWrappers
.
- Since:
- 0.9.0
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
-
Field Summary
Fields inherited from interface com.alibaba.ttl.spi.TtlAttachments
KEY_IS_AUTO_WRAPPER
-
Method Summary
Modifier and TypeMethodDescriptioncall()
wrap methodCallable.call()
.boolean
static <T> TtlCallable<T>
Factory method, wrap inputCallable
toTtlCallable
.static <T> TtlCallable<T>
Factory method, wrap inputCallable
toTtlCallable
.static <T> TtlCallable<T>
Factory method, wrap inputCallable
toTtlCallable
.return the original/underneathCallable
.static <T> List<TtlCallable<T>>
gets
(Collection<? extends Callable<T>> tasks) wrap inputCallable
Collection toTtlCallable
Collection.static <T> List<TtlCallable<T>>
gets
(Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall) wrap inputCallable
Collection toTtlCallable
Collection.static <T> List<TtlCallable<T>>
gets
(Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall, boolean idempotent) wrap inputCallable
Collection toTtlCallable
Collection.<T> T
getTtlAttachment
(String key) int
hashCode()
void
setTtlAttachment
(String key, Object value) toString()
unwrap()
unwrap to the original/underneathCallable
.static <T> Callable<T>
UnwrapTtlCallable
to the original/underneath one.unwraps
(Collection<? extends Callable<T>> tasks) UnwrapTtlCallable
to the original/underneath one.
-
Method Details
-
call
wrap methodCallable.call()
. -
getCallable
return the original/underneathCallable
. -
unwrap
unwrap to the original/underneathCallable
.- Specified by:
unwrap
in interfaceTtlWrapper<V>
- Since:
- 2.11.4
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-
get
-
get
@Nullable @Contract(value="null, _ -> null; !null, _ -> !null", pure=true) public static <T> TtlCallable<T> get(@Nullable Callable<T> callable, boolean releaseTtlValueReferenceAfterCall) - Parameters:
callable
- inputCallable
releaseTtlValueReferenceAfterCall
- release TTL value reference after run, avoid memory leak even ifTtlRunnable
is referred.- Returns:
- Wrapped
Callable
-
get
@Nullable @Contract(value="null, _, _ -> null; !null, _, _ -> !null", pure=true) public static <T> TtlCallable<T> get(@Nullable Callable<T> callable, boolean releaseTtlValueReferenceAfterCall, boolean idempotent) - Parameters:
callable
- inputCallable
releaseTtlValueReferenceAfterCall
- release TTL value reference after run, avoid memory leak even ifTtlRunnable
is referred.idempotent
- is idempotent or not.true
will 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 inputCallable
Collection toTtlCallable
Collection.- 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 inputCallable
Collection toTtlCallable
Collection.- Parameters:
tasks
- task to be wrappedreleaseTtlValueReferenceAfterCall
- release TTL value reference after run, avoid memory leak even ifTtlRunnable
is referred.- Returns:
- Wrapped
Callable
-
gets
@NonNull public static <T> List<TtlCallable<T>> gets(@Nullable Collection<? extends Callable<T>> tasks, boolean releaseTtlValueReferenceAfterCall, boolean idempotent) wrap inputCallable
Collection toTtlCallable
Collection.- Parameters:
tasks
- task to be wrappedreleaseTtlValueReferenceAfterCall
- release TTL value reference after run, avoid memory leak even ifTtlRunnable
is referred.idempotent
- is idempotent or not.true
will cover up bugs! DO NOT set, only when you know why.- Returns:
- Wrapped
Callable
-
unwrap
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static <T> Callable<T> unwrap(@Nullable Callable<T> callable) UnwrapTtlCallable
to the original/underneath one.this method is
null
-safe, when inputCallable
parameter isnull
, returnnull
; if inputCallable
parameter is not aTtlCallable
just return inputCallable
.so
TtlCallable.unwrap(TtlCallable.get(callable))
will always return the same inputcallable
object.- Since:
- 2.10.2
- See Also:
-
unwraps
@NonNull public static <T> List<Callable<T>> unwraps(@Nullable Collection<? extends Callable<T>> tasks) UnwrapTtlCallable
to the original/underneath one.Invoke
unwrap(Callable)
for each element in input collection.This method is
null
-safe, when inputCallable
collection parameter isnull
, return an empty list.- Since:
- 2.10.2
- See Also:
-
setTtlAttachment
- Specified by:
setTtlAttachment
in interfaceTtlAttachments
- Parameters:
key
- attachment keyvalue
- attachment value- Since:
- 2.11.0
-
getTtlAttachment
- Specified by:
getTtlAttachment
in interfaceTtlAttachments
- Parameters:
key
- attachment key- Since:
- 2.11.0
-