Search in sources :

Example 11 with WriteLock

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

the class RWLock method runWriteOperation.

public void runWriteOperation(Runnable r) {
    WriteLock wl = _lock.writeLock();
    wl.lock();
    try {
        r.run();
    } finally {
        wl.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Example 12 with WriteLock

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

the class RWLock method runWriteOperation.

public <T> T runWriteOperation(Callable<T> call) throws Exception {
    WriteLock wl = _lock.writeLock();
    wl.lock();
    try {
        return call.call();
    } finally {
        wl.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Example 13 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)

Example 14 with WriteLock

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

the class AbstractExpandingTableModel method addNode.

protected void addNode(final E object) {
    WriteLock writeLock = rwl.writeLock();
    writeLock.lock();
    try {
        objects.put(object, new ExpandingTableNode<>(object));
        keys.add(object);
        buildVisibleModel();
        fireTableDataChanged();
    } finally {
        writeLock.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Example 15 with WriteLock

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

the class AbstractExpandingTableModel method buildVisibleModel.

private synchronized void buildVisibleModel(final E root) {
    WriteLock writeLock = rwl.writeLock();
    writeLock.lock();
    try {
        List<ExpandingTableNode<E>> model = new ArrayList<>();
        for (E child : getChildren(root)) {
            loadVisibleModel(child, model);
        }
        visibleObjects = model;
    } finally {
        writeLock.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList)

Aggregations

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