public String decodeUrl(final String path) throws Exception {
   ServerSocket serverSocket = new ServerSocket(0);
   final int port = serverSocket.getLocalPort();
   serverSocket.close();
   Server server = new Server(port);
   server.setStopAtShutdown(true);
   ServletContextHandler ctx = new ServletContextHandler(server, "/", true, false);
   ctx.addServlet(new ServletHolder(new DecodeServlet()), "/*");
   server.start();
   ThreadUtils.sleep(500);
   new Thread() {
     @Override
     public void run() {
       try {
         ThreadUtils.sleep(500);
         InputStream is = new URL("http://localhost:" + port + path).openStream();
       } catch (IOException e) {
         throw new RuntimeException(e);
       }
     }
   }.start();
   synchronized (this) {
     wait();
   }
   return this.decodedPath;
 }
Exemple #2
0
 synchronized void awaitConnTryFailed() throws Exception {
   for (; ; ) {
     if (connTryFailed) {
       break;
     }
     wait();
     if (panic) throw new Exception("aborted by panic in DB");
   }
 }
 private void block() {
   IN_RESTORE_LATCH.trigger();
   // this mimics what happens in the HDFS client code.
   // an interrupt on a waiting object leads to an infinite loop
   try {
     synchronized (this) {
       wait();
     }
   } catch (InterruptedException e) {
     while (!isClosed()) {
       try {
         synchronized (this) {
           wait();
         }
       } catch (InterruptedException ignored) {
       }
     }
   }
 }
    public synchronized boolean waitTillAborted(long time) {
      if (!isAborted()) {
        try {
          wait(time);
        } catch (InterruptedException e) {
          // swallow and return state of aborted
        }
      }

      return isAborted();
    }
 public synchronized void publish(LogRecord record) {
   if (!record.getMessage().startsWith("cnt")) {
     return;
   }
   boolean snd = Thread.currentThread().getName().equals("2nd");
   if (runSecond == snd) {
     notify();
     runSecond = !runSecond;
   }
   try {
     wait(500);
   } catch (InterruptedException ex) {
   }
 }
Exemple #6
0
  private void closeDoc(XInterface xDoc) {
    m_aLog.log(Protocol.TYPE_SCOPE_OPEN, "closeDoc() started ...");

    try {
      Random aRandom = new Random();
      int nRetry = 5;
      while (nRetry > 0) {
        try {
          XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xDoc);
          if (xClose != null) {
            xClose.close(false);
            m_aLog.log(Protocol.TYPE_OK, "closeDoc() = OK.");
            nRetry = 0;
          } else {
            m_aLog.log(
                Protocol.TYPE_ERROR, "closeDoc() = ERROR. Doc doesn't provide needed interface!");
          }
        } catch (com.sun.star.util.CloseVetoException exVeto) {
          m_aLog.log(Protocol.TYPE_WARNING, "got CloseVetoException on calling doc.close().");
          m_aLog.log(
              Protocol.TYPE_WARNING_INFO, "Please check the reason for that more in detail.");
          m_aLog.log(
              Protocol.TYPE_WARNING_INFO,
              "A message like \"Can not close while saving.\" was intended and doesn't show an error!");
          m_aLog.log(Protocol.TYPE_WARNING_INFO, exVeto.getMessage());
        }

        if (nRetry > 0) {
          --nRetry;
          long nWait = aRandom.nextInt(30000); // 30 sec.
          try {
            m_aLog.log(Protocol.TYPE_INFO, "sleep for " + nWait + " ms");
            synchronized (this) {
              wait(nWait);
            }
          } catch (Throwable ex) {
            m_aLog.log(Protocol.TYPE_WARNING, "got exception for wait() !?");
            m_aLog.log(Protocol.TYPE_WARNING_INFO, ex.getMessage());
          }
        }
      }
    } catch (Throwable ex) {
      m_aLog.log(ex);
    }

    m_aLog.log(Protocol.TYPE_SCOPE_CLOSE, "closeDoc() finished.");
  }
Exemple #7
0
    synchronized void awaitNewmaster(Environment site, long deadline) throws Exception {
      long now;

      for (; ; ) {
        ReplicationStats s = site.getReplicationStats(StatsConfig.DEFAULT);

        // am I the master?
        //
        if (s.getEnvId() == s.getMaster()) {
          break;
        }

        if ((now = System.currentTimeMillis()) >= deadline)
          throw new Exception("aborted by timeout");
        long waitTime = deadline - now;
        wait(waitTime);
        if (panic) throw new Exception("aborted by panic in DB");
      }
    }
  @Test
  public void testSendMeasurements() throws Exception {
    System.out.println();

    writer = new AsciiDataWriter();
    writer.setDataEncoding(new TextEncodingImpl(",", "\n"));
    writer.setOutput(System.out);

    ISensorDataInterface locOutput = driver.getObservationOutputs().get("avlData");
    locOutput.registerListener(this);

    driver.start();

    synchronized (this) {
      while (sampleCount < 50) wait();
    }

    driver.stop();
  }
Exemple #9
0
  public void impl_checkConcurrentAutoSaveToNormalUISave() {
    Random aRandom = new Random();

    int i = 0;
    int c = 5;
    for (i = 0; i < c; ++i) {
      XInterface xDoc = createBigCalcDoc();
      try {
        long nWait = aRandom.nextInt(120000);
        m_aLog.log(Protocol.TYPE_INFO, "sleep for " + nWait + " ms");
        synchronized (this) {
          wait(nWait);
        }
      } catch (Throwable ex) {
        m_aLog.log(Protocol.TYPE_WARNING, "got exception for wait() !?");
        m_aLog.log(Protocol.TYPE_WARNING_INFO, ex.getMessage());
      }
      saveDoc(xDoc, utils.getOfficeTemp(m_xSMGR) + "/test_calc.ods");
      closeDoc(xDoc);
    }
  }
Exemple #10
0
 synchronized void await() throws Exception {
   while (!done) {
     wait();
   }
   if (panic) throw new Exception("aborted by panic in DB");
 }
Exemple #11
0
 synchronized void waitToSleep() throws Exception {
   while (!mSleeping) {
     wait();
   }
 }