Whirr provides a Java API for stopping and starting clusters. Please see the javadoc and the unit test source code for how to achieve this.
There's also some example code at http://github.com/hammer/whirr-demo.