GOBIND for Server-side JDK Integration?

187 views
Skip to first unread message

Bill House

unread,
Mar 24, 2016, 11:43:08 AM3/24/16
to golang-nuts
We have a need to to integrate libraries written in Go with Java-based middleware services.  In the gobind design doc, it is said that the Android dependencies are "small", but that (as of 1.4), the golang runtime can only be loaded by the Android JVM.  We are considering doing the JNI/cgo work to make a non-mobile gobind for general use, but if there is some golang reason that would prevent this from happening, like golang libs refusing to load for non-Android JVMs, it would be better to find out sooner than later.  Anyone know this area well enough to comment? 

BTW, if someone is in a position to produce such a "gobind" analog for server-side JDK integration, we might consider a business arrangement.

Thanks,

Bill

Henrik Johansson

unread,
Mar 24, 2016, 12:13:25 PM3/24/16
to Bill House, golang-nuts
I don't know the specific use case but does it not seem easier to just create a (micro?) service or two in Go for each of the libraries?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bill House

unread,
Mar 24, 2016, 12:22:22 PM3/24/16
to Henrik Johansson, golang-nuts
That's the approach we are taking in the meantime -- little REST services that live side-by-side with the Java services.  Doable, but having the "gobind" capability is still attractive for better performance and other reasons having more to do with the Java system being integrated with.

Thanks,

Bill

Hyang-Ah Hana Kim

unread,
Mar 24, 2016, 12:34:47 PM3/24/16
to Bill House, golang-nuts
Have you considered upgrading Go to 1.5+ to get various buildmode support works. 1.6 is preferred.
Currently gobind work is focusing on mobile platform support. But I don't see any major roadblocker to make gobind work for non-android platform (maybe some build tags related changes)?

But from my experience, living with three languages in one process (C, Java, Go) is not very pleasant for maintenance and debugging. 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
__

sri...@laddoo.net

unread,
Mar 24, 2016, 12:43:27 PM3/24/16
to golang-nuts
I haven't tried this with gobind specifically, but I've gotten java -> go calls working fine on osx, with go code compiled as a shared library. You will likely need a slightly different version of gobind + seq which uses a vanilla compiler + JDK as opposed to the android NDK/SDK. The JNI function signatures are slightly different (JNI GetEnv IIRC) and you need a different set of headers. I haven't tried using libjvm to launch a jvm from Go, but that should also be possible. You'll also run into a few problems where gobind assumes it'll be able to find an Android Context. Keep in mind that you might not get too much of a performance win. The cgo overhead + JNI calling overhead can add up.

I'll play around with this a bit on the weekend and see how complex it'll be.

Sridhar

sri...@laddoo.net

unread,
Mar 27, 2016, 2:23:15 PM3/27/16
to golang-nuts
I've got a half-working prototype up at https://github.com/sridharv/gojava

It depends on a fork of gomobile which is at https://github.com/sridharv/gomobile-java.

Some of the tests panic so it's not ready for use yet. I'll take a look at this again next weekend, but if you have time this week pull requests are always welcome.

Once all the tests pass I'll publish instructions and a proper README.

Sridhar

PS: There's no need for a business agreement, etc. This is something I enjoyed spending a couple of Sunday afternoon hours on.

sri...@laddoo.net

unread,
Mar 27, 2016, 4:38:00 PM3/27/16
to golang-nuts
All tests that were in gomobile are now passing. Take it for a spin (if you still need it) and let me know if it proves useful. 
Reply all
Reply to author
Forward
0 new messages