Skip to content

Instantly share code, notes, and snippets.

@charlesmunger
Created May 8, 2013 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesmunger/5544182 to your computer and use it in GitHub Desktop.
Save charlesmunger/5544182 to your computer and use it in GitHub Desktop.
Example code for running Pheme
package charlesmunger.testpheme;
import com.google.common.collect.Collections2;
import pheme.api.Component;
import pheme.api.ComponentType;
import pheme.api.Pheme;
import scala.Array;
import scala.reflect.ClassTag;
/**
* Hello world!
*
*/
public class App {
public static void main(String[] args) {
String dir = System.getProperty("user.dir");
System.out.println(dir);
new Thread(new Runnable() {
public void run() {
play.core.server.NettyServer.main(new String[]{"."});
}
}).start();
String hostname = getHostname(args);
Pheme pheme = new Pheme(hostname);
Component starter = pheme.register(App.class.getSimpleName(), ComponentType.JOB);
starter.log("info", "I'M ALIVE. SEND HELP. At least there's beer here.");
starter.count("Beers on the wall", 99);
for (int i = 99; i > 0; i--) {
starter.count("Beers on the wall", -1);
wait(500);
}
starter.log("info", "Out of beer! Now we're really in trouble.");
wait(500);
System.exit(0);
}
private static String getHostname(String[] args) {
String hostname = "127.0.0.1";
if (args.length >= 1) {
hostname = args[0];
}
return hostname;
}
private static void wait(int milli) {
try {
Thread.sleep(milli);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment