i want to know a simple way of implementing callback mechanism in Rserve for a java client . According to Rserve docs :
Rserve provides no callback functionality. Your application could implement callbacks via TCP/IP and the R sockets but it is not a part of Rserve.
This means my java client can call functions on the remote Session through Rconnection reference , but the remote Session cannot call back the java client which has instantiated it . How can i develop such a mechanism . If its through R sockets or a tcp/ip server , does that mean for every connection there will be a socket server open ?
Ok, so this is how I think it is possible to implement reactive R.
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.
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""")
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With