private ArquillianConfig getArquillianConfig(final String className, long timeout) { synchronized (deployedTests) { log.debugf("Getting Arquillian config for: %s", className); for (ArquillianConfig arqConfig : deployedTests) { for (String aux : arqConfig.getTestClasses()) { if (aux.equals(className)) { log.debugf("Found Arquillian config for: %s", className); return arqConfig; } } } if (timeout <= 0) { throw new IllegalStateException("Cannot obtain Arquillian config for: " + className); } try { log.debugf("Waiting on Arquillian config for: %s", className); deployedTests.wait(timeout); } catch (InterruptedException e) { // ignore } } return getArquillianConfig(className, -1); }
private void lockOnReportDir(File reportDir) { synchronized (files) { while (files.contains(reportDir)) try { files.wait(); } catch (InterruptedException ex) { logger.log(SEVERE, Thread.currentThread().getName() + " INTERRUPTED", ex); } files.add(reportDir); files.notifyAll(); // must own the lock } }
public void xxWaitForSignal() throws Exception { log.info(tid() + " XX_WAIT_FOR_SIGNAL (" + id + ")"); boolean posted = signals.contains(id); while (posted == false) { checkTestMarkedForExit(); log.info(tid() + " Signal not posted, waiting..."); synchronized (signals) { try { signals.wait(100); } catch (InterruptedException ignore) { } } posted = signals.contains(id); } log.info(tid() + " Got it!"); }
@Override public boolean sendMessage(String topic, String msg) { final String msgId; synchronized (this) { if (msg.contains("\n")) { throw new IllegalArgumentException("Message can't contain new line character"); } if (writer == null || writer.checkError()) { return false; } msgId = UUID.randomUUID().toString(); sentMessages.add(msgId); writer.println(msgId); writer.println(topic); writer.println(msg); writer.flush(); if (writer.checkError()) { sentMessages.remove(msgId); return false; } } LOG.debug("Waiting for confirmation for " + msgId); try { final long start = System.currentTimeMillis(); while (!receivedConfirmations.remove(msgId)) { final long elapsed = System.currentTimeMillis() - start; if (elapsed > TIMEOUT || connectionHold == null) { return false; } synchronized (receivedConfirmations) { receivedConfirmations.wait(TIMEOUT - elapsed); } } } catch (InterruptedException e) { return false; } finally { sentMessages.remove(msgId); } return true; }