To improve console application I have made I though adding some new functions to track for example the status of threads (these threads are responsible for monitoring data from different sources). So what I was thinking to do is create some kind of mechanism which would allow me to query the status of my application. The following methods are the methods I thought to implement:
1) Simple thread listening for user input and checking some variables or calling some functions on monitoring threads. Quite simple to implement, but has one problem at least I don’t see the way to overpass it: application can run for monthes and if I want to access the machine where it is running using SSH it will be not possible to use my “console”
2) Create some RMI or some socket interface which could be connected by another simple program, sending commands and recieving responses. Seems to me the most suitable method, more hard to implement but can be quite powerfull.
3) The last and the simplest sulution, which is not console, but could serve my needs is writing data to some file and after reading the file. I don’t cosider implementing this because it’s not interactive at all.
The question is: is there any better method to implementing console for some java application besides the presented ones?
Thanks a lot,
Serhiy.
The best solution is something similar to your ideas about RMI. You could use a different technology if you like, but the idea of allowing the application to accept new monitoring connections is critical.
File base solutions (like you outline in #3) fall victim to loss of the file, lack of disk space, etc). Solutions like you mention in #1 fall victim to not properly handling the access from a different user space.
With RMI (or similar, like CORBA, SOAP, Web Service, etc.) you get proper networking which allows people to communicate when on different machines (or just in different process spaces). That’s a lot of value (and a bit of code), but it is far less headache than a the job half-done.