synchronized IbisIdentifier getElectionResult(String election, long timeout) throws IOException { long deadline = System.currentTimeMillis() + timeout; if (timeout == 0) { deadline = Long.MAX_VALUE; } Election result = elections.get(election); while (result == null) { long timeRemaining = deadline - System.currentTimeMillis(); if (timeRemaining <= 0) { logger.debug("getElectionResullt deadline expired"); return null; } try { if (timeRemaining > 1000) { timeRemaining = 1000; } logger.debug("waiting " + timeRemaining + " for election"); wait(timeRemaining); logger.debug("DONE waiting " + timeRemaining + " for election"); } catch (final InterruptedException e) { // IGNORE } result = elections.get(election); } logger.debug("getElection result = " + result); return result.getWinner(); }
synchronized String[] wonElections(IbisIdentifier id) { ArrayList<String> result = new ArrayList<String>(); for (Election e : elections) { if (e.getWinner().equals(id)) { result.add(e.getName()); } } return result.toArray(new String[result.size()]); }