[Play Java 2.3.9] Java / Scala Future driven by a callback

90 views
Skip to first unread message

Kalpak Gadre

unread,
Jun 20, 2015, 1:20:22 PM6/20/15
to play-fr...@googlegroups.com
Hi,


I am working on an application which deals with third-party SOAP services. A request from user delegates to multiple SOAP services simultaneously, aggregates the results and sends back to the user.

The system needs to be scalable and should allow multiple concurrent users. As each user requests ends up triggering about 10 web service calls and each call blocking for about 1 second, the system needs to be designed with non-blocking I/O.

I am using Apache CXF within Play Framework (Java) for this system. I have managed to generate the Asynchronous WS Client proxies and enable the async transport. What I am unable to figure out is how to return a Future to Play's Thread when I have delegated to multiple Web Service proxies and the results will be obtained as callbacks.

Option 1: Using async method calls returning Java Future.

As described in this scala.concurrent.Future wrapper for java.util.concurrent.Future thread, there is no way we can convert a Java Future to a Scala Future. Only way to get a result from the Future is to do Future.get() which blocks the caller. Since CXF's generated proxies return Java Future, this option is ruled out.

Option 2: Use Scala Future.

Since CXF generates the proxy interfaces, I am not sure if there is any way I can intervene and return a Scala Future (AFAIK Akka uses Scala Futures) instead of Java Future?

Option 3: Use the callback approach.

The async methods generated by CXF which return Java Future also takes a callback object which I suppose will provide a callback when result is ready. To use this approach, I will need to return a Future which will wait until I receive a callback.

I think Option 3 is most promising, although I have no ideas about how I can return a Future which will be completed on receiving a callback. I could possibly have a thread waiting in a while(true) and waiting in between until result is available. Again, I don't know how I can go into wait without blocking the thread?

In a nutshell, I am trying to build a system which is making a lot of SOAP web service calls, where each call blocks for significant time. The system may easily run out of threads in case of lot of concurrent web service calls. I am working on finding a solution which is non-blocking I/O based which can allow many ongoing web service calls at the same time.

Thanks,

Kalpak

Kalpak Gadre

unread,
Jun 20, 2015, 1:31:09 PM6/20/15
to play-fr...@googlegroups.com
To simplify, How can I create a Promise<Result> which is completed on receiving a callback? 

I can create a function which loops infinitely waiting for some delta time in between, but then the wait operation also needs to be non blocking.

--
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/haLz6QKhGGo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/e7de4bfe-f777-48c5-ba40-e44153729a9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Kalpak R. Gadre

Kalpak Gadre

unread,
Jun 22, 2015, 12:56:29 AM6/22/15
to play-fr...@googlegroups.com
Figured that Promise is exactly the thing I needed. I was under impression that Promise also needs a block of code like Future which it will run and will complete when the block of code completes. 

play.libs.F.RedeemablePromise was what I needed to use.

Thanks,

Kalpak
--
Kalpak R. Gadre

James Roper

unread,
Jun 23, 2015, 1:08:54 AM6/23/15
to play-framework
If you're interested, Typesafe has a commercial play-soap library in beta.  The proxies it generates return either scala Future or Play Java F.Promise (configurable), and so you can just use it directly, no need to wrap things.

You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/CAPgBAs42ECtDwhp4aT7T-ZE_hRL6Wxe0iYiOQp0zEGF1MdP_Eg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
James Roper
Software Engineer

Typesafe – Build reactive apps!
Twitter: @jroper

Kalpak Gadre

unread,
Jun 23, 2015, 1:37:38 AM6/23/15
to play-fr...@googlegroups.com
Thanks James,

I will definitely keep that in mind. 

For now, I have managed to get it working with CXF, Async HTTP Transport and Promise API. I am planning to do a load test and find out how well it is working together.

Thanks,

Kalpak


For more options, visit https://groups.google.com/d/optout.



--
Kalpak R. Gadre
Reply all
Reply to author
Forward
0 new messages