Fix checkstyle in Kryo{IO,Input,Output}Pool 70/111670/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 May 2024 22:08:32 +0000 (00:08 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 8 May 2024 22:35:11 +0000 (00:35 +0200)
Reformat and make minor adjustments to keep everyone happy.

Change-Id: I32371650660080adfac970d9530abb04609de7f6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/utils/serializer/KryoIOPool.java
atomix-storage/src/main/java/io/atomix/utils/serializer/KryoInputPool.java
atomix-storage/src/main/java/io/atomix/utils/serializer/KryoOutputPool.java

index 6324631d6ccedc563f1c6015ca9ce436d85749b8..acd33e5194c53c6fdd3ee7aaeefac8519d5b9df5 100644 (file)
@@ -20,32 +20,31 @@ import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.function.Function;
 
 abstract class KryoIOPool<T> {
+    private final ConcurrentLinkedQueue<SoftReference<T>> queue = new ConcurrentLinkedQueue<>();
 
-  private final ConcurrentLinkedQueue<SoftReference<T>> queue = new ConcurrentLinkedQueue<>();
-
-  private T borrow(final int bufferSize) {
-    T element;
-    SoftReference<T> reference;
-    while ((reference = queue.poll()) != null) {
-      if ((element = reference.get()) != null) {
-        return element;
-      }
+    private T borrow(final int bufferSize) {
+        T element;
+        SoftReference<T> reference;
+        while ((reference = queue.poll()) != null) {
+            if ((element = reference.get()) != null) {
+                return element;
+            }
+        }
+        return create(bufferSize);
     }
-    return create(bufferSize);
-  }
 
-  protected abstract T create(final int bufferSize);
+    abstract T create(int bufferSize);
 
-  protected abstract boolean recycle(final T element);
+    abstract boolean recycle(T element);
 
-  <R> R run(final Function<T, R> function, final int bufferSize) {
-    final T element = borrow(bufferSize);
-    try {
-      return function.apply(element);
-    } finally {
-      if (recycle(element)) {
-        queue.offer(new SoftReference<>(element));
-      }
+    <R> R run(final Function<T, R> function, final int bufferSize) {
+        final T element = borrow(bufferSize);
+        try {
+            return function.apply(element);
+        } finally {
+            if (recycle(element)) {
+                queue.offer(new SoftReference<>(element));
+            }
+        }
     }
-  }
 }
index 0eeb8dfc89dbccc88427a1a054b55a942c1b57a0..4f5ac46f77f62c200c542ebdc4a823d94b293ac9 100644 (file)
@@ -17,21 +17,21 @@ package io.atomix.utils.serializer;
 
 import com.esotericsoftware.kryo.io.Input;
 
-class KryoInputPool extends KryoIOPool<Input> {
+final class KryoInputPool extends KryoIOPool<Input> {
+    static final int MAX_POOLED_BUFFER_SIZE = 512 * 1024;
 
-  static final int MAX_POOLED_BUFFER_SIZE = 512 * 1024;
-
-  @Override
-  protected Input create(int bufferSize) {
-    return new Input(bufferSize);
-  }
+    @Override
+    Input create(final int bufferSize) {
+        return new Input(bufferSize);
+    }
 
-  @Override
-  protected boolean recycle(Input input) {
-    if (input.getBuffer().length < MAX_POOLED_BUFFER_SIZE) {
-      input.setInputStream(null);
-      return true;
+    @Override
+    boolean recycle(final Input input) {
+        if (input.getBuffer().length >= MAX_POOLED_BUFFER_SIZE) {
+            // discard
+            return false;
+        }
+        input.setInputStream(null);
+        return true;
     }
-    return false; // discard
-  }
 }
index 6b1737fd12942e06c4fb90243a611a6a821a8bdd..e77316c932f4eec79944faf14e68a3372a6e1f48 100644 (file)
  */
 package io.atomix.utils.serializer;
 
-class KryoOutputPool extends KryoIOPool<ByteArrayOutput> {
+final class KryoOutputPool extends KryoIOPool<ByteArrayOutput> {
+    private static final int MAX_BUFFER_SIZE = 768 * 1024;
+    static final int MAX_POOLED_BUFFER_SIZE = 512 * 1024;
 
-  private static final int MAX_BUFFER_SIZE = 768 * 1024;
-  static final int MAX_POOLED_BUFFER_SIZE = 512 * 1024;
-
-  @Override
-  protected ByteArrayOutput create(int bufferSize) {
-    return new ByteArrayOutput(bufferSize, MAX_BUFFER_SIZE, new BufferAwareByteArrayOutputStream(bufferSize));
-  }
+    @Override
+    ByteArrayOutput create(final int bufferSize) {
+        return new ByteArrayOutput(bufferSize, MAX_BUFFER_SIZE, new BufferAwareByteArrayOutputStream(bufferSize));
+    }
 
-  @Override
-  protected boolean recycle(ByteArrayOutput output) {
-    if (output.getByteArrayOutputStream().getBufferSize() < MAX_POOLED_BUFFER_SIZE) {
-      output.getByteArrayOutputStream().reset();
-      output.clear();
-      return true;
+    @Override
+    boolean recycle(final ByteArrayOutput output) {
+        final var baos = output.getByteArrayOutputStream();
+        if (baos.getBufferSize() >= MAX_POOLED_BUFFER_SIZE) {
+            // discard
+            return false;
+        }
+        baos.reset();
+        output.clear();
+        return true;
     }
-    return false; // discard
-  }
 }