Skip to content

Commit

Permalink
Code clean-up - formatting. No functional change
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed May 10, 2024
1 parent 041ac35 commit ada0a5e
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 307 deletions.
21 changes: 10 additions & 11 deletions java/org/apache/catalina/tribes/io/BufferPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
public class BufferPool {
private static final Log log = LogFactory.getLog(BufferPool.class);

public static final int DEFAULT_POOL_SIZE =
Integer.getInteger("org.apache.catalina.tribes.io.BufferPool.DEFAULT_POOL_SIZE", 100*1024*1024).intValue(); //100 MiB
public static final int DEFAULT_POOL_SIZE = Integer
.getInteger("org.apache.catalina.tribes.io.BufferPool.DEFAULT_POOL_SIZE", 100 * 1024 * 1024).intValue(); // 100
// MiB

protected static final StringManager sm = StringManager.getManager(BufferPool.class);

Expand All @@ -40,8 +41,7 @@ public static BufferPool getBufferPool() {
if (instance == null) {
BufferPool pool = new BufferPool();
pool.setMaxSize(DEFAULT_POOL_SIZE);
log.info(sm.getString("bufferPool.created",
Integer.toString(DEFAULT_POOL_SIZE),
log.info(sm.getString("bufferPool.created", Integer.toString(DEFAULT_POOL_SIZE),
pool.getClass().getName()));
instance = pool;
}
Expand All @@ -55,12 +55,12 @@ private BufferPool() {

public XByteBuffer getBuffer(int minSize, boolean discard) {
XByteBuffer buffer = queue.poll();
if ( buffer != null ) {
if (buffer != null) {
size.addAndGet(-buffer.getCapacity());
}
if ( buffer == null ) {
buffer = new XByteBuffer(minSize,discard);
} else if ( buffer.getCapacity() <= minSize ) {
if (buffer == null) {
buffer = new XByteBuffer(minSize, discard);
} else if (buffer.getCapacity() <= minSize) {
buffer.expand(minSize);
}
buffer.setDiscard(discard);
Expand All @@ -69,7 +69,7 @@ public XByteBuffer getBuffer(int minSize, boolean discard) {
}

public void returnBuffer(XByteBuffer buffer) {
if ( (size.get() + buffer.getCapacity()) <= maxSize ) {
if ((size.get() + buffer.getCapacity()) <= maxSize) {
size.addAndGet(buffer.getCapacity());
queue.offer(buffer);
}
Expand All @@ -82,8 +82,7 @@ public void clear() {

protected int maxSize;
protected final AtomicInteger size = new AtomicInteger(0);
protected final ConcurrentLinkedQueue<XByteBuffer> queue =
new ConcurrentLinkedQueue<>();
protected final ConcurrentLinkedQueue<XByteBuffer> queue = new ConcurrentLinkedQueue<>();

public void setMaxSize(int bytes) {
this.maxSize = bytes;
Expand Down
Loading

0 comments on commit ada0a5e

Please sign in to comment.