apache / pekko

Build highly concurrent, distributed, and resilient message-driven applications using Java/Scala
https://pekko.apache.org/
Apache License 2.0
1.21k stars 148 forks source link

Doc: We can metion the Java 21's new switch statement. #979

Closed He-Pin closed 2 months ago

He-Pin commented 9 months ago

Motivation: When handle an actor's messages, in Scala ,we can use the pattern matching, but now with JDK 21, we can use the new fancy :

switch(msg) {
  case XEvent event -> handle(event);
  default _ -> unhandled(msg);

style, and which will leverage the typeSwitch and maybe better performance vs the if else.

duobei commented 9 months ago

When I execute sbt docs/paradoxBrowse, it raised a error:

[error] java.lang.RuntimeException: Error creating extended parser class: Could not determine whether class 'org.pegdown.ParserWithDirectives$$parboiled' has already been loaded
[error]     at org.parboiled.Parboiled.createParser(Parboiled.java:58)
[error]     at com.lightbend.paradox.markdown.Reader.<init>(Reader.scala:40)
[error]     at com.lightbend.paradox.sbt.ParadoxPlugin$.$anonfun$baseParadoxSettings$2(ParadoxPlugin.scala:83)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error]     at sbt.Execute.work(Execute.scala:292)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error]     at java.base/java.lang.Thread.run(Thread.java:833)
[error] Caused by: java.lang.RuntimeException: Could not determine whether class 'org.pegdown.ParserWithDirectives$$parboiled' has already been loaded
[error]     at org.parboiled.transform.AsmUtils.findLoadedClass(AsmUtils.java:217)
[error]     at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:35)
[error]     at org.parboiled.Parboiled.createParser(Parboiled.java:54)
[error]     at com.lightbend.paradox.markdown.Reader.<init>(Reader.scala:40)
[error]     at com.lightbend.paradox.sbt.ParadoxPlugin$.$anonfun$baseParadoxSettings$2(ParadoxPlugin.scala:83)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error]     at sbt.Execute.work(Execute.scala:292)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error]     at java.base/java.lang.Thread.run(Thread.java:833)
[error] Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) accessible: module java.base does not "opens java.lang" to unnamed module @57103ee8
[error]     at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
[error]     at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
[error]     at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
[error]     at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
[error]     at org.parboiled.transform.AsmUtils.findLoadedClass(AsmUtils.java:210)
[error]     at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:35)
[error]     at org.parboiled.Parboiled.createParser(Parboiled.java:54)
[error]     at com.lightbend.paradox.markdown.Reader.<init>(Reader.scala:40)
[error]     at com.lightbend.paradox.sbt.ParadoxPlugin$.$anonfun$baseParadoxSettings$2(ParadoxPlugin.scala:83)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error]     at sbt.Execute.work(Execute.scala:292)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error]     at java.base/java.lang.Thread.run(Thread.java:833)
[error] (docs / Compile / paradoxProcessor) Error creating extended parser class: Could not determine whether class 'org.pegdown.ParserWithDirectives$$parboiled' has already been loaded
pjfanning commented 9 months ago

sbt paradox commands are best with Java 11.

duobei commented 9 months ago

sbt paradox commands are best with Java 11.

But it can't work with Java 17.

He-Pin commented 9 months ago

@duobei Yes, in Java 17 , you need add opens, something like :

             --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
                            --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
                            --add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
                            --add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
                            --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
                            --add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
                            --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
                            --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
                            --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
                            --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
                            --add-opens java.base/java.lang=ALL-UNNAMED
                            --add-opens java.base/java.net=ALL-UNNAMED
                            --add-opens java.base/java.util=ALL-UNNAMED
                            --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED
                            --add-opens java.base/java.nio=ALL-UNNAMED
                            --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
                            --add-exports java.base/sun.net.www.protocol.https=ALL-UNNAMED
                            --add-exports java.base/sun.util.calendar=ALL-UNNAMED
                            --add-exports java.base/java.lang.reflect=ALL-UNNAMED
                            --add-opens java.base/sun.net.util=ALL-UNNAMED
                            --add-opens java.base/sun.nio.ch=ALL-UNNAMED
                            --add-opens java.base/java.math=ALL-UNNAMED
                            --add-opens java.base/sun.security.action=ALL-UNNAMED
                            --add-opens java.management/sun.management=ALL-UNNAMED
Roiocam commented 9 months ago

@duobei Yes, in Java 17 , you need add opens, something like :

I think we have a plugin PekkoDisciplinePlugin which can be filled in Scala or Java options, Can you try to produce a setting for JDk17? Thanks.

He-Pin commented 9 months ago

It's experimental in jdk 17?

pjfanning commented 2 months ago

https://github.com/apache/pekko/pull/1011 was merged