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.
The downloaded artifact contains a example project that shows how Whirr can be used for various tasks .Check the examples subfolder.
You can execute an example by running:
$ ./bin/example [example-name]