Package java.util.concurrent

Examples of java.util.concurrent.Semaphore


    private Semaphore lock;
    private String node;

    public NodeDeletionListener(ZooKeeperWatcher watcher, String node) {
      super(watcher);
      lock = new Semaphore(0);
      this.node = node;
    }
View Full Code Here


   */
  private static ServiceReference getBlueprintContainerRef(Bundle b) throws ServiceUnavailableException
  {
    ServiceReference result = findBPCRef(b);
    if (result == null) {
      Semaphore s = new Semaphore(0);
      AtomicReference<ServiceReference> bpcRef = new AtomicReference<ServiceReference>();
      ServiceTracker st = new ServiceTracker (b.getBundleContext(), BlueprintContainer.class.getName(),
          new BlueprintContainerServiceTrackerCustomizer (b, s, bpcRef));
      st.open();
     
      // Make another check for the BlueprintContainer service in case it came up just before our tracker engaged
      int graceperiod = getGracePeriod(b);
      result = findBPCRef(b);
      if (result == null && graceperiod >= 0) {
        if (graceperiod == 0) { // Wait for an unlimited period
          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

          FileChannelConfiguration.DEFAULT_CHECKPOINT_WRITE_TIMEOUT;
    }


    if(queueRemaining == null) {
      queueRemaining = new Semaphore(capacity, true);
    }
    if(log != null) {
      log.setCheckpointInterval(checkpointInterval);
      log.setMaxFileSize(maxFileSize);
    }
View Full Code Here

        Thread.currentThread().interrupt();
      }
    } else {
      synchronized(queueLock) {
        queue = new LinkedBlockingDeque<Event>(capacity);
        queueRemaining = new Semaphore(capacity);
        queueStored = new Semaphore(0);
      }
    }

    if (channelCounter == null) {
      channelCounter = new ChannelCounter(getName());
View Full Code Here

  @Override
  public void configure(Context context) {
    memoryChannel.configure(context);
    int capacity = context.getInteger(CAPACITY, DEFAULT_CAPACITY);
    if(queueRemaining == null) {
      queueRemaining = new Semaphore(capacity, true);
    } else if(capacity > this.capacity) {
      // capacity increase
      queueRemaining.release(capacity - this.capacity);
    } else if(capacity < this.capacity) {
      queueRemaining.acquireUninterruptibly(this.capacity - capacity);
View Full Code Here

        this.next = next;
        this.maxSize = maxSize;
        this.minSize = minSize;
        this.blockingTimeoutMilliseconds = blockingTimeoutMilliseconds;
        setIdleTimeoutMinutes(idleTimeoutMinutes);
        permits = new Semaphore(maxSize, true);
    }
View Full Code Here

            resizeLock.writeLock().lock();
            try {
                ResizeInfo resizeInfo = new ResizeInfo(this.minSize, permits.availablePermits(), connectionCount, newMaxSize);
                this.shrinkLater = resizeInfo.getShrinkLater();

                permits = new Semaphore(newMaxSize, true);
                //pre-acquire permits for the existing checked out connections that will not be closed when they are returned.
                for (int i = 0; i < resizeInfo.getTransferCheckedOut(); i++) {
                    permits.acquire();
                }
                //transfer connections we are going to keep
View Full Code Here

  }
  */

  private void leaveIOCriticalSection(String key) {
    synchronized (socketCreationMap) {
      Semaphore creationSemaphore = socketCreationMap.get(key);
      if ( sipStack.isLoggingEnabled()) {
              sipStack.getStackLogger().logDebug("leaveIOCriticalSection : " + key);
          }
      if (creationSemaphore != null) {
        creationSemaphore.release();
      }
    }
  }
View Full Code Here

  }
 

 
  private void enterIOCriticalSection(String key) throws IOException {
    Semaphore creationSemaphore = null;
    if ( sipStack.isLoggingEnabled()) {
        sipStack.getStackLogger().logDebug("enterIOCriticalSection : " + key);
    }
    synchronized (socketCreationMap) {
      creationSemaphore = socketCreationMap.get(key);
      if (creationSemaphore == null) {
        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

         * @param timeout
         *            wait period for the event
         */
        public void waitForEvent(long timeout) {
            Thread thread = Thread.currentThread();
            Semaphore semaphore = _semaphores.get(thread);
            if (semaphore == null) {
                semaphore = new Semaphore(1, true);
                semaphore.drainPermits();
                _semaphores.putIfAbsent(thread, semaphore);
            }
            semaphore = _semaphores.get(thread);
            try {
                semaphore.tryAcquire(timeout, TimeUnit.MILLISECONDS);
            } catch (InterruptedException exception) {
                logger.log(Level.FINER, "Exception ", exception);
            }
        }
View Full Code Here

TOP

Related Classes of java.util.concurrent.Semaphore

Copyright © 2018 www.massapicom. 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.