Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.Condition


        //resubscribe
        durableSubscriber = clientSession.createDurableSubscriber(topic, getTestQueueName(),"testprop='TimeToLiveTest'", false);

        // Ensure we sleep the required amount of time.
        ReentrantLock waitLock = new ReentrantLock();
        Condition wait = waitLock.newCondition();
        final long MILLIS = 1000000L;

        long waitTime = TIME_TO_LIVE * MILLIS;
        while (waitTime > 0)
        {
            try
            {
                waitLock.lock();

                waitTime = wait.awaitNanos(waitTime);
            }
            catch (InterruptedException e)
            {
                //Stop if we are interrupted
                fail(e.getMessage());
View Full Code Here


            Assert.assertEquals("thread not waiting",
                         Thread.State.WAITING, gct.getState());

            // get access to the objects we need
            Lock      lck = mgr.extendedCPBR.getLock();
            Condition cnd = mgr.extendedCPBR.newestWT.getCondition();

            // Now trigger spurious wakeups. We'll do it several times
            // in a loop, just to be sure the connection manager has a
            // fair chance of misbehaving, and the gct to register it.

            for (int i=0; i<3; i++) {
                if (i > 0)
                    Thread.sleep(333); // don't go too fast

                try {
                    lck.lock();
                    cnd.signalAll(); // this is the spurious wakeup
                } finally {
                    lck.unlock();
                }

                // now give the waiting thread some time to register a wakeup
View Full Code Here

            }
            oldMemtable.freeze();

            final CommitLogSegment.CommitLogContext ctx = writeCommitLog ? CommitLog.instance().getContext() : null;
            logger_.info(columnFamily_ + " has reached its threshold; switching in a fresh Memtable at " + ctx);
            final Condition condition = submitFlush(oldMemtable);
            memtable_ = new Memtable(this);
            // a second executor that makes sure the onMemtableFlushes get called in the right order,
            // while keeping the wait-for-flush (future.get) out of anything latency-sensitive.
            return commitLogUpdater_.submit(new WrappedRunnable()
            {
                public void runMayThrow() throws InterruptedException, IOException
                {
                    condition.await();
                    if (writeCommitLog)
                    {
                        // if we're not writing to the commit log, we are replaying the log, so marking
                        // the log header with "you can discard anything written before the context" is not valid
                        CommitLog.instance().discardCompletedSegments(table_, columnFamily_, ctx);
View Full Code Here

     * (since, by definition, it started last).
     */
    Condition submitFlush(IFlushable flushable)
    {
        logger_.info("Enqueuing flush of " + flushable);
        final Condition condition = new SimpleCondition();
        flushable.flushAndSignal(condition, flushSorter_, flushWriter_);
        return condition;
    }
View Full Code Here

        workqueue = new AutomaticWorkQueueImpl(UNBOUNDED_MAX_QUEUE_SIZE, INITIAL_SIZE,
                                               UNBOUNDED_HIGH_WATER_MARK,
                                               UNBOUNDED_LOW_WATER_MARK,
                                               DEFAULT_DEQUEUE_TIMEOUT);
        final Lock runLock = new ReentrantLock();
        final Condition runCondition = runLock.newCondition();
        long start = System.currentTimeMillis();
        Runnable doNothing = new Runnable() {
            public void run() {
                runLock.lock();
                try {
                    runCondition.signal();
                } finally {
                    runLock.unlock();
                }
            }
        };
       
        workqueue.schedule(doNothing, 5000);
       
        runLock.lock();
        try {
            runCondition.await();
        } finally {
            runLock.unlock();
        }
       
        assertTrue("expected delay",
View Full Code Here

            {
                return null;
            }
            logger_.info(columnFamily_ + " has reached its threshold; switching in a fresh Memtable");
            oldMemtable.freeze();
            final Condition condition = submitFlush(oldMemtable);
            memtable_ = new Memtable(table_, columnFamily_);
            // a second executor that makes sure the onMemtableFlushes get called in the right order,
            // while keeping the wait-for-flush (future.get) out of anything latency-sensitive.
            return commitLogUpdater_.submit(new Runnable()
            {
                public void run()
                {
                    try
                    {
                        condition.await();
                        if (writeCommitLog)
                        {
                            // if we're not writing to the commit log, we are replaying the log, so marking
                            // the log header with "you can discard anything written before the context" is not valid
                            onMemtableFlush(ctx);
View Full Code Here

            // since they're a little complicated.  (We dont' want to move the remove back to switchMemtable, which is
            // the other sane option, since that could mean keeping a flushed memtable in the Historical set unnecessarily
            // while earlier flushes finish.)
            getMemtablesPendingFlushNotNull(columnFamily_).add((Memtable) flushable); // it's ok for the MT to briefly be both active and pendingFlush
        }
        final Condition condition = new SimpleCondition();
        flushSorter_.submit(new Runnable()
        {
            public void run()
            {
                final List sortedKeys = flushable.getSortedKeys();
                flushWriter_.submit(new Runnable()
                {
                    public void run()
                    {
                        try
                        {
                            addSSTable(flushable.writeSortedContents(sortedKeys));
                        }
                        catch (IOException e)
                        {
                            throw new RuntimeException(e);
                        }
                        if (flushable instanceof Memtable)
                        {
                            getMemtablesPendingFlushNotNull(columnFamily_).remove(flushable);
                        }
                        condition.signalAll();
                    }
                });
            }
        });
        return condition;
View Full Code Here

      if (debug) {
        this.logger.debug("detector on " + descriptor + " : on"); //$NON-NLS-1$ //$NON-NLS-2$
      }

      // Retrieve the detector condition
      Condition condition = this.detectors.get(descriptor);
      if (condition == null) {
        if (debug) {
          this.logger.debug("creates a new detector on " + descriptor); //$NON-NLS-1$
        }
        // Creates a new condition
        condition = this.locker.newCondition();
        this.detectors.put(descriptor, condition);
      }

      // Waits for the condition
      condition.await();

      if (debug) {
        this.logger.debug("detector on " + descriptor + " : off"); //$NON-NLS-1$ //$NON-NLS-2$
      }
      return true;
View Full Code Here

  void notifyDetection(MessageType descriptor)
  {
    // Set the re-entrance protection
    lock();
    try {
      Condition condition = this.detectors.get(descriptor);
      if (condition != null) {
        if (this.logger.isDebugEnabled()) {
          this.logger.debug("detector on " + descriptor + " : released"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        // Signal the
        condition.signalAll();
      }
    }
    finally {
      // Release the re-entrance protection
      unlock();
View Full Code Here

    // Set the re-entrance protection
    lock();
    try {
      // Unlock all conditions
      Condition condition;
      for (Entry<MessageType, Condition> detector : this.detectors.entrySet()) {
        condition = detector.getValue();
        if (this.locker.hasWaiters(condition)) {
          if (debug) {
            this.logger.debug("broke detector wait on " + detector.getKey()); //$NON-NLS-1$
          }
          condition.signalAll();
        }
      }

      // Clear the map
      this.detectors.clear();
View Full Code Here

TOP

Related Classes of java.util.concurrent.locks.Condition

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.