public Message send(Message query) { int q, r; Message best = null; byte rcode; for (q = 0; q < 20; q++) { boolean ok = false; for (r = 0; r < resolvers.length; r++) ok |= sendTo(query, r, q); if (!ok) break; Message m = null; synchronized (queue) { try { queue.wait((quantum + 1) * 1000); } catch (InterruptedException e) { System.out.println("interrupted"); } if (queue.size() == 0) continue; m = (Message) queue.firstElement(); queue.removeElementAt(0); Integer I = (Integer) queue.firstElement(); queue.removeElementAt(0); r = I.intValue(); } if (m == null) invalid[r] = true; else { rcode = m.getHeader().getRcode(); if (rcode == Rcode.NOERROR) return m; else { if (best == null) best = m; invalid[r] = true; } } } return best; }
private synchronized String getNextMessageFromQueue() throws InterruptedException { while (mMessageQueue.size() == 0) wait(); String message = (String) mMessageQueue.get(0); mMessageQueue.removeElementAt(0); return message; }
public synchronized void deleteClient(ClientInfo aClientInfo) { int clientIndex = mClients.indexOf(aClientInfo); if (clientIndex != -1) mClients.removeElementAt(clientIndex); }