public void run() { HashSet<Query> processed = new HashSet<Query>(); List<Query> queries; while (true) { try { queries = connection.getNewMessages(); int newQueries = 0; for (Query q : queries) { if (!processed.contains(q)) { newQueries++; respondToQuery(q); processed.add(q); } } if (newQueries > 0) { System.out.println(newQueries + " new queries."); } } catch (SmsRecieveException e) { // TODO error log this e.printStackTrace(); } // sleep for a while before cheking again try { Thread.sleep(CHECK_FREQ); } catch (InterruptedException e) { System.out.println( "Something has gone terribly wrong, and the PioText thread has been interrupted. Exiting..."); e.printStackTrace(); System.exit(1); } } }
private void respondToQuery(Query query) { handler.identifyKeyword(query); String response = handler.getResponse(query); try { connection.sendSms(query.getPhoneNumber(), response); query.setTimeResponded(new Date()); query.setResponse(response); log(query); } catch (SmsSendException e) { // TODO error log this e.printStackTrace(); } }
/** Initializes the sms connection. */ public void initialize() throws ConnectionException { connection.connect(); }