Package java.util.concurrent

Examples of java.util.concurrent.Semaphore.tryAcquire()


      }
    };
    final String type = "test";
    engine.addMessageListener(type, listener);
    engine.send(new TestMessage<String>(type, expectedBody));
    lock.tryAcquire(3, TimeUnit.SECONDS);
    assertEquals(expectedBody, actualBody.toString());
    engine.stop();
  }

  @Test(timeout = 1000)
View Full Code Here


    engine.addMessageListener(type, listener);
    final int totalMessages = 1000;
    for (int i = 0; i < totalMessages; i++) {
      engine.send(message);
    }
    lock.tryAcquire(totalMessages, 3, TimeUnit.SECONDS);
    assertEquals(totalMessages, counter.get());
    engine.stop();
  }

  @Test(timeout = 1000)
View Full Code Here

    engine.addMessageListener(type, listenerB);
    final int totalMessages = 1000;
    for (int i = 0; i < totalMessages; i++) {
      engine.send(message);
    }
    lock.tryAcquire(totalMessages * 2, 3, TimeUnit.SECONDS);
    assertEquals(totalMessages * 2, counter.get());
    engine.stop();
  }

  @Test
View Full Code Here

            for (int i = 0; i < configs.length; i++) {
                configs[i].delete();
            }

            if (!sem.tryAcquire(1, TimeUnit.SECONDS)) {
                throw new IOException("Not all instances were removed in time.");
            }
            tracker.close();
        }
    }
View Full Code Here

            for (int i = 0; i < configs.length; i++) {
                configs[i].delete();
            }

            if (!sem.tryAcquire(1, TimeUnit.SECONDS)) {
                throw new IOException("Not all instances were removed in time.");
            }
            tracker.close();
        }
    }
View Full Code Here

            };
            tracker.open();

            configs[0].delete();

            if (!sem.tryAcquire(1, TimeUnit.SECONDS)) {
                throw new IOException("Instance did not get removed in time.");
            }
        }
    }
View Full Code Here

            // there is no limit, always allow it
            permit.name = null;
            return permit;
        }

        boolean permitted = semaphore.tryAcquire();

        if (!permitted) {
            int deniedCount = getDeniedCount(name).incrementAndGet(); // don't worry about this not being atomic with aquire, no biggie
            long sleepBeforeRetry = getSleepBeforeRetryHint(deniedCount);
            throw new NotPermittedException(sleepBeforeRetry);
View Full Code Here

                sem.release();
            }
        }.start();

        // wait for the reading to be done
        sem.tryAcquire(5, TimeUnit.SECONDS);

        request = m_cachedRepository.getRequest(true);
        assert request[0].equals("checkout");

        // inspect the current contents of impl
View Full Code Here

     
      semaphore.release(numThreads);
     
      try
      {
         assertTrue("messages received within 15 seconds", semaphore.tryAcquire(numThreads, 15, TimeUnit.SECONDS));
        
         log.info("Messages received");
      }
      finally
      {
View Full Code Here

      }
      {
        // wait until jetty handler receives reply and captures session
        for ( int i = 1; i <= 12; i++ ) {
          log.debug( "Waiting for 5 sec (" + i + ")" );
          if ( semaphore.tryAcquire( 5, TimeUnit.SECONDS ) ) {
            Thread.sleep( 1000 );
            break;
          }
        }
      }
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.