tags:

views:

164

answers:

5

Is there a reliable, cross-platform way to do IPC (between two JVMs running on the same host) in Java (J2SE) that doesn't rely on the network stack?

To be more specific, I have a server application that I'd like to provide a small "monitoring" GUI app for. The monitor app would simply talk to the server process and display simple status information. The server app has a web interface for most of its interaction, but sometimes things go wrong (port conflict, user forgot password) that require a local control app.

In the past I've done this by having the server listen on 127.0.01 on a specific port and the client communicates that way. However, this isn't as reliable as I'd like. Certain things can make this not work (Windows's network stack can be bizarre with VPN adapters, MediaSense, laptops lid closing/power saving modes). You can imagine the user's confusion when the tool they use to diagnose the server doesn't even think the server is running.

Named Pipes seem plausible, but Java doesn't seem to have an API for them unless I'm mistaken. Ideas? Third party libraries that support this? My performance requirements are obviously extremely lax in case that helps.

A: 

Does Windows even have named pipes? I was going to suggest it. You'd just have to use an exec() to create it.

Kevin Bourrillion
Yeah, Windows has named pipes. I did that... ONCE!
Carl Smotricz
+2  A: 

One of my specialties is really low-tech solutions. Especially if your performance requirements aren't critical:

The low-low tech alternative to named pipes is named FILES. Think yourself up a protocol where one app writes a file and another reads it. If need be, you can do semaphoring between them.

Remember that a rename is pretty much an atomic operation, so you could calmly write a file in some process and then make it magically appear in its entirety by renaming/moving it from somewhere that wasn't previously visible.

You can poll for data by checking for appearance of a file (in a loop with a SLEEP in it), and you can signal completion by deleting the file.

An added benefit is that you can debug your app using the DIR command :)

Carl Smotricz
Love it. Simplicity FTW.
CarlG
+1  A: 

Depending on how much data you need to pass between the server and the diagnostic tool you could:

  • go low-tech and have a background thread check a file in the file system; fetch commands from it; write ouput into a second to be picked up by the diagnostic tool.
  • build a component that manages an input/output queue in shared memory connecting to it via JNI.
rsp
A: 

Consider JMX. I do not know if any of the Windows JVM's allow JMX over shared memory.

Thorbjørn Ravn Andersen
A: 

Map a read_write byte buffer into memory from a FileChannel. Write status information into the byte buffer, then call force() to get it written out. On the monitor side, open up the same file and map it into memory too. Poll it periodically to find out the status.

Ross Judson