Exemplo n.º 1
0
  public void testWhenFalse() throws InterruptedException {
    final WaitableBoolean blocker = new WaitableBoolean(true);
    final WaitableBoolean actionPerformed = new WaitableBoolean(false);

    Runnable switcher =
        new Runnable() {
          public void run() {
            try {
              Thread.sleep(500);
              blocker.set(false);
            } catch (InterruptedException iex) {
              // ignore
            }
          }
        };

    Runnable action =
        new Runnable() {
          public void run() {
            actionPerformed.set(true);
          }
        };

    new Thread(switcher).start();
    blocker.whenFalse(action);
    assertFalse(blocker.get());
    assertTrue(actionPerformed.get());
  }
Exemplo n.º 2
0
  public void testWhenFalseAlreadyFalse() throws InterruptedException {
    final WaitableBoolean blocker = new WaitableBoolean(false);
    final WaitableBoolean actionPerformed = new WaitableBoolean(false);

    Runnable action =
        new Runnable() {
          public void run() {
            actionPerformed.set(true);
          }
        };

    blocker.whenFalse(action);
    assertFalse(blocker.get());
    assertTrue(actionPerformed.get());
  }
Exemplo n.º 3
0
 /**
  * Called before an event is sent or dispatched to a service, it will block until resume() is
  * called. Users can override this method if they want to handle pausing differently e.g.
  * implement a store and forward policy
  *
  * @param event the current event being passed to the service
  * @throws InterruptedException if the thread is interrupted
  */
 protected void waitIfPaused(MuleEvent event) throws InterruptedException {
   if (logger.isDebugEnabled() && paused.get()) {
     logger.debug("Service: " + name + " is paused. Blocking call until resume is called");
   }
   paused.whenFalse(null);
 }