Java Code Examples for java.util.concurrent.atomic.AtomicReference#lazySet()
The following examples show how to use
java.util.concurrent.atomic.AtomicReference#lazySet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LongConcurrentLinkedHashMap.java From jane with GNU Lesser General Public License v3.0 | 6 votes |
/** Drains the read buffer up to an amortized threshold. */ // @GuardedBy("evictionLock") private void drainReadBuffer(int bufferIndex) { final long writeCount = readBufferWriteCount[bufferIndex].get(); for (int i = 0; i < ConcurrentLinkedHashMap.READ_BUFFER_DRAIN_THRESHOLD; i++) { final int index = (int) (readBufferReadCount[bufferIndex] & ConcurrentLinkedHashMap.READ_BUFFER_INDEX_MASK); final AtomicReference<Node<V>> slot = readBuffers[bufferIndex][index]; final Node<V> node = slot.get(); if (node == null) { break; } slot.lazySet(null); applyRead(node); readBufferReadCount[bufferIndex]++; } readBufferDrainAtWriteCount[bufferIndex].lazySet(writeCount); }
Example 2
Source File: ConcurrentLinkedHashMap.java From groovy with Apache License 2.0 | 6 votes |
/** Drains the read buffer up to an amortized threshold. */ @GuardedBy("evictionLock") void drainReadBuffer(int bufferIndex) { final long writeCount = readBufferWriteCount[bufferIndex].get(); for (int i = 0; i < READ_BUFFER_DRAIN_THRESHOLD; i++) { final int index = (int) (readBufferReadCount[bufferIndex] & READ_BUFFER_INDEX_MASK); final AtomicReference<Node<K, V>> slot = readBuffers[bufferIndex][index]; final Node<K, V> node = slot.get(); if (node == null) { break; } slot.lazySet(null); applyRead(node); readBufferReadCount[bufferIndex]++; } readBufferDrainAtWriteCount[bufferIndex].lazySet(writeCount); }
Example 3
Source File: JournalImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
private static ByteBuffer allocateDirectBufferIfNeeded(final SequentialFileFactory fileFactory, final int requiredCapacity, final AtomicReference<ByteBuffer> bufferRef) { ByteBuffer buffer = bufferRef != null ? bufferRef.get() : null; if (buffer != null && buffer.capacity() < requiredCapacity) { fileFactory.releaseDirectBuffer(buffer); buffer = null; } if (buffer == null) { buffer = fileFactory.allocateDirectBuffer(requiredCapacity); } else { buffer.clear().limit(requiredCapacity); } if (bufferRef != null) { bufferRef.lazySet(buffer); } return buffer; }
Example 4
Source File: JournalImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
private synchronized JournalLoadInformation load(final LoaderCallback loadManager, final boolean changeData, final JournalState replicationSync) throws Exception { final JournalState state = this.state; if (state == JournalState.STOPPED || state == JournalState.LOADED) { throw new IllegalStateException("Journal " + this + " must be in " + JournalState.STARTED + " state, was " + state); } if (state == replicationSync) { throw new IllegalStateException("Journal cannot be in state " + JournalState.STARTED); } // AtomicReference is used only as a reference, not as an Atomic value final AtomicReference<ByteBuffer> wholeFileBufferRef = new AtomicReference<>(); try { return load(loadManager, changeData, replicationSync, wholeFileBufferRef); } finally { final ByteBuffer wholeFileBuffer = wholeFileBufferRef.get(); if (wholeFileBuffer != null) { fileFactory.releaseDirectBuffer(wholeFileBuffer); wholeFileBufferRef.lazySet(null); } } }
Example 5
Source File: ConcurrentLinkedHashMap.java From concurrentlinkedhashmap with Apache License 2.0 | 6 votes |
/** Drains the read buffer up to an amortized threshold. */ @GuardedBy("evictionLock") void drainReadBuffer(int bufferIndex) { final long writeCount = readBufferWriteCount[bufferIndex].get(); for (int i = 0; i < READ_BUFFER_DRAIN_THRESHOLD; i++) { final int index = (int) (readBufferReadCount[bufferIndex] & READ_BUFFER_INDEX_MASK); final AtomicReference<Node<K, V>> slot = readBuffers[bufferIndex][index]; final Node<K, V> node = slot.get(); if (node == null) { break; } slot.lazySet(null); applyRead(node); readBufferReadCount[bufferIndex]++; } readBufferDrainAtWriteCount[bufferIndex].lazySet(writeCount); }
Example 6
Source File: ConcurrentLinkedHashMap.java From spring-boot-protocol with Apache License 2.0 | 6 votes |
/** Drains the read buffer up to an amortized threshold. */ // @GuardedBy("evictionLock") void drainReadBuffer(int bufferIndex) { final long writeCount = readBufferWriteCount[bufferIndex].get(); for (int i = 0; i < READ_BUFFER_DRAIN_THRESHOLD; i++) { final int index = (int) (readBufferReadCount[bufferIndex] & READ_BUFFER_INDEX_MASK); final AtomicReference<Node<K, V>> slot = readBuffers[bufferIndex][index]; final Node<K, V> node = slot.get(); if (node == null) { break; } slot.lazySet(null); applyRead(node); readBufferReadCount[bufferIndex]++; } readBufferDrainAtWriteCount[bufferIndex].lazySet(writeCount); }
Example 7
Source File: FastFlowBuffer.java From caffeine with Apache License 2.0 | 6 votes |
@Override public void drainTo(Consumer<E> consumer) { long head = readCounter; long tail = relaxedWriteCounter(); long size = (tail - head); if (size == 0) { return; } do { int index = (int) (head & BUFFER_MASK); AtomicReference<E> slot = buffer[index]; E e = slot.get(); if (e == null) { // not published yet break; } slot.lazySet(null); consumer.accept(e); head++; } while (head != tail); lazySetReadCounter(head); }
Example 8
Source File: ManyToOneBuffer.java From caffeine with Apache License 2.0 | 6 votes |
@Override public void drainTo(Consumer<E> consumer) { long head = readCounter; long tail = relaxedWriteCounter(); long size = (tail - head); if (size == 0) { return; } do { int index = (int) (head & BUFFER_MASK); AtomicReference<E> slot = buffer[index]; E e = slot.get(); if (e == null) { // not published yet break; } slot.lazySet(null); consumer.accept(e); head++; } while (head != tail); lazySetReadCounter(head); }
Example 9
Source File: ConcurrentLinkedHashMap.java From jane with GNU Lesser General Public License v3.0 | 6 votes |
/** Drains the read buffer up to an amortized threshold. */ // @GuardedBy("evictionLock") private void drainReadBuffer(int bufferIndex) { final long writeCount = readBufferWriteCount[bufferIndex].get(); for (int i = 0; i < READ_BUFFER_DRAIN_THRESHOLD; i++) { final int index = (int) (readBufferReadCount[bufferIndex] & READ_BUFFER_INDEX_MASK); final AtomicReference<Node<K, V>> slot = readBuffers[bufferIndex][index]; final Node<K, V> node = slot.get(); if (node == null) { break; } slot.lazySet(null); applyRead(node); readBufferReadCount[bufferIndex]++; } readBufferDrainAtWriteCount[bufferIndex].lazySet(writeCount); }
Example 10
Source File: ConcurrentLinkedHashMap.java From concurrentlinkedhashmap with Apache License 2.0 | 5 votes |
@Override public void clear() { evictionLock.lock(); try { // Discard all entries Node<K, V> node; while ((node = evictionDeque.poll()) != null) { data.remove(node.key, node); makeDead(node); } // Discard all pending reads for (AtomicReference<Node<K, V>>[] buffer : readBuffers) { for (AtomicReference<Node<K, V>> slot : buffer) { slot.lazySet(null); } } // Apply all pending writes Runnable task; while ((task = writeBuffer.poll()) != null) { task.run(); } } finally { evictionLock.unlock(); } }
Example 11
Source File: LongConcurrentLinkedHashMap.java From jane with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void clear() { evictionLock.lock(); try { // Discard all entries Node<V> node; while ((node = evictionDeque.poll()) != null) { data.remove(node.key, node); makeDead(node); } // Discard all pending reads for (AtomicReference<Node<V>>[] buffer : readBuffers) { for (AtomicReference<Node<V>> slot : buffer) { slot.lazySet(null); } } // Apply all pending writes Runnable task; while ((task = writeBuffer.poll()) != null) { task.run(); } } finally { evictionLock.unlock(); } }
Example 12
Source File: ConcurrentLinkedHashMap.java From jane with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void clear() { evictionLock.lock(); try { // Discard all entries Node<K, V> node; while ((node = evictionDeque.poll()) != null) { data.remove(node.key, node); makeDead(node); } // Discard all pending reads for (AtomicReference<Node<K, V>>[] buffer : readBuffers) { for (AtomicReference<Node<K, V>> slot : buffer) { slot.lazySet(null); } } // Apply all pending writes Runnable task; while ((task = writeBuffer.poll()) != null) { task.run(); } } finally { evictionLock.unlock(); } }
Example 13
Source File: AtomicReferenceTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * get returns the last value lazySet in same thread */ public void testGetLazySet() { AtomicReference ai = new AtomicReference(one); assertSame(one, ai.get()); ai.lazySet(two); assertSame(two, ai.get()); ai.lazySet(m3); assertSame(m3, ai.get()); }
Example 14
Source File: TicketBuffer.java From caffeine with Apache License 2.0 | 5 votes |
@Override public void drainTo(Consumer<E> consumer) { for (int i = 0; i < BUFFER_SIZE; i++) { final int index = (int) (readCounter & BUFFER_MASK); final AtomicReference<Object> slot = buffer[index]; if (slot.get() instanceof Turn) { break; } long next = readCounter + BUFFER_SIZE; slot.lazySet(new Turn(next)); readCounter++; } }
Example 15
Source File: ConcurrentLinkedHashMap.java From groovy with Apache License 2.0 | 5 votes |
@Override public void clear() { evictionLock.lock(); try { // Discard all entries Node<K, V> node; while ((node = evictionDeque.poll()) != null) { data.remove(node.key, node); makeDead(node); } // Discard all pending reads for (AtomicReference<Node<K, V>>[] buffer : readBuffers) { for (AtomicReference<Node<K, V>> slot : buffer) { slot.lazySet(null); } } // Apply all pending writes Runnable task; while ((task = writeBuffer.poll()) != null) { task.run(); } } finally { evictionLock.unlock(); } }
Example 16
Source File: AtomicReferenceTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * get returns the last value lazySet in same thread */ public void testGetLazySet() { AtomicReference ai = new AtomicReference(one); assertSame(one, ai.get()); ai.lazySet(two); assertSame(two, ai.get()); ai.lazySet(m3); assertSame(m3, ai.get()); }
Example 17
Source File: ConcurrentLinkedHashMap.java From spring-boot-protocol with Apache License 2.0 | 5 votes |
@Override public void clear() { evictionLock.lock(); try { // Discard all entries Node<K, V> node; while ((node = evictionDeque.poll()) != null) { data.remove(node.key, node); makeDead(node); } // Discard all pending reads for (AtomicReference<Node<K, V>>[] buffer : readBuffers) { for (AtomicReference<Node<K, V>> slot : buffer) { slot.lazySet(null); } } // Apply all pending writes Runnable task; while ((task = writeBuffer.poll()) != null) { task.run(); } } finally { evictionLock.unlock(); } }