Package org.cspoker.external.pokersource

Examples of org.cspoker.external.pokersource.PokersourceConnection


  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();
    }

  }
View Full Code Here


  @Override
  public RemoteServerContext login(String username, String password) throws LoginException {
    try {
      SerialListener serial = new SerialListener();
      TransListener transListener = new TransListener();
      final PokersourceConnection conn = new PokersourceConnection(server);
      conn.addListeners(serial, transListener);
      conn.send(new Login(username, password));
      serialObtained.await();
      conn.removeListeners(serial, transListener);
      return new PSServerContext(conn, serial.getSerial());
    } catch (IOException e) {
      throw new LoginException(e.getMessage());
    } catch (JSONException e) {
      throw new LoginException(e.getMessage());
View Full Code Here

TOP

Related Classes of org.cspoker.external.pokersource.PokersourceConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.