Package java.util.concurrent

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


      final String methodName, byte[] requestBytes, ApiProxy.ApiConfig apiConfig) {
    Semaphore semaphore = (Semaphore) environment.getAttributes().get(
        LocalEnvironment.API_CALL_SEMAPHORE);
    if (semaphore != null) {
      try {
        semaphore.acquire();
      } catch (InterruptedException ex) {
        throw new RuntimeException("Interrupted while waiting on semaphore:", ex);
      }
    }
    boolean offline = environment.getAttributes().get(IS_OFFLINE_REQUEST_KEY) != null;
View Full Code Here


        consumedUntil(topic, (numLedgers + 1) * 2L);
        // Wait until ledger ranges is updated.
        Thread.sleep(2000L);

        Semaphore latch = new Semaphore(1);
        latch.acquire();
        tpManager.readTopicPersistenceInfo(topic, new Callback<Versioned<LedgerRanges>>() {
            @Override
            public void operationFinished(Object ctx, Versioned<LedgerRanges> ranges) {
                if (null == ranges || ranges.getValue().getRangesList().size() > 1) {
                    failureException = new PubSubException.NoTopicPersistenceInfoException("Invalid persistence info found for topic " + topic.toStringUtf8());
View Full Code Here

            public void operationFailed(Object ctx, PubSubException exception) {
                failureException = exception;
                ((Semaphore)ctx).release();
            }
        }, latch);
        latch.acquire();
        latch.release();
        assertNull("Should not fail with exception.", failureException);
    }

    @Test(timeout=60000)
View Full Code Here

        return msgs;
    }

    protected void acquireTopic(ByteString topic) throws Exception {
        Semaphore latch = new Semaphore(1);
        latch.acquire();
        manager.acquiredTopic(topic, new Callback<Void>() {
            @Override
            public void operationFinished(Object ctx, Void resultOfOperation) {
                failureException = null;
                ((Semaphore)ctx).release();
View Full Code Here

            public void operationFailed(Object ctx, PubSubException exception) {
                failureException = exception;
                ((Semaphore)ctx).release();
            }
        }, latch);
        latch.acquire();
        latch.release();
        if (null != failureException) {
            throw failureException;
        }
    }
View Full Code Here

    protected void releaseTopic(final ByteString topic) throws Exception {
        manager.lostTopic(topic);
        // backward testing ledger ranges without start seq id
        if (removeStartSeqId) {
            Semaphore latch = new Semaphore(1);
            latch.acquire();
            tpManager.readTopicPersistenceInfo(topic, new Callback<Versioned<LedgerRanges>>() {
                @Override
                public void operationFinished(Object ctx, Versioned<LedgerRanges> ranges) {
                    if (null == ranges) {
                        failureException = new PubSubException.NoTopicPersistenceInfoException("No persistence info found for topic " + topic.toStringUtf8());
View Full Code Here

                public void operationFailed(Object ctx, PubSubException exception) {
                    failureException = exception;
                    ((Semaphore)ctx).release();
                }
            }, latch);
            latch.acquire();
            latch.release();
            if (null != failureException) {
                throw failureException;
            }
        }
View Full Code Here

        final Semaphore finished = new Semaphore(0);
        enqueue(new Runnable() {
            public void run() {
                ready.release();
                try {
                    finished.acquire();
                } catch (InterruptedException ie) {
                    __log.error("Thread interrupted.", ie);
                    throw new BpelEngineException("Thread interrupted.", ie);
                }
            }
View Full Code Here

                if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
                    throw new TimeoutException();
                }
            } else {
                thread.setName(original + " (waiting for exchange " + exchange.getId() + ")");
                lock.acquire();
            }
            e.setRole(e.getRole() == Role.Consumer ? Role.Provider : Role.Consumer);
        } catch (InterruptedException ex) {
            exchange.setError(ex);
            for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
View Full Code Here

  public <T> T perform(DispatchableAction<T> action) throws IllegalActionException, RemoteException{
    semaphores.putIfAbsent(action.getID(), new Semaphore(0));
    Semaphore semaphore = semaphores.get(action.getID());
    serializer.perform(action);
    try {
      semaphore.acquire();
    } catch (InterruptedException exception) {
      Thread.currentThread().interrupt();
    }
    ActionEvent<T> actionEvent = cast(action);
    return actionEvent.getResult();
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.