Ok, so this is how I think it is possible to implement reactive R.
Non-blocking calls from java
You need to fork RServe java client and split method request
into two parts in this line [1]. First part write request to the socket and the second waits for response. We need to make waiting optional by for example some boolean
flag.
Returning result from R
You will need some kind of active communication to Java. One possibility is to use plain sockets or something on higher level as HTTP. I thought about httpRequest package [2].
So the call from java should look like:
connection.eval(s"""simplePostToHost(
"192.168.12.12","/listener/results/",
try(eval(parse(text="$code")),silent=TRUE),port=8080""")
Listening for result in Java
The request and response should share some kind of unique ID so we know which response is for which request. You should run some service that listen on path /listener/results for incoming results and tells Java that result is ready. It should also enable to reuse RConnection that previously should be marked as "busy".
I recommend to use it this part scala Promise[T] .
Hope it helps somebody. I'm probably going to implement it once my company needs it.
[1]https://github.com/s-u/REngine/blob/a74e184c051c2d2e850430cd2d0526656d3a6c48/Rserve/protocol/RTalk.java#L211
[2]https://cran.r-project.org/web/packages/httpRequest/httpRequest.pdf
socketConnection
, from R, to connect to your Java client (who should be listening). – Alarcon