public interface Tuple6Task<T1,T2,T3,T4,T5,T6> extends Task<Tuple6<T1,T2,T3,T4,T5,T6>>
Modifier and Type | Method and Description |
---|---|
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
andThen(Consumer6<T1,T2,T3,T4,T5,T6> consumer)
Equivalent to
andThen("andThen", consumer) . |
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
andThen(java.lang.String desc,
Consumer6<T1,T2,T3,T4,T5,T6> consumer)
Creates a new task which applies a consumer to the result of this task
and completes with a result of this task.
|
static <T1,T2,T3,T4,T5,T6> |
cast(Task<Tuple6<T1,T2,T3,T4,T5,T6>> task) |
default <R> Task<R> |
flatMap(Function6<T1,T2,T3,T4,T5,T6,Task<R>> f)
Equivalent to
flatMap("flatMap", f) . |
default <R> Task<R> |
flatMap(java.lang.String desc,
Function6<T1,T2,T3,T4,T5,T6,Task<R>> f)
Creates a new task by applying a function to the successful result of this task and
returns the result of a function as the new task.
|
default <R> Task<R> |
map(Function6<T1,T2,T3,T4,T5,T6,R> f)
Equivalent to
map("map", f) . |
default <R> Task<R> |
map(java.lang.String desc,
Function6<T1,T2,T3,T4,T5,T6,R> f)
Creates a new task by applying a function to the successful result of this task.
|
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
onFailure(Consumer1<java.lang.Throwable> consumer)
Equivalent to
onFailure("onFailure", consumer) . |
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
onFailure(java.lang.String desc,
Consumer1<java.lang.Throwable> consumer)
Creates a new task which applies a consumer to the exception this
task may fail with.
|
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
recover(Function1<java.lang.Throwable,Tuple6<T1,T2,T3,T4,T5,T6>> f)
Equivalent to
recover("recover", func) . |
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
recover(java.lang.String desc,
Function1<java.lang.Throwable,Tuple6<T1,T2,T3,T4,T5,T6>> f)
Creates a new task that will handle failure of this task.
|
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
recoverWith(Function1<java.lang.Throwable,Task<Tuple6<T1,T2,T3,T4,T5,T6>>> f)
Equivalent to
recoverWith("recoverWith", func) . |
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
recoverWith(java.lang.String desc,
Function1<java.lang.Throwable,Task<Tuple6<T1,T2,T3,T4,T5,T6>>> f)
Creates a new task that will handle failure of this task.
|
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
shareable()
Creates a new task that can be safely shared within a plan or between multiple
plans.
|
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
withSideEffect(Function6<T1,T2,T3,T4,T5,T6,Task<?>> func)
Equivalent to
withSideEffect("sideEffect", func) . |
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
withSideEffect(java.lang.String desc,
Function6<T1,T2,T3,T4,T5,T6,Task<?>> func)
Creates a new task that will run another task as a side effect once the primary task
completes successfully.
|
default Tuple6Task<T1,T2,T3,T4,T5,T6> |
withTimeout(long time,
java.util.concurrent.TimeUnit unit)
Creates a new task that has a timeout associated with it.
|
action, action, andThen, andThen, andThen, andThen, apply, async, async, async, async, blocking, blocking, callable, callable, contextRun, failure, failure, flatMap, flatMap, flatten, flatten, getId, getName, getPriority, getShallowTrace, getShallowTraceBuilder, getTrace, getTraceBuilder, map, map, par, par, par, par, par, par, par, par, setPriority, setTraceValueSerializer, toTry, toTry, transform, transform, value, value, withSideEffect, withSideEffect
addListener, await, await, get, getError, getOrDefault, isDone, isFailed
cancel
default <R> Task<R> map(Function6<T1,T2,T3,T4,T5,T6,R> f)
map("map", f)
.map(String, Function6)
default <R> Task<R> map(java.lang.String desc, Function6<T1,T2,T3,T4,T5,T6,R> f)
Task<String>
hello = Task.value("Hello World"); // this task will complete with value 11 Task<Integer>
length = hello.map("length", s->
s.length());
If this task is completed with an exception then the new task will also complete with that exception.
Task<String>
failing = Task.callable("hello", ()->
{ return "Hello World".substring(100); }); // this task will fail with java.lang.StringIndexOutOfBoundsException Task<Integer>
length = failing.map("length", s->
s.length());
R
- return type of function func
desc
- description of a mapping function, it will show up in a tracef
- function to be applied to successful result of this task.default <R> Task<R> flatMap(Function6<T1,T2,T3,T4,T5,T6,Task<R>> f)
flatMap("flatMap", f)
.flatMap(String, Function6)
default <R> Task<R> flatMap(java.lang.String desc, Function6<T1,T2,T3,T4,T5,T6,Task<R>> f)
Task<URI>
url = Task.value("uri", URI.create("http://linkedin.com")); // this task will complete with contents of a LinkedIn homepage // assuming fetch(u) fetches contents given by a URI Task<String>
homepage = url.flatMap("fetch", u->
fetch(u));
If this task is completed with an exception then the new task will also contain that exception.
Task<URI>
url = Task.callable("uri", ()->
URI.create("not a URI")); // this task will fail with java.lang.IllegalArgumentException Task<String>
homepage = url.flatMap("fetch", u->
fetch(u));
R
- return type of function func
desc
- description of a mapping function, it will show up in a tracef
- function to be applied to successful result of this task which returns new task
to be executeddefault Tuple6Task<T1,T2,T3,T4,T5,T6> andThen(Consumer6<T1,T2,T3,T4,T5,T6> consumer)
andThen("andThen", consumer)
.andThen(String, Consumer6)
default Tuple6Task<T1,T2,T3,T4,T5,T6> andThen(java.lang.String desc, Consumer6<T1,T2,T3,T4,T5,T6> consumer)
Task<String>
hello = Task.value("greeting", "Hello World"); // this task will print "Hello World" Task<String>
sayHello = hello.andThen("say", System.out::println);
If this task fails then consumer will not be called and failure will be propagated to task returned by this method.
Task<String>
failing = Task.callable("greeting", ()->
{ return "Hello World".substring(100); }); // this task will fail with java.lang.StringIndexOutOfBoundsException Task<String>
sayHello = failing.andThen("say", System.out::println);
desc
- description of a consumer, it will show up in a traceconsumer
- consumer of a value returned by this taskdefault Tuple6Task<T1,T2,T3,T4,T5,T6> recover(Function1<java.lang.Throwable,Tuple6<T1,T2,T3,T4,T5,T6>> f)
recover("recover", func)
.default Tuple6Task<T1,T2,T3,T4,T5,T6> recover(java.lang.String desc, Function1<java.lang.Throwable,Tuple6<T1,T2,T3,T4,T5,T6>> f)
// this method return task which asynchronously retrieves Person by id Task<Person>
fetchPerson(Long id) { (...) } // this task will fetch Person object and transform it into"<first name> <last name>"
// if fetching Person failed then form"Member <id>"
will be return Task<String>
userName = fetchPerson(id) .map("toSignature", p->
p.getFirstName() + " " + p.getLastName()) .recover(e->
"Member " + id);
Note that task cancellation is not considered to be a failure. If this task has been cancelled then task returned by this method will also be cancelled and recovery function will not be applied.
recover
in interface Task<Tuple6<T1,T2,T3,T4,T5,T6>>
desc
- description of a recovery function, it will show up in a tracef
- recovery function which can complete task with a value depending on
failure of this taskdefault Tuple6Task<T1,T2,T3,T4,T5,T6> recoverWith(Function1<java.lang.Throwable,Task<Tuple6<T1,T2,T3,T4,T5,T6>>> f)
recoverWith("recoverWith", func)
.recoverWith
in interface Task<Tuple6<T1,T2,T3,T4,T5,T6>>
Task.recoverWith(String, Function1)
default Tuple6Task<T1,T2,T3,T4,T5,T6> recoverWith(java.lang.String desc, Function1<java.lang.Throwable,Task<Tuple6<T1,T2,T3,T4,T5,T6>>> f)
// this method return task which asynchronously retrieves Person by id from cache Task<Person>
fetchFromCache(Long id) { (...) } // this method return task which asynchronously retrieves Person by id from DB Task<Person>
fetchFromDB(Long id) { (...) } // this task will try to fetch Person from cache and // if it fails for any reason it will attempt to fetch from DB Task<Person>
user = fetchFromCache(id).recoverWith(e->
fetchFromDB(id));
If recovery task fails then returned task is completed with that failure.
Note that task cancellation is not considered to be a failure. If this task has been cancelled then task returned by this method will also be cancelled and recovery function will not be applied.
recoverWith
in interface Task<Tuple6<T1,T2,T3,T4,T5,T6>>
desc
- description of a recovery function, it will show up in a tracef
- recovery function provides task which will be used to recover from
failure of this taskdefault Tuple6Task<T1,T2,T3,T4,T5,T6> onFailure(Consumer1<java.lang.Throwable> consumer)
onFailure("onFailure", consumer)
.default Tuple6Task<T1,T2,T3,T4,T5,T6> onFailure(java.lang.String desc, Consumer1<java.lang.Throwable> consumer)
Task<String>
failing = Task.callable("greeting", ()->
{ return "Hello World".substring(100); }); // this task will print out java.lang.StringIndexOutOfBoundsException // and complete with that exception as a reason for failure Task<String>
sayHello = failing.onFailure("printFailure", System.out::println);
If this task completes successfully then consumer will not be called.
Task<String>
hello = Task.value("greeting", "Hello World"); // this task will return "Hello World" Task<String>
sayHello = hello.onFailure(System.out::println);
Exceptions thrown by a consumer will be ignored.
Note that task cancellation is not considered to be a failure. If this task has been cancelled then task returned by this method will also be cancelled and consumer will not be called.
default Tuple6Task<T1,T2,T3,T4,T5,T6> shareable()
Sharing tasks within a plan or among different plans is generally not safe because task can
be cancelled if it's parent has been resolved. Imagine situation where fetch
task that fetches data from a remote server is shared among few plans. If one of those
plans times out then all started tasks that belong to it will be automatically cancelled.
This means that fetch
may also be cancelled and this can affect other plans that
are still running. Similar situation can happen even within one plan if task is used multiple
times.
In example below google
task has timeout 10ms what causes entire plan to fail and as a consequence
all tasks that belong to it that have been started - in this case bing
task. This may
be problematic if bing
task is used somewhere else.
final Task<Response>
google = HttpClient.get("http://google.com").task(); final Task<Response>
bing = HttpClient.get("http://bing.com").task(); // this task will fail because google task will timeout after 10ms // as a consequence bing task will be cancelled final Task> both = Task.par(google.withTimeout(10, TimeUnit.MILLISECONDS), bing);
shareable
method solves above problem. Task returned by shareable()
can be
can be cancelled without affecting original task.
final Task<Response>
google = HttpClient.get("http://google.com").task(); final Task<Response>
bing = HttpClient.get("http://bing.com").task(); // this task will fail because wrapped google task will timeout after 10ms // notice however that original googel and bing tasks were not cancelled final Task> both = Task.par(google.shareable().withTimeout(10, TimeUnit.MILLISECONDS), bing.shareable());
default Tuple6Task<T1,T2,T3,T4,T5,T6> withTimeout(long time, java.util.concurrent.TimeUnit unit)
TimeoutException
as a reason of failure and this task will be cancelled.
final Taskgoogle = HttpClient.get("http://google.com").task() .withTimeout(10, TimeUnit.MILLISECONDS);
default Tuple6Task<T1,T2,T3,T4,T5,T6> withSideEffect(Function6<T1,T2,T3,T4,T5,T6,Task<?>> func)
withSideEffect("sideEffect", func)
.withSideEffect(String, Function6)
default Tuple6Task<T1,T2,T3,T4,T5,T6> withSideEffect(java.lang.String desc, Function6<T1,T2,T3,T4,T5,T6,Task<?>> func)
Task<Long>
id = Task.value("id", 1223L); // this task will be completed as soon as user name is fetched // by fetch() method and will not fail even if updateMemcache() fails Task<String>
userName = id.flatMap("fetch", u->
fetch(u)) .withSideEffect("update memcache", u->
updateMemcache(u));
desc
- description of a side effect, it will show up in a tracefunc
- function to be applied on result of successful completion of this task
to get side effect taskstatic <T1,T2,T3,T4,T5,T6> Tuple6Task<T1,T2,T3,T4,T5,T6> cast(Task<Tuple6<T1,T2,T3,T4,T5,T6>> task)