This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git


The following commit(s) were added to refs/heads/main by this push:
     new 9cab31bf55 make Java sample more modern by using sealed and record 
(#2493)
9cab31bf55 is described below

commit 9cab31bf55e38607ba4c9850534f302fe869d808
Author: PJ Fanning <[email protected]>
AuthorDate: Fri Nov 14 11:54:17 2025 +0100

    make Java sample more modern by using sealed and record (#2493)
    
    * make Java sample more modern by using sealed and record
    
    * Update OnMessageIntroTest.java
---
 .../org/apache/pekko/typed/OnMessageIntroTest.java | 72 +++++-----------------
 1 file changed, 14 insertions(+), 58 deletions(-)

diff --git 
a/actor-typed-tests/src/test/java/jdocs/org/apache/pekko/typed/OnMessageIntroTest.java
 
b/actor-typed-tests/src/test/java/jdocs/org/apache/pekko/typed/OnMessageIntroTest.java
index 283bca4965..5b5dee1368 100644
--- 
a/actor-typed-tests/src/test/java/jdocs/org/apache/pekko/typed/OnMessageIntroTest.java
+++ 
b/actor-typed-tests/src/test/java/jdocs/org/apache/pekko/typed/OnMessageIntroTest.java
@@ -39,76 +39,32 @@ public interface OnMessageIntroTest {
   public class ChatRoom {
     // #chatroom-behavior
     // #chatroom-protocol
-    static interface RoomCommand {}
+    static sealed interface RoomCommand permits GetSession, 
PublishSessionMessage {}
 
-    public static final class GetSession implements RoomCommand {
-      public final String screenName;
-      public final ActorRef<SessionEvent> replyTo;
-
-      public GetSession(String screenName, ActorRef<SessionEvent> replyTo) {
-        this.screenName = screenName;
-        this.replyTo = replyTo;
-      }
-    }
+    public static final record GetSession(String screenName, 
ActorRef<SessionEvent> replyTo)
+        implements RoomCommand {}
 
     // #chatroom-protocol
-    private static final class PublishSessionMessage implements RoomCommand {
-      public final String screenName;
-      public final String message;
-
-      public PublishSessionMessage(String screenName, String message) {
-        this.screenName = screenName;
-        this.message = message;
-      }
-    }
+    private static final record PublishSessionMessage(String screenName, 
String message)
+        implements RoomCommand {}
 
     // #chatroom-protocol
 
-    static interface SessionEvent {}
-
-    public static final class SessionGranted implements SessionEvent {
-      public final ActorRef<PostMessage> handle;
-
-      public SessionGranted(ActorRef<PostMessage> handle) {
-        this.handle = handle;
-      }
-    }
-
-    public static final class SessionDenied implements SessionEvent {
-      public final String reason;
-
-      public SessionDenied(String reason) {
-        this.reason = reason;
-      }
-    }
-
-    public static final class MessagePosted implements SessionEvent {
-      public final String screenName;
-      public final String message;
+    static sealed interface SessionEvent permits SessionGranted, 
SessionDenied, MessagePosted {}
 
-      public MessagePosted(String screenName, String message) {
-        this.screenName = screenName;
-        this.message = message;
-      }
-    }
+    public static final record SessionGranted(ActorRef<PostMessage> handle)
+        implements SessionEvent {}
 
-    static interface SessionCommand {}
+    public static final record SessionDenied(String reason) implements 
SessionEvent {}
 
-    public static final class PostMessage implements SessionCommand {
-      public final String message;
+    public static final record MessagePosted(String screenName, String message)
+        implements SessionEvent {}
 
-      public PostMessage(String message) {
-        this.message = message;
-      }
-    }
+    static sealed interface SessionCommand permits PostMessage, NotifyClient {}
 
-    private static final class NotifyClient implements SessionCommand {
-      final MessagePosted message;
+    public static final record PostMessage(String message) implements 
SessionCommand {}
 
-      NotifyClient(MessagePosted message) {
-        this.message = message;
-      }
-    }
+    private static final record NotifyClient(MessagePosted message) implements 
SessionCommand {}
 
     // #chatroom-protocol
     // #chatroom-behavior


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to