protected boolean fireBeforeLocationChangedFromUi(final String location) {
   final AtomicReference<Boolean> accept = new AtomicReference<Boolean>();
   synchronized (accept) {
     // notify Scout
     Runnable t =
         new Runnable() {
           @Override
           public void run() {
             synchronized (accept) {
               accept.set(
                   getScoutObject().getUIFacade().fireBeforeLocationChangedFromUI(location));
               accept.notifyAll();
             }
           }
         };
     getUiEnvironment().invokeScoutLater(t, 0);
     // end notify
     // wait at most 10 seconds
     try {
       accept.wait(10000L);
     } catch (InterruptedException e) {
       // nop
     }
   }
   return accept.get() != null ? accept.get().booleanValue() : false;
 }
Beispiel #2
0
  /**
   * Waits until this promise completes.
   *
   * @param time
   * @param timeUnits
   * @return
   * @throws InterruptedException
   */
  public HttpPromise<T> waitForComplete(long time, TimeUnit timeUnits) throws InterruptedException {
    long timeMillis = timeUnits.toMillis(time);
    long startTime = System.currentTimeMillis();

    synchronized (value) {
      while ((System.currentTimeMillis() - startTime) < timeMillis && !isComplete()) {
        value.wait(timeMillis - (System.currentTimeMillis() - startTime));
      }
    }

    return this;
  }
Beispiel #3
0
  /** Test of createTimer method, of class FleaseStage. */
  @Test
  public void testOpenAndGetLease() throws Exception {
    final ASCIIString CELL_ID = new ASCIIString("testcell");

    final AtomicReference<Flease> result = new AtomicReference();

    FleaseStage fs =
        new FleaseStage(
            cfg,
            "/tmp/xtreemfs-test/",
            new FleaseMessageSenderInterface() {

              @Override
              public void sendMessage(FleaseMessage message, InetSocketAddress recipient) {
                // ignore me
              }
            },
            true,
            new FleaseViewChangeListenerInterface() {

              @Override
              public void viewIdChangeEvent(ASCIIString cellId, int viewId) {}
            },
            new FleaseStatusListener() {

              @Override
              public void statusChanged(ASCIIString cellId, Flease lease) {
                // System.out.println("state change: "+cellId+" owner="+lease.getLeaseHolder());
                synchronized (result) {
                  result.set(
                      new Flease(
                          cellId,
                          lease.getLeaseHolder(),
                          lease.getLeaseTimeout_ms(),
                          lease.getMasterEpochNumber()));
                  result.notify();
                }
              }

              @Override
              public void leaseFailed(ASCIIString cellId, FleaseException error) {
                fail(error.toString());
              }
            },
            null);

    FleaseMessage msg = new FleaseMessage(FleaseMessage.MsgType.EVENT_RESTART);
    msg.setCellId(CELL_ID);

    fs.start();
    fs.waitForStartup();

    fs.openCell(CELL_ID, new ArrayList(), false);

    synchronized (result) {
      if (result.get() == null) result.wait(1000);
      if (result.get() == null) fail("timeout!");
    }

    assertEquals(result.get().getLeaseHolder(), cfg.getIdentity());

    FleaseFuture f = fs.closeCell(CELL_ID, false);
    f.get();

    Thread.sleep(12000);

    result.set(null);

    fs.openCell(CELL_ID, new ArrayList(), false);

    synchronized (result) {
      if (result.get() == null) result.wait(1000);
      if (result.get() == null) fail("timeout!");
    }

    assertEquals(result.get().getLeaseHolder(), cfg.getIdentity());

    fs.shutdown();
    fs.waitForShutdown();
  }