Add lock to BaseRobot to prevent multiple robot processes.
Resolves #3 (closed)
In previous APIs, this has been implemented using a lock file in /tmp
. For this version it was suggested that we put a PID file in /var/run
, which was an approach that I initially approved of.
However, up to this point and as confirmed by #120 (closed), we are ensuring the cross-platform compatibility of j5
and I'm sure you're aware that Windows doesn't have /var/run
. The closest equivalent is called a Mutex and has very poor support on Unix systems.
The solution that I have implemented in this pull request takes leafs out of the book of enterprise Java and isn't exactly what I would do in an ideal world.
Binding to a TCP port on the host is kept to a single process at the kernel level, which means that it is harder to override (e.g no deleting of the PID file.). Additionally, in the case of a crash, the TCP port is automatically closed as we are no longer binding to it.
I am still open to alternative solutions to this and am looking forward to hearing back from you all.