better handling of incoming messages in ruby/java