コード例 #1
0
  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);
  }
コード例 #2
0
 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
   }
 }
コード例 #3
0
  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!");
  }
コード例 #4
0
ファイル: PushServlet.java プロジェクト: Cognifide/CQ-Actions
  @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;
  }