Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Apache ZooKeeper 3.7.0 Server Source Code
Apache ZooKeeper is an open-source server which enables highly
reliable distributed coordination.
Apache ZooKeeper Server Source Code files are provided in the source packge (apache-zookeeper-3.7.0.tar.gz). You can download it at Apache ZooKeeper Website.
You can also browse Apache ZooKeeper Server Source Code below:
✍: FYIcenter.com
⏎ org/apache/zookeeper/util/CircularBlockingQueue.java
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.zookeeper.util; import java.util.ArrayDeque; import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A bounded blocking queue backed by an array. This queue orders elements FIFO * (first-in-first-out). The head of the queue is that element that has been on * the queue the longest time. The tail of the queue is that element that has * been on the queue the shortest time. New elements are inserted at the tail of * the queue, and the queue retrieval operations obtain elements at the head of * the queue. If the queue is full, the head of the queue (the oldest element) * will be removed to make room for the newest element. */ public class CircularBlockingQueue<E> implements BlockingQueue<E> { private static final Logger LOG = LoggerFactory.getLogger(CircularBlockingQueue.class); /** Main lock guarding all access */ private final ReentrantLock lock; /** Condition for waiting takes */ private final Condition notEmpty; /** The array-backed queue */ private final ArrayDeque<E> queue; private final int maxSize; private long droppedCount; public CircularBlockingQueue(int queueSize) { this.queue = new ArrayDeque<>(queueSize); this.maxSize = queueSize; this.lock = new ReentrantLock(); this.notEmpty = this.lock.newCondition(); this.droppedCount = 0L; } /** * This method differs from {@link BlockingQueue#offer(Object)} in that it * will remove the oldest queued element (the element at the front of the * queue) in order to make room for any new elements if the queue is full. * * @param e the element to add * @return true since it will make room for any new elements if required */ @Override public boolean offer(E e) { Objects.requireNonNull(e); final ReentrantLock lock = this.lock; lock.lock(); try { if (this.queue.size() == this.maxSize) { final E discard = this.queue.remove(); this.droppedCount++; LOG.debug("Queue is full. Discarding oldest element [count={}]: {}", this.droppedCount, discard); } this.queue.add(e); this.notEmpty.signal(); } finally { lock.unlock(); } return true; } @Override public E poll(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { while (this.queue.isEmpty()) { if (nanos <= 0) { return null; } nanos = this.notEmpty.awaitNanos(nanos); } return this.queue.poll(); } finally { lock.unlock(); } } @Override public E take() throws InterruptedException { final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { while (this.queue.isEmpty()) { this.notEmpty.await(); } return this.queue.poll(); } finally { lock.unlock(); } } @Override public boolean isEmpty() { final ReentrantLock lock = this.lock; lock.lock(); try { return this.queue.isEmpty(); } finally { lock.unlock(); } } @Override public int size() { final ReentrantLock lock = this.lock; lock.lock(); try { return this.queue.size(); } finally { lock.unlock(); } } /** * Returns the number of elements that were dropped from the queue because the * queue was full when a new element was offered. * * @return The number of elements dropped (lost) from the queue */ public long getDroppedCount() { return this.droppedCount; } /** * For testing purposes only. * * @return True if a thread is blocked waiting for a new element to be offered * to the queue */ boolean isConsumerThreadBlocked() { final ReentrantLock lock = this.lock; lock.lock(); try { return lock.getWaitQueueLength(this.notEmpty) > 0; } finally { lock.unlock(); } } @Override public int drainTo(Collection<? super E> c) { throw new UnsupportedOperationException(); } @Override public E poll() { throw new UnsupportedOperationException(); } @Override public E element() { throw new UnsupportedOperationException(); } @Override public E peek() { throw new UnsupportedOperationException(); } @Override public E remove() { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends E> arg0) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } @Override public boolean containsAll(Collection<?> arg0) { throw new UnsupportedOperationException(); } @Override public Iterator<E> iterator() { throw new UnsupportedOperationException(); } @Override public boolean removeAll(Collection<?> arg0) { throw new UnsupportedOperationException(); } @Override public boolean retainAll(Collection<?> arg0) { throw new UnsupportedOperationException(); } @Override public Object[] toArray() { throw new UnsupportedOperationException(); } @Override public <T> T[] toArray(T[] arg0) { throw new UnsupportedOperationException(); } @Override public boolean add(E e) { throw new UnsupportedOperationException(); } @Override public boolean contains(Object o) { throw new UnsupportedOperationException(); } @Override public int drainTo(Collection<? super E> c, int maxElements) { throw new UnsupportedOperationException(); } @Override public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { throw new UnsupportedOperationException(); } @Override public void put(E e) throws InterruptedException { throw new UnsupportedOperationException(); } @Override public int remainingCapacity() { throw new UnsupportedOperationException(); } @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); } }
⏎ org/apache/zookeeper/util/CircularBlockingQueue.java
Or download all of them as a single archive file:
File name: zookeeper-server-3.7.0-fyi.zip File size: 871011 bytes Release date: 2021-05-17 Download
⇒ Apache ZooKeeper 3.7.0 Jute Source Code
⇐ Download Apache ZooKeeper 3.7.0 Source Package
2022-11-16, 24659👍, 0💬
Popular Posts:
JDK 11 jdk.internal.vm.compiler .jmodis the JMOD file for JDK 11 Internal VM Compiler module. JDK 11...
commons-collections4-4.2 -sources.jaris the source JAR file for Apache Commons Collections 4.2, whic...
JDK 11 jdk.rmic.jmod is the JMOD file for JDK 11 RMI (Remote Method Invocation) Compiler Tool tool, ...
What Is poi-3.5.jar - Part 2? poi-3.5.jar is one of the JAR files for Apache POI 3.5, which provides...
How to download and install ojdbc7.jar for Oracle 12c R1? ojdbc8.jar for Oracle 12c R1 is a Java 7 a...