Skip to content

Commit d76181e

Browse files
committed
Move capacity calculation to internal class
1 parent 20e0582 commit d76181e

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

log4j-kit/src/main/java/org/apache/logging/log4j/kit/recycler/RecyclerProperties.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.logging.log4j.kit.recycler;
1818

19+
import static org.apache.logging.log4j.kit.recycler.internal.CapacityUtil.DEFAULT_CAPACITY;
20+
1921
import org.apache.logging.log4j.kit.env.Log4jProperty;
2022
import org.apache.logging.log4j.status.StatusLogger;
2123
import org.jspecify.annotations.NullMarked;
@@ -31,23 +33,10 @@
3133
@Log4jProperty(name = "recycler")
3234
public record RecyclerProperties(@Nullable String factory, @Nullable Integer capacity) {
3335

34-
private static final int BITS_PER_INT = 32;
35-
36-
/**
37-
* The default recycler capacity: {@code max(2C, 8)}, {@code C} denoting the number of available processors,
38-
* rounded to the next power of 2.
39-
*/
40-
private static final int DEFAULT_CAPACITY =
41-
Math.max(ceilingNextPowerOfTwo(2 * Runtime.getRuntime().availableProcessors()), 8);
42-
4336
public RecyclerProperties {
4437
capacity = validateCapacity(capacity);
4538
}
4639

47-
public static int ceilingNextPowerOfTwo(final int x) {
48-
return 1 << (BITS_PER_INT - Integer.numberOfLeadingZeros(x - 1));
49-
}
50-
5140
private static Integer validateCapacity(final @Nullable Integer capacity) {
5241
if (capacity != null) {
5342
if (capacity >= 1) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.logging.log4j.kit.recycler.internal;
18+
19+
public class CapacityUtil {
20+
21+
private static final int BITS_PER_INT = 32;
22+
23+
private static int ceilingNextPowerOfTwo(final int x) {
24+
return 1 << (BITS_PER_INT - Integer.numberOfLeadingZeros(x - 1));
25+
}
26+
27+
/**
28+
* The default recycler capacity: {@code max(2C, 8)}, {@code C} denoting the number of available processors,
29+
* rounded to the next power of 2.
30+
*/
31+
public static final int DEFAULT_CAPACITY =
32+
Math.max(ceilingNextPowerOfTwo(2 * Runtime.getRuntime().availableProcessors()), 8);
33+
}

log4j-kit/src/test/java/org/apache/logging/log4j/kit/recycler/internal/RecyclerFactoryRegistryTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.kit.recycler.internal;
1818

19+
import static org.apache.logging.log4j.kit.recycler.internal.CapacityUtil.DEFAULT_CAPACITY;
1920
import static org.assertj.core.api.Assertions.assertThat;
2021

2122
import org.apache.logging.log4j.kit.recycler.RecyclerFactory;
@@ -28,9 +29,6 @@
2829

2930
public class RecyclerFactoryRegistryTest {
3031

31-
private static final int DEFAULT_CAPACITY =
32-
Math.max(2 * Runtime.getRuntime().availableProcessors() + 1, 8);
33-
3432
@Test
3533
void DummyRecyclerFactory_should_work() {
3634
final RecyclerFactory factory = RecyclerFactoryTestUtil.createForEnvironment("dummy", null);

0 commit comments

Comments
 (0)