Search in sources :

Example 6 with WriteLock

use of java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock in project jgnash by ccavanaugh.

the class AbstractExpandingTableModel method toggleExpansion.

public void toggleExpansion(final E object) {
    WriteLock writeLock = rwl.writeLock();
    writeLock.lock();
    try {
        if (isParent(object)) {
            ExpandingTableNode<E> node = getNode(object);
            node.setExpanded(!node.isExpanded());
            preferences.put(EXPANSION_STATE, getExpansionState());
            fireNodeChanged();
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Example 7 with WriteLock

use of java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock in project jgnash by ccavanaugh.

the class AbstractExpandingTableModel method clear.

protected void clear() {
    WriteLock writeLock = rwl.writeLock();
    writeLock.lock();
    try {
        visibleObjects.clear();
        objects.clear();
        keys.clear();
    } finally {
        writeLock.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Example 8 with WriteLock

use of java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock in project jgnash by ccavanaugh.

the class AbstractExpandingTableModel method loadModel.

private void loadModel() {
    WriteLock writeLock = rwl.writeLock();
    writeLock.lock();
    try {
        keys.clear();
        objects.clear();
        visibleObjects.clear();
        for (E object : getModelObjects()) {
            objects.put(object, new ExpandingTableNode<>(object));
            keys.add(object);
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Example 9 with WriteLock

use of java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock in project zookeeper by apache.

the class ZKDatabase method addCommittedProposal.

/**
 * maintains a list of last <i>committedLog</i>
 *  or so committed requests. This is used for
 * fast follower synchronization.
 * @param request committed request
 */
public void addCommittedProposal(Request request) {
    WriteLock wl = logLock.writeLock();
    try {
        wl.lock();
        if (committedLog.size() > commitLogCount) {
            committedLog.removeFirst();
            minCommittedLog = committedLog.getFirst().packet.getZxid();
        }
        if (committedLog.isEmpty()) {
            minCommittedLog = request.zxid;
            maxCommittedLog = request.zxid;
        }
        byte[] data = SerializeUtils.serializeRequest(request);
        QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid, data, null);
        Proposal p = new Proposal();
        p.packet = pp;
        p.request = request;
        committedLog.add(p);
        maxCommittedLog = p.packet.getZxid();
    } finally {
        wl.unlock();
    }
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) QuorumPacket(org.apache.zookeeper.server.quorum.QuorumPacket) Proposal(org.apache.zookeeper.server.quorum.Leader.Proposal)

Example 10 with WriteLock

use of java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock in project jgnash by ccavanaugh.

the class AbstractExpandingTableModel method loadVisibleModel.

private void loadVisibleModel(final E object, final List<ExpandingTableNode<E>> model) {
    WriteLock writeLock = rwl.writeLock();
    writeLock.lock();
    try {
        if (isVisible(object)) {
            ExpandingTableNode<E> node = getNode(object);
            // protect against a null node if the model does not contain a requested visible object
            if (node != null) {
                model.add(node);
            }
            if (isParent(object)) {
                for (E child : getChildren(object)) {
                    loadVisibleModel(child, model);
                }
            }
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Aggregations

WriteLock (java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock)16 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)15 ArrayList (java.util.ArrayList)2 File (java.io.File)1 IOException (java.io.IOException)1 Proposal (org.apache.zookeeper.server.quorum.Leader.Proposal)1 QuorumPacket (org.apache.zookeeper.server.quorum.QuorumPacket)1