Browse Source

KAFKA-10403: Replace Scala collection by Java collection in Log4jController (#9182)

This removes the need to have the Scala library in the classpath
when deserializing the MBean.

Reviewers: Ismael Juma <ismael@juma.me.uk>
pull/9222/head
Chia-Ping Tsai 4 years ago committed by GitHub
parent
commit
4ea709dc45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      core/src/main/scala/kafka/utils/Log4jController.scala
  2. 8
      core/src/test/scala/kafka/utils/LoggingTest.scala

5
core/src/main/scala/kafka/utils/Log4jController.scala

@ -87,9 +87,10 @@ object Log4jController { @@ -87,9 +87,10 @@ object Log4jController {
class Log4jController extends Log4jControllerMBean {
def getLoggers: util.List[String] = {
Log4jController.loggers.map {
// we replace scala collection by java collection so mbean client is able to deserialize it without scala library.
new util.ArrayList[String](Log4jController.loggers.map {
case (logger, level) => s"$logger=$level"
}.toList.asJava
}.toSeq.asJava)
}

8
core/src/test/scala/kafka/utils/LoggingTest.scala

@ -26,6 +26,14 @@ import org.junit.Assert.{assertEquals, assertTrue} @@ -26,6 +26,14 @@ import org.junit.Assert.{assertEquals, assertTrue}
class LoggingTest extends Logging {
@Test
def testTypeOfGetLoggers(): Unit = {
val log4jController = new Log4jController
// the return object of getLoggers must be a collection instance from java standard library.
// That enables mbean client to deserialize it without extra libraries.
assertEquals(classOf[java.util.ArrayList[String]], log4jController.getLoggers.getClass)
}
@Test
def testLog4jControllerIsRegistered(): Unit = {
val mbs = ManagementFactory.getPlatformMBeanServer()

Loading…
Cancel
Save