public void run() { try { final String app_id = "9c543f25063cb80ff1241154"; final String api_key = "tuuy8h_dfVheRO80T0AR"; String jsonResponce = GetTournamentsWithStatus(app_id, api_key, 6); trace(ExtensionLogLevel.INFO, "Started Tournaments JSON Responce : " + jsonResponce); String jsonResponce1 = GetTournamentsByDefault(app_id, api_key); trace(ExtensionLogLevel.INFO, "Tournaments JSON Responce : " + jsonResponce1); List<TournamentModel> tournList = ParseTournamentsResponce(jsonResponce); tournList.addAll(ParseTournamentsResponce(jsonResponce1)); synchronized (tournaments) { // Check created tournamemts, and create rooms for (TournamentModel tm : tournList) { TournamentModel contains = tournaments.get(tm.id); if (contains != null) { contains.UpdateMatchTime(tm); if (contains.date_games_start != null) trace( ExtensionLogLevel.INFO, "Tournament " + contains.id + " Started At " + tm.date_games_start); } else { Room room = CreateTournamentRoom(tm.title + "_" + tm.id, tm.id, (int) tm.max_players); tm.setRoom(room); tournaments.put(tm.id, tm); } } // найти id которых нету в полученном списке иу далить комнаты которые не существуют List<String> idsToRemove = new ArrayList<String>(); for (String key : tournaments.keySet()) { if (ContainsId(key, tournList)) continue; idsToRemove.add(key); } for (String key : idsToRemove) { TournamentModel tm = tournaments.get(key); getApi().removeRoom(tm.getRoom()); } } } catch (Exception e) { trace( ExtensionLogLevel.ERROR, "Tournament Request Exception ", e, e.getStackTrace().toString()); // e.printStackTrace(); } }
public void run() { try { synchronized (tournaments) { for (TournamentModel tm : tournaments.values()) { tm.Update(); } } } catch (Exception e) { trace( ExtensionLogLevel.ERROR, "Tournament Update Exception ", e, e.getStackTrace().toString()); } }