Refactor ExecutionEnvironments into generic and API dependent parts

This is a first step towards bringing the Scala API up to speed with the
Java API. By doing this a lot of the exisiting infrastructure can be
shared.