I have two APIs that return two different Results classes. We combine these two results to get a finalClass.
Basically, if these Apis are run at the Same time ,
if it receives Class A first with a certain result (G,H), it doesn't matter what class B is (we will not wait for serviceAPI B), just return Final class from table below.
If Class A does not have a certain result, we have to wait for combine both results (A & B) to get Final class.
I'm trying to use these stackoverflow articles, to process this. I prefer not to mark them with an interface marker class (these are legacy objects), however open to it as second option.
Return the future that gets executed first with a specific condition on the response
In java, how do I process CompletableFutures and get the first desireable result that completes?
public class A {
public String resultA;
}
public class B {
public int resultB;
}
public class Final {
public String resultFinal;
}
CompletableFuture<A> futureA = CompletableFuture.supplyAsync(() -> serviceA.getAPI());
CompletableFuture<B> futureB = CompletableFuture.supplyAsync(() -> serviceB.getAPI());
CompletableFuture.allOf(futureA,futureB).join();
open to making both classes a marker interface
public class A implements MarkerResponse {
public class B implements MarkerResponse {
public interface MarkerResponse {}
Currently using Spring Boot with Java 8. Context: the real service dual apis can be variable 1-5 min, so trying to do performance improvement if possible.