Java has come a long way since I first started developing with Java back when the gold standard was
JDK 1.1 (1997). We now have Generics, hooray no more writing wrappers for container classes to add type safety. Anonymous classes, great for providing glue logic, not as good as lambdas.
Over this time the focus has moved away from threads as the solution, as they limit scalability.
Java now supports asynchronous IO but a shame that the standard Future (java.util.concurrent.Future) interface does not include callbacks, you have to poll it to find out when the IO has completed. This results in a number of incompatible extensions to Future.
I look back at the changes and I see the influence from other sources. i.e. C++ STL (Standard Template Language) for generics. Soon we will be writing functional code in Java!
A Console server
A while back I wrote a console server in Python, when I came across the apache Mina project along with
its ssh server and a terminal handler for mina. I could see I had the pieces to implement this in Java.
A console server is a terminal server working in reverse. Instead of connecting to a serial port with your terminal to talk to the computer, you connect over a network connection (SSH preferably) to talk to an external device (network router) on its serial management port. In the network world this can be out of band and allow you to access a device that is having problems.
The code for this is up on github, it is currently a work in progress.
Conclusions
I found implementing this tool in Java a little more long winded, especially the command parser code. The dynamic languages
such as Python make this part of a problem much easier to implement, partly due to the untyped nature of the language
and partly due to functions being first class objects. In Java to create a table of actions for each command I ended up
creating a class for each, that implemented at execute method, in Python I just did dynamic lookup on my own class
to find the correct action method. I am sure that I could do something using the reflection APIs but this still feels
heavier.
It was interesting exploring the Mina framework and I can see me using this in my day job as it does provide a solid
base of asynchronous networking functionality. Unlike some .net SSH libraries I tried to use in a recent job, where there
seemed to be no awareness of thread safety.
Futures
The command parser needs some work to implement additional commands.
The python version also logs all data on the serial ports.
The Python version allows you to connect to any port from the master connection (Command interface).
I need an escape mechanism, i.e. ATexit so can close a console connection.
The command interface exit command needs to work, need to dig into mina ssh to close the current session.
Finally
If you are looking for a console server at present I would suggest you use the Python version and run it on a
Raspberry Pi. If you are in the market for a console server in Java to embed somewhere you can always pay
me to tidy this up.