Skip to content

Commit

Permalink
Turn Server into a sealed interface
Browse files Browse the repository at this point in the history
Sealed interfaces are useful in switch exprs to enumerate possible values
so that it becomes a compile error to introduce a new server type
without implementing an appropriate arm for the switch block.
  • Loading branch information
fishface60 committed Dec 27, 2024
1 parent 56317fa commit 673b1a6
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public abstract class AbstractServer implements Server {
public abstract class AbstractServer {

private static final Logger log = LogManager.getLogger(AbstractServer.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package net.rptools.clientserver.simple.server;

/** A server implementation that never receives connections */
public class NilServer extends AbstractServer {
public final class NilServer extends AbstractServer implements Server {
@Override
public void start() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.io.IOException;

public interface Server extends AutoCloseable {
public sealed interface Server extends AutoCloseable permits NilServer, SocketServer, WebRTCServer {
void start() throws IOException;

void close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* @author drice
*/
public class SocketServer extends AbstractServer {
public final class SocketServer extends AbstractServer implements Server {

private static final Logger log = LogManager.getLogger(SocketServer.class);
private final int port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

public class WebRTCServer extends AbstractServer {
public final class WebRTCServer extends AbstractServer implements Server {
private static final Logger log = LogManager.getLogger(WebRTCServer.class);

public interface Listener {
Expand Down

0 comments on commit 673b1a6

Please sign in to comment.