private int game_id;
private Queue<Runnable> todos = new LinkedList<Runnable>();
private void run() throws IOException {
final PokersourceConnection conn = new PokersourceConnection("http://pokersource.eu/POKER_REST");
try {
AllEventListener listener = new LoggingListener(){
@Override
protected void log(JSONPacket event) {
logger.info(event.getClass().getSimpleName()+": "+event.toJSONObject().toString());
}
@Override
public void onSerial(Serial serial2) {
super.onSerial(serial2);
serial = serial2.getSerial();
}
@Override
public void onTable(Table table) {
super.onTable(table);
game_id = table.getId();
}
@Override
public void onError(Error error) {
super.onError(error);
try {
conn.close();
} catch (IOException e) {
logger.error(e);
}
}
@Override
public void onSelfInPosition(SelfInPosition selfInPosition) {
super.onSelfInPosition(selfInPosition);
try {
conn.send(new Call(serial, game_id));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
public void onSitOut(SitOut sitOut) {
super.onSitOut(sitOut);
if(sitOut.getGame_id()==game_id && sitOut.getSerial() == serial){
try {
conn.send(new Sit(serial, game_id));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
};
conn.addListener(listener);
conn.send(new Login("foobar", "foobar")).await();
conn.send(new TablePicker(serial, true)).await();
conn.startPolling(game_id);
conn.send(new SitOut(serial, game_id));
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} finally{
conn.close();
}
}