Skip to content

Conversation

@UladzislauBlok
Copy link
Contributor

CoreUtils.scala is currently a blocker for migrating KafkaConfig.scala to the server-common module. This PR introduces a Java implementation of CoreUtils within server-common to facilitate the ongoing effort of decoupling the server modules.

Key Changes:

  • Rewrote the majority of utility methods from CoreUtils.scala into a new CoreUtils.java class, located in the org.apache.kafka.server.util package inside server-common module.
  • Moved SocketServerConfigs to the server-common module, as it is a required dependency for the migrated utility methods.
  • Note that lock-related methods were excluded from this migration as they were previously moved to LockUtils . see PR #19961. With the adjustments for read/write locks.

Architecture Note: I have moved SocketServerConfigs to server-common to resolve dependency issues. Currently, configuration classes are split between server and server-common. I'd like to clarify what is the strategic place to keep config related classes?

Migration Strategy: To keep the scope of this PR manageable and ensure a smoother review process, CoreUtils.scala has not been removed. This PR focuses on providing the new Java-based infrastructure. A subsequent PR will be submitted to replace existing call sites and perform the final cleanup of the Scala implementation.

@github-actions github-actions bot added triage PRs from the community streams core Kafka Broker tools connect mirror-maker-2 build Gradle build or GitHub Actions clients labels Jan 11, 2026
// see server-common.server.util
// see LockUtils#inLock(Lock lock, ThrowingSupplier<T, E> supplier)
// see LockUtils#inLock(Lock lock, ThrowingRunnable<E> runnable)
def inLock[T](lock: Lock)(fun: => T): T = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was already moved to LockUtils

  • see LockUtils#inLock(Lock lock, ThrowingSupplier<T, E> supplier)
  • see LockUtils#inLock(Lock lock, ThrowingRunnable runnable)

@UladzislauBlok UladzislauBlok changed the title KAFKA-15852: Move and rewrite CoreUtils to Java in server-common KAFKA-15853: Move and rewrite CoreUtils to Java in server-common Jan 11, 2026
@github-actions github-actions bot removed the triage PRs from the community label Jan 12, 2026
Copy link
Member

@mimaison mimaison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I think we may be able to get rid of CoreUtils altogether.

* 2. It is the most general possible utility, not just the thing you needed in one particular place
* 3. You have tests for it if it is nontrivial in any way
*/
public class CoreUtils {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class name does not make sense anymore, as it's not in the core module anymore.

* @param logging The logging instance to use for logging the thrown exception.
* @param logLevel The log level to use for logging.
*/
public static void swallow(Runnable action, Logger logging, Level logLevel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this method? Could we use Utils.closeQuietly() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about Utils.closeQuietly(). I can see that sometimes swallow is used with ERROR level, but we should rather update Utils.closeQuietly() to support other levels instead of add duplicated functionality here.

*
* @param files list of files to be deleted
*/
public static void delete(List<String> files) throws IOException {
Copy link
Member

@mimaison mimaison Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used by tests so we shouldn't have this in src/main. We could move it to TestUtils or even inline it as it's really short, it could even be a 1 liner if using the functional syntax forEach().

}
}

public static List<Endpoint> listenerListToEndPoints(List<String> listeners, Map<ListenerName, SecurityProtocol> securityProtocolMap) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the methods below are only used by KafkaConfig so they should probably be moved there.

* @param name The name to register this mbean with
* @return true if the registration succeeded
*/
public static boolean registerMBean(Object mbean, String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comments, but it seems all other methods could be deleted or moved elsewhere. That leaves us with only this method. It does not make sense to have a utility class for a single method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move it to Utils

@UladzislauBlok
Copy link
Contributor Author

@mimaison Hey. Thanks for the comments. I agree with you on the point that we can refactor method to use it inline (like delete) or move it to other classes like Utils for MBeans method. Let me do this and remove CoreUtils.scala in this MR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants