babl-ws / babl

Low-latency WebSocket Server
https://babl.ws
Apache License 2.0
68 stars 22 forks source link

JDK 17 Support? #109

Open ccnlui opened 2 years ago

ccnlui commented 2 years ago

I'm exploring this library and it seems like I was not able to build the project with JDK 17 or JDK 11. I also had problems when I tried to import it as a library.

I'd really appreciate some pointers on how to build this project locally, and what I should look into in order to make it compatible with JDK 17.

2 problems I've encountered so far: problem 1: cannot build project with JDK 17 (or JDK 11)

error with JDK 17

$ ./gradlew --version
------------------------------------------------------------
Gradle 6.7.1
------------------------------------------------------------
Build time:   2020-11-16 17:09:24 UTC
Revision:     2972ff02f3210d2ceed2f1ea880f026acfbab5c0
Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          17.0.2 (Eclipse Adoptium 17.0.2+8)
OS:           Mac OS X 12.3.1 aarch64

$ ./gradlew build
> Task :generateCodecs
> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x3b811c26) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x3b811c26

error with JDK 11

$ ./gradlew --version
------------------------------------------------------------
Gradle 6.7.1
------------------------------------------------------------
Build time:   2020-11-16 17:09:24 UTC
Revision:     2972ff02f3210d2ceed2f1ea880f026acfbab5c0
Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.14.1 (Eclipse Adoptium 11.0.14.1+1)
OS:           Mac OS X 12.3.1 x86_64

> Task :checkLicenseMain FAILED
No matching header format found for build/generated-sources/java/sbe-schema.sbeir

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':checkLicenseMain'.
> License violations were found: build/generated-sources/java/com/aitusoftware/babl/codec/RemoveSessionFromTopicEncoder.java, ...

problem 2: cannot run project with JDK 17 when imported as library Sample broadcast server that broadcasts to every connected client 1 msg / second, which resulted in the following exception while running with JDK 17. But the same code works with JDK 11.

Program:

try (SessionContainers containers = BablServer.launch(config))
{
    containers.start();
    streamServer.broadcast.createTopic(42);
    final String TOPIC_ONE_MSG = "TOPIC_ONE";
    final UnsafeBuffer topicOneMsg = new UnsafeBuffer(TOPIC_ONE_MSG.getBytes(StandardCharsets.UTF_8));
    while (true)
    {
        streamServer.broadcast.sendToTopic(42, ContentType.TEXT, topicOneMsg, 0, topicOneMsg.capacity());
        Thread.sleep(1);
    }
}

Exception:

Exception in thread "main" java.lang.InternalError: a fault occurred in a recent unsafe memory access operation in compiled Java code
        at com.aitusoftware.babl.websocket.FrameEncoder.<init>(FrameEncoder.java:49)
        at com.aitusoftware.babl.websocket.FrameEncoder.<init>(FrameEncoder.java:94)
        at com.aitusoftware.babl.websocket.SessionFactory.get(SessionFactory.java:67)
        at com.aitusoftware.babl.websocket.SessionFactory.get(SessionFactory.java:32)
        at com.aitusoftware.babl.pool.ObjectPool.<init>(ObjectPool.java:43)
        at com.aitusoftware.babl.websocket.SessionContainer.<init>(SessionContainer.java:128)
        at com.aitusoftware.babl.websocket.BablServer.initialiseServerInstance(BablServer.java:252)
        at com.aitusoftware.babl.websocket.BablServer.launch(BablServer.java:140)
ccnlui commented 2 years ago

problem 2 is resolved if I use an intel machine with x86 arch

epickrram commented 2 years ago

Hi @ccnlui non-x86 architectures are not currently supported (see #53). There are some notes on that issue on moving forward with support for other platforms, but we have no plans to progress unless someone is willing to sponsor the development work.

For the build issues, the build script specifies default tasks:

https://github.com/babl-ws/babl/blob/master/build.gradle#L23

that should be run when you execute a build with no arguments. This works for me on JDK11.

The build error on JDK17 looks like an API compatibility issue with the javac compiler. You could try upgrading gradle to the latest version, and see if that solves your issue.

ccnlui commented 2 years ago

@epickrram Thank you for your suggestion.

I upgraded gradle to 7.4.2 to had to do some workarounds and I finally got gradle to compile and test: There's one test that is failing (failed on jdk11 as well):

DockerComposeIntegrationTest > shouldExposeMonitoringData() FAILED
    org.awaitility.core.ConditionTimeoutException at DockerComposeIntegrationTest.java:120

I do have docker-compose installed at /usr/local/bin/docker-compose. After some digging, I wonder if this is because the docker images specified in docker/docker-compose.yaml are not available?

I tried the following without running the test, and I was not able to bring up the containers:

$ cd docker/
$ docker-compose up
[+] Running 0/5
 ⠿ babl-health-monitor Error                                                                                                                                                                          0.7s
 ⠿ babl-server Error                                                                                                                                                                                  0.7s
 ⠿ babl-error-monitor Error                                                                                                                                                                           0.7s
 ⠿ babl-stats-monitor Error                                                                                                                                                                           0.7s
 ⠿ http_host Error                                                                                                                                                                                    0.7s
Error response from daemon: pull access denied for aitusoftware/babl-error-printer, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

I'd appreciate any feedback. Thank you.

list of workarounds for jdk 17: 1) remove plugin id 'net.minecrell.licenser' version '0.4.1' and task licenseFormat from build.gradle because it caused the following error:

An exception occurred applying plugin request [id: 'net.minecrell.licenser', version: '0.4.1']
> Failed to apply plugin 'net.minecrell.licenser'.
   > Could not set unknown property 'header' for extension 'base' of type org.gradle.api.plugins.internal.DefaultBasePluginExtension.

2) replace main with mainClass because it seemed like API changed

task generateCodecs(type: JavaExec) {
    mainClass.set('uk.co.real_logic.sbe.SbeTool')
    ...
}

3) Add jvm following jvm args to both application{} and test{} block

--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
epickrram commented 2 years ago

There is a script to build the docker images locally:

https://github.com/babl-ws/babl/blob/master/scripts/docker-build.sh

epickrram commented 2 years ago

@ccnlui I've updated the license plugin. Can you try again with JDK17?

ccnlui commented 2 years ago

@epickrram awesome! And thanks for the pointer. I can now build the project and pass the test after building docker images.

I still had to add following jvm args to pass tests: --add-opens=java.base/sun.nio.ch=ALL-UNNAMED

$ ./gradlew --version
------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------
Build time:   2022-03-31 15:25:29 UTC
Revision:     540473b8118064efcc264694cbcaa4b677f61041
Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.3 (Eclipse Adoptium 17.0.3+7)
OS:           Linux 5.13.0-41-generic amd64

$ ./gradlew
... some warnings...
BUILD SUCCESSFUL in 49s
28 actionable tasks: 24 executed, 4 up-to-date
epickrram commented 2 years ago

@ccnlui if you would like to submit a PR with the changes required to build on JDK17, I'd happily merge.

ccnlui commented 2 years ago

submitted a pull request https://github.com/babl-ws/babl/pull/121

It builds successfully on my desktop:

$ ./gradlew --version
------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------
Build time:   2022-03-31 15:25:29 UTC
Revision:     540473b8118064efcc264694cbcaa4b677f61041
Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.3 (Eclipse Adoptium 17.0.3+7)
OS:           Linux 5.15.0-46-generic amd64