Package java.util.concurrent.locks.ReentrantReadWriteLock

Examples of java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock


        String currentMessage = currentMessageCache.get(topic);
        return currentMessage;
    }

    public void readLockUnlockConsumers(boolean lock) {
        ReadLock readlock = consumerListLock.readLock();
        lockUnlock(readlock, lock);
    }
View Full Code Here


            writeLockUnlockSubscription(false);
        }
    }

    public void readLockUnlockSubscriptions(boolean lock) {
        ReadLock readlock = subscriptionLock.readLock();
        lockUnlock(readlock, lock);
    }
View Full Code Here

           
            /* we are sending the diff check if we have proposals in memory to be able to
             * send a diff to the
             */
            ReentrantReadWriteLock lock = leader.zk.getZKDatabase().getLogLock();
            ReadLock rl = lock.readLock();
            try {
                rl.lock();       
                final long maxCommittedLog = leader.zk.getZKDatabase().getmaxCommittedLog();
                final long minCommittedLog = leader.zk.getZKDatabase().getminCommittedLog();
                LinkedList<Proposal> proposals = leader.zk.getZKDatabase().getCommittedLog();
                if (proposals.size() != 0) {
                    if ((maxCommittedLog >= peerLastZxid)
                            && (minCommittedLog <= peerLastZxid)) {
                        packetToSend = Leader.DIFF;
                        zxidToSend = maxCommittedLog;
                        for (Proposal propose: proposals) {
                            if (propose.packet.getZxid() > peerLastZxid) {
                                queuePacket(propose.packet);
                                QuorumPacket qcommit = new QuorumPacket(Leader.COMMIT, propose.packet.getZxid(),
                                        null, null);
                                queuePacket(qcommit);
                            }
                        }
                    } else if (peerLastZxid > maxCommittedLog) {
                        packetToSend = Leader.TRUNC;
                        zxidToSend = maxCommittedLog;
                        updates = zxidToSend;
                    }
                } else {
                    // just let the state transfer happen
                }              
               
                leaderLastZxid = leader.startForwarding(this, updates);
                if (peerLastZxid == leaderLastZxid) {
                    // We are in sync so we'll do an empty diff
                    packetToSend = Leader.DIFF;
                    zxidToSend = leaderLastZxid;
                }
            } finally {
                rl.unlock();
            }

            QuorumPacket newLeaderQP = new QuorumPacket(Leader.NEWLEADER,
                    leaderLastZxid, null, null);
            oa.writeRecord(newLeaderQP, "packet");
View Full Code Here

        /**
         * {@inheritDoc}
         */
        @Override
        public int getNumIdle(final K key) {
            ReadLock readLock = readWriteLock.readLock();
            readLock.lock();
            try {
                return keyedPool.getNumIdle(key);
            } finally {
                readLock.unlock();
            }
        }
View Full Code Here

        /**
         * {@inheritDoc}
         */
        @Override
        public int getNumActive(final K key) {
            ReadLock readLock = readWriteLock.readLock();
            readLock.lock();
            try {
                return keyedPool.getNumActive(key);
            } finally {
                readLock.unlock();
            }
        }
View Full Code Here

        /**
         * {@inheritDoc}
         */
        @Override
        public int getNumIdle() {
            ReadLock readLock = readWriteLock.readLock();
            readLock.lock();
            try {
                return keyedPool.getNumIdle();
            } finally {
                readLock.unlock();
            }
        }
View Full Code Here

        /**
         * {@inheritDoc}
         */
        @Override
        public int getNumActive() {
            ReadLock readLock = readWriteLock.readLock();
            readLock.lock();
            try {
                return keyedPool.getNumActive();
            } finally {
                readLock.unlock();
            }
        }
View Full Code Here

        /**
         * {@inheritDoc}
         */
        @Override
        public int getNumIdle() {
            ReadLock readLock = readWriteLock.readLock();
            readLock.lock();
            try {
                return pool.getNumIdle();
            } finally {
                readLock.unlock();
            }
        }
View Full Code Here

        /**
         * {@inheritDoc}
         */
        @Override
        public int getNumActive() {
            ReadLock readLock = readWriteLock.readLock();
            readLock.lock();
            try {
                return pool.getNumActive();
            } finally {
                readLock.unlock();
            }
        }
View Full Code Here

        return logLock;
    }
   

    public synchronized LinkedList<Proposal> getCommittedLog() {
        ReadLock rl = logLock.readLock();
        // only make a copy if this thread isn't already holding a lock
        if(logLock.getReadHoldCount() <=0) {
            try {
                rl.lock();
                return new LinkedList<Proposal>(this.committedLog);
            } finally {
                rl.unlock();
            }
        }
        return this.committedLog;
    }     
View Full Code Here

TOP

Related Classes of java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock

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.