How can I supply asynchronous data to Node from Java using J2V8

238 views Asked by At

I've got an app written in JavaScript that makes use of the rxjs library to handle asynchronous data. I've wanted to plugin a java back end and I found J2V8 which lets me fire up Node and talk to it from Java.

For synchronous tasks everything is fine, but when I'm mapping an rxjs Observable to an RxJava Observable I get (silently swallowed) "Invalid V8 thread access" exceptions.

I can see why this might be the case. Node is single threaded and probably busy doing it's own thing when I try and push in my asynchronous response.

The wider view of what I'm wanting to achieve is something like :

Subscription event arrives in Java => Subscription passed to NodeJS for processing => NodeJS calls back out to Java for the actual data source => Java pushes data back into NodeJS for processing => NodeJS passes on the results to the original Java subscriber.

Specifically what I'd like is some advice on how I might push asynchronous events from Java into Node.

Edit : To respond to queries about why I'm trying to do this. I've got a NodeJS server that does what I want it to do with some JS Data Sources. I'm wanting to add a Java Data Source that will communicate with the NodeJS server using websockets. There's a bunch of request/response logic that is common for every data source so I was hoping to funnel requests that hit the Java Data Source through a short JS pipeline containing this logic. I could duplicate the logic in Java, but I'm trying to avoid writing and having to maintain the same thing in 2 different languages.

It's entirely possible that what I'm trying to do is daft, but I'm in prototype stage so I'm experimentng.

0

There are 0 answers