Package java.util.concurrent

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


        creationSemaphore = new Semaphore(1, true);
        socketCreationMap.put(key, creationSemaphore);
      }
    }
    try {
      boolean retval = creationSemaphore.tryAcquire(10, TimeUnit.SECONDS);
      if (!retval) {
        throw new IOException("Could not acquire IO Semaphore'" + key
            + "' after 10 seconds -- giving up ");
      }
    } catch (InterruptedException e) {
View Full Code Here


                Thread.sleep(500);
            }
        }

        // Wait until all updates return
        sem.tryAcquire(15, TimeUnit.SECONDS);
       
        // Verify that server is following and has the same epoch as the leader
        Assert.assertTrue("Not following", qu.getPeer(index).peer.follower != null);
        long epochF = (qu.getPeer(index).peer.getActiveServer().getZxid() >> 32L);
        long epochL = (leader.getEpoch() >> 32L);
View Full Code Here

                return null;
            }
        });

        // Wait for the thread to start
        assertTrue(signal.tryAcquire(5, TimeUnit.SECONDS));

        // Attempt to ensure that test thread is blocked waiting for an object
        Thread.sleep(500);

        pool.invalidateObject(Integer.valueOf(1), object2);
View Full Code Here

        Thread.sleep(500);

        pool.invalidateObject(Integer.valueOf(1), object2);

        assertTrue("Call to invalidateObject did not unblock pool waiters.",
                   signal.tryAcquire(2, TimeUnit.SECONDS));

        if (result.get() != null) {
            throw new AssertionError(result.get());
        }
    }
View Full Code Here

        Semaphore lock = e.getRole() == Role.Consumer ? e.getConsumerLock(true)
                : e.getProviderLock(true);
        try {
            dispatch(e);
            if (timeout > 0) {
                if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
                    throw new TimeoutException();
                }
            } else {
                lock.acquire();
            }
View Full Code Here

          try {
            s.acquire();
          } catch (InterruptedException ix) {}
        } else {
          try {
            s.tryAcquire(graceperiod, TimeUnit.MILLISECONDS);
          } catch (InterruptedException ix) {}
        }
      }
      result = bpcRef.get();
      st.close();
View Full Code Here

  public boolean tryAcquirePermitOnCascClientSemaphore(CascadedClient cascClient, int oti, ISCMPMessageCallback callback) {
    boolean permit = false;
    Semaphore cascClientSemaphore = cascClient.getCascClientSemaphore();
    try {
      LOGGER.trace("acquire permit callback=" + callback.getClass());
      permit = cascClientSemaphore.tryAcquire(oti, TimeUnit.MILLISECONDS);
    } catch (InterruptedException ex) {
      // thread interrupted during acquire a permit on semaphore
      callback.receive(ex);
      LOGGER.warn("thread interrupted during acquire a permit on semaphore service=" + cascClient.getServiceName() + " "
          + ex.toString());
View Full Code Here

                          stackLogger.logDebug("trying to acquiring semaphore for message " + message);
                        }
                        // we try to acquire here so that if the result if false because it is already acquired
                        // we acquire it in the thread to avoid blocking other messages with a different call id
                        // that could be processed in parallel
                        final boolean acquired = callIdSemaphore.tryAcquire(0, TimeUnit.SECONDS);                                               
                       
                        Thread messageDispatchTask = new Thread() {
                          @Override
                          public void run() {
                            // if it was not acquired above
View Full Code Here

  public boolean tryAcquirePermitOnCascClientSemaphore(CascadedClient cascClient, int oti, ISCMPMessageCallback callback) {
    boolean permit = false;
    Semaphore cascClientSemaphore = cascClient.getCascClientSemaphore();
    try {
      LOGGER.trace("acquire permit callback=" + callback.getClass());
      permit = cascClientSemaphore.tryAcquire(oti, TimeUnit.MILLISECONDS);
    } catch (InterruptedException ex) {
      // thread interrupted during acquire a permit on semaphore
      callback.receive(ex);
      LOGGER.warn("thread interrupted during acquire a permit on semaphore service=" + cascClient.getServiceName() + " "
          + ex.toString());
View Full Code Here

            try {
                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.");
                }
            }
            finally {
                tracker.close();
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.