Skip to content

INT-3724: Gateway - Support CompletableFuture #1463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

garyrussell
Copy link
Contributor

JIRA: https://jira.spring.io/browse/INT-3724

Add support for CompletableFuture<?> return types on gateway methods, if JDK8 is being used.

  • If the return type is exactly CompletableFuture and an async executor is provided, use CompletableFuture.supplyAsync()
  • If there is no return async executor, return types can be CompletableFuture or a subclass and the flow can return such a future.
  • Also fixes a problem for return type Future<Message<?>> with no async executor; previously this caused a ClassCastException
    because the gateway returned the message - it assumed such return types would always run on an excutor.

We can consider back-porting this last part, but nobody has complained.

TODO: Docs, after review

JIRA: https://jira.spring.io/browse/INT-3724

Add support for `CompletableFuture<?>` return types on gateway methods, if JDK8 is being used.

- If the return type is exactly `CompletableFuture` and an async executor is provided, use `CompletableFuture.supplyAsync()`
- If there is no return async executor, return types can be `CompletableFuture` or a subclass and the flow can return such a future.

- Also fixes a problem for return type `Future<Message<?>>` with no async executor; previously this caused a `ClassCastException`
   because the gateway returned the message - it assumed such return types would always run on an excutor.

We can consider back-porting this last part, but nobody has complained.
@@ -72,6 +82,13 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
}

public BeanDefinitionHolder parse(Map<String, Object> gatewayAttributes) {
boolean completableFutureCapable = true;
try {
ClassUtils.forName("java.util.concurrent.CompletableFuture", this.beanClassLoader);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this one is a part of JVM I don't see reason to worry about classloader.
Although you have already done that we can live with that and merge as is.

@garyrussell
Copy link
Contributor Author

Pushed docs

If `DEBUG` logging is enabled, a log is emitted indicating that the async executor cannot be used for this scenario.


`CompletionFuture` s can be used to perform additional manipulation on the reply, such as:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional word?
" CompletableFuture s " ?
Let me know and I fix it and merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo - thanks

@artembilan
Copy link
Member

Merged as 5e9624f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants