Created
May 8, 2013 22:30
-
-
Save charlesmunger/5544182 to your computer and use it in GitHub Desktop.
Example code for running Pheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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