Examples of Waiter


Examples of net.jodah.concurrentunit.Waiter

    // Awaits should return immediately
    assertTrue(System.currentTimeMillis() - t < 500);
  }

  public void shouldHandleSequentialWaiters() throws Throwable {
    final Waiter waiter = new Waiter();
    for (int i = 0; i < 1; i++) {
      circuit.open();

      new Thread(new Runnable() {
        @Override
        public void run() {
          try {
            System.out.println("Waiting for circuit to be closed");
            circuit.await();
            System.out.println("Circuit closed");
            waiter.resume();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }).start();

      Thread.sleep(500);
      circuit.close();
      waiter.await(500);
    }
  }
View Full Code Here

Examples of net.jodah.concurrentunit.Waiter

  }

  public void shouldHandleConcurrentWaiters() throws Throwable {
    circuit.open();

    final Waiter waiter = new Waiter();
    waiter.expectResumes(3);
    for (int i = 0; i < 3; i++)
      new Thread(new Runnable() {
        @Override
        public void run() {
          try {
            System.out.println("Waiting for circuit to be closed");
            circuit.await();
            System.out.println("Circuit closed");
            waiter.resume();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }).start();

    Thread.sleep(1000);
    circuit.close();
    waiter.await(500);
  }
View Full Code Here

Examples of net.jodah.concurrentunit.Waiter

  }

  public void shouldInterruptWaiters() throws Throwable {
    circuit.open();

    final Waiter waiter = new Waiter();
    waiter.expectResumes(3);
    for (int i = 0; i < 3; i++)
      new Thread(new Runnable() {
        @Override
        public void run() {
          try {
            circuit.await();
          } catch (InterruptedException e) {
            waiter.resume();
          }
        }
      }).start();

    Thread.sleep(300);
    circuit.interruptWaiters();
    waiter.await(500);
  }
View Full Code Here

Examples of net.jodah.concurrentunit.Waiter

  }

  public void shouldNotBlockOpenWhenSyncAcquired() throws Throwable {
    circuit.open();

    final Waiter waiter = new Waiter();
    waiter.expectResume();
    new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          circuit.await();
          waiter.resume();
        } catch (InterruptedException e) {
        }
      }
    }).start();

    Thread.sleep(300);
    circuit.open();
    circuit.close();
    waiter.await(500);
  }
View Full Code Here

Examples of net.jodah.concurrentunit.Waiter

    doAnswer(failNTimes(4, retryableChannelShutdownSignal(), null, mockChannel(1).channelHandler)).when(
        mockChannel(1).delegate)
        .basicCancel("foo-tag");

    final Waiter waiter = new Waiter();
    waiter.expectResumes(2);
    for (int i = 0; i < 2; i++)
      runInThread(new Runnable() {
        public void run() {
          try {
            performInvocation();
            waiter.resume();
          } catch (Throwable t) {
            waiter.fail(t);
          }
        }
      });

    waiter.await(2000);

    // Even though both threads will fail twice, only one thread will perform recovery
    verifyCxnCreations(1);
    verifyChannelCreations(1, 3);
    verifyChannelCreations(2, 1);
View Full Code Here

Examples of org.apache.camel.example.cafe.stuff.Waiter

    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry jndi = new JndiRegistry();
        jndi.bind("drinkRouter", new DrinkRouter());
        jndi.bind("orderSplitter", new OrderSplitter());
        jndi.bind("barista", new Barista());
        jndi.bind("waiter", new Waiter());
        jndi.bind("aggregatorStrategy", new CafeAggregationStrategy());
        return jndi;
    }
View Full Code Here

Examples of org.apache.commons.pool2.Waiter

        // See if we end up with dead man walking
        SimpleTestThread<Waiter> t2 = new SimpleTestThread<Waiter>(waiterPool, "51");
        Thread thread2 = new Thread(t2);
        thread2.start()// Triggers clearOldest, killing all of the 0's and the 2 oldest 1's
        Thread.sleep(50); // Wait for clearOldest to kick off, but not long enough to reach the 1's
        Waiter waiter = waiterPool.borrowObject("1");
        Thread.sleep(200); // Wait for execution to happen
        waiterPool.returnObject("1", waiter)// Will throw IllegalStateException if dead
        waiterPool.close();
    }
View Full Code Here

Examples of org.apache.qpid.transport.util.Waiter

            }
            sender = new Disassembler(secureSender, settings.getMaxFrameSize());

            send(new ProtocolHeader(1, 0, 10));

            Waiter w = new Waiter(lock, timeout);
            while (w.hasTime() && state == OPENING && error == null)
            {
                w.await();
            }

            if (error != null)
            {
                ConnectionException t = error;
View Full Code Here

Examples of org.apache.qpid.transport.util.Waiter

    public Session createSession(Binary name, long expiry, boolean isNoReplay)
    {
        synchronized (lock)
        {
            Waiter w = new Waiter(lock, timeout);
            while (w.hasTime() && state != OPEN && error == null)
            {
                w.await();
            }

            if (state != OPEN)
            {
                throw new ConnectionException("Timed out waiting for connection to be ready. Current state is :" + state);
View Full Code Here

Examples of org.apache.qpid.transport.util.Waiter

            switch (state)
            {
            case OPEN:
                state = CLOSING;
                connectionClose(replyCode, replyText, _options);
                Waiter w = new Waiter(lock, timeout);
                while (w.hasTime() && state == CLOSING && error == null)
                {
                    w.await();
                }

                if (error != null)
                {
                    close(replyCode, replyText, _options);
                    throw new ConnectionException(error);
                }

                switch (state)
                {
                case CLOSING:
                    close(replyCode, replyText, _options);
                    throw new ConnectionException("close() timed out");
                case CLOSED:
                    break;
                default:
                    throw new IllegalStateException(String.valueOf(state));
                }
                break;
            case CLOSED:
                break;
            default:
                if (sender != null)
                {
                    sender.close();
                    w = new Waiter(lock, timeout);
                    while (w.hasTime() && sender != null && error == null)
                    {
                        w.await();
                    }

                    if (error != null)
                    {
                        throw new ConnectionException(error);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.