Generic JAva State MACHine implementation.