Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.Condition


            {
                if (shutdown)
                {
                    throw new InVMException("InVM Transport already shutdown") ;
                }
                final Condition condition = (lockstep > 0 ? lock.newCondition() : null) ;
                final InVMQueueEntry queueEntry = new InVMQueueEntry(value, condition) ;
                if (!entries.offer(queueEntry))
                {
                    throw new InVMException("Failed to append message to InVM queue") ;
                }
                if (numWaiters > 0)
                {
                    waitingCondition.signal() ;
                }
               
                if (condition != null)
                {
                    try
                    {
                        condition.await(lockstep, TimeUnit.MILLISECONDS) ;
                    }
                    catch (final InterruptedException ie)
                    {
                        LOGGER.warn("Waiting delivery thread interupted while waiting on message pickup on InVM queue '" + serviceId + "'.  Exiting pickup wait state.") ;
                    }
View Full Code Here


                }
                final InVMQueueEntry entry = entries.poll() ;
                if (entry != null)
                {
                    final Object result = entry.getValue() ;
                    final Condition condition = entry.getCondition() ;
                    if (condition != null)
                    {
                        condition.signal() ;
                    }
                    return result ;
                }
                return null ;
            }
View Full Code Here

        {
            lock.lock() ;
            try
            {
                numDeliveries-- ;
                final Condition condition = (lockstep > 0 ? lock.newCondition() : null) ;
                final InVMQueueEntry queueEntry = new InVMQueueEntry(this, value, condition, System.currentTimeMillis() + expiryTime) ;
                if (!entries.offer(queueEntry))
                {
                    throw new InVMException("Failed to append message to InVM queue") ;
                }
                if (numWaiters > 0)
                {
                    waitingCondition.signal() ;
                }
               
                if (condition != null)
                {
                    try
                    {
                        condition.await(lockstep, TimeUnit.MILLISECONDS) ;
                    }
                    catch (final InterruptedException ie)
                    {
                        LOGGER.warn("Waiting delivery thread interupted while waiting on message pickup on InVM queue '" + serviceId + "'.  Exiting pickup wait state.") ;
                    }
View Full Code Here

                }
                final InVMQueueEntry entry = entries.poll() ;
                if (entry != null)
                {
                    entry.setInactive() ;
                    final Condition condition = entry.getCondition() ;
                    if (condition != null)
                    {
                        condition.signal() ;
                    }
                    return entry ;
                }
                return null ;
            }
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();
                        onMemtableFlush(ctx);
                    }
                    catch (Exception e)
                    {
                        throw new RuntimeException(e);
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

        } catch (IllegalArgumentException iax) {
            // expected
        }

        Lock      lck = new ReentrantLock();
        Condition cnd = lck.newCondition();

        WaitingThread wt = new WaitingThread(cnd, null);
        assertEquals("wrong condition", cnd, wt.getCondition());
        assertNull  ("pool from nowhere", wt.getPool());
        assertNull  ("thread from nowhere", wt.getThread());
View Full Code Here


    public void testAwaitWakeup() throws InterruptedException {

        Lock      lck = new ReentrantLock();
        Condition cnd = lck.newCondition();
        WaitingThread wt = new WaitingThread(cnd, null);

        AwaitThread ath = new AwaitThread(wt, lck, null);
        ath.start();
        Thread.sleep(100); // give extra thread time to block
View Full Code Here


    public void testInterrupt() throws InterruptedException {

        Lock      lck = new ReentrantLock();
        Condition cnd = lck.newCondition();
        WaitingThread wt = new WaitingThread(cnd, null);

        AwaitThread ath = new AwaitThread(wt, lck, null);
        ath.start();
        Thread.sleep(100); // give extra thread time to block
View Full Code Here


    public void testIllegal() throws InterruptedException {

        Lock      lck = new ReentrantLock();
        Condition cnd = lck.newCondition();
        WaitingThread wt = new WaitingThread(cnd, null);

        try {
            lck.lock();
            wt.wakeup();
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.