1

I'm writing a little application that will act as an uninstaller for a bigger application. I want the uninstaller to be able to send a very basic message (a simple notify) to the application if it's running.

What is the best way to do this?

Illustration of what I want:

public class Uninstall {
    public static void main(String[] args) {
        if(isRunning("Application")) {
            // Tell Application to clear data & exit
            sendMessage("Application","EXIT");
        }
    }
}
Darajan
  • 868
  • 1
  • 9
  • 23

1 Answers1

1

You're options are basically

  • Through the file system

    A bit clunky, but easy to debug. Basically your main application would keep an eye on the file system (for instance by using a WatchService. More info here).

  • Through plain socktes

    Your main application opens up a socket and accepts connections from other applications that want to communicate with it. If all you want to do is to be able to shut down the main application, something as simple as

    new Thread() {
        public void run() {
            new ServerSocket(123456).accept();
            System.exit(0);
        }
    }.start();
    

    might do.

  • Over RMI

    Use an RMI registry to let your uninstaller do remote method invocations on your main application.

Assuming that you will build both the main application and the installer at the same time. And since they will run on the same JVM version and both on localhost I would definitely recommend RMI.

(Other OS-specific answers may include named pipes or signals, but I'd discourage you to go in this direction.)

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • Thanks for the fast answer, RMI definitely what I was looking for. – Darajan Sep 29 '14 at 13:05
  • @Underbar: RMI is probably a complete overkill and unnecessary complex for your purpose. – jarnbjo Sep 29 '14 at 13:07
  • @jarnbjo what would you recommend? Going through the filesystem/sockets seems to open up a hole for any other application to force my app to uninstall. – Darajan Sep 29 '14 at 13:09
  • 2
    RMI isn't much safer. In fact, I don't think there is a way to prevent someone from inpersonating the uninstaller. A simple socket may be the best way to go if all you want to do is to send one simple command. – aioobe Sep 29 '14 at 13:10
  • It's of course possible to implement some kind of authentication mechanism to prevent any "unknown" application to send an IPC signal. Neither RMI nor plain socket communication offer authentication by themselves. – jarnbjo Sep 29 '14 at 13:39