Skip to content

Commit 9b22b56

Browse files
committed
Make Subscribers interfaces
1 parent 5eb67ad commit 9b22b56

14 files changed

+20
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ the `WebSocketClient` or `WebSocketManager` classes directly this shouldn't requ
4949

5050
The debug/error handler methods have been removed. Errors and debug messages are now exclusively logged using SLF4J
5151

52+
#### Subscribers
53+
The `Subscriber` classes are now interfaces and their methods have been renamed to make the more explicit and reduce
54+
the chance of conflicts with other overrides.
5255

5356
### Other
5457
- Arrays have been Replaced by Collection's in almost all places

src/main/java/com/exaroton/api/ws/WebSocketConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public CompletableFuture<Boolean> serverHasStatus(Set<ServerStatus> status) {
228228
return future.thenApply(s -> s.hasStatus(status));
229229
}
230230

231-
private <T extends Subscriber> void addStreamSubscriber(Class<? extends Stream<T>> c, T subscriber) {
231+
private <T> void addStreamSubscriber(Class<? extends Stream<T>> c, T subscriber) {
232232
if (!this.streams.containsKey(c)) {
233233
throw new IllegalStateException("There is no active stream for: " + c);
234234
}

src/main/java/com/exaroton/api/ws/stream/ConsoleStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected void onDataMessage(String type, JsonObject message) {
2828
case "line":
2929
String line = gson.fromJson(message, ConsoleStreamData.class).getData();
3030
for (ConsoleSubscriber subscriber : subscribers) {
31-
subscriber.line(line);
31+
subscriber.handleLine(line);
3232
}
3333
}
3434
}

src/main/java/com/exaroton/api/ws/stream/HeapStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected void onDataMessage(String type, JsonObject message) {
2222
HeapUsage usage = gson.fromJson(message, HeapStreamData.class).getData();
2323

2424
for (HeapSubscriber subscriber : subscribers) {
25-
subscriber.heap(usage);
25+
subscriber.handleHeapUsage(usage);
2626
}
2727
break;
2828
}

src/main/java/com/exaroton/api/ws/stream/ServerStatusStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected void onDataMessage(String type, JsonObject message) {
3232
ws.onStatusChange();
3333

3434
for (ServerStatusSubscriber subscriber : subscribers) {
35-
subscriber.statusUpdate(oldServer, this.server);
35+
subscriber.handleStatusUpdate(oldServer, this.server);
3636
}
3737
break;
3838
}

src/main/java/com/exaroton/api/ws/stream/StatsStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected void onDataMessage(String type, JsonObject message) {
2222
StatsData stats = gson.fromJson(message, StatsStreamData.class).getData();
2323

2424
for (StatsSubscriber subscriber : subscribers) {
25-
subscriber.stats(stats);
25+
subscriber.handleStats(stats);
2626
}
2727
break;
2828
}

src/main/java/com/exaroton/api/ws/stream/Stream.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.exaroton.api.server.ServerStatus;
44
import com.exaroton.api.ws.WebSocketConnection;
55
import com.exaroton.api.ws.data.StreamData;
6-
import com.exaroton.api.ws.subscriber.Subscriber;
76
import com.google.gson.Gson;
87
import com.google.gson.JsonObject;
98
import org.jetbrains.annotations.ApiStatus;
@@ -15,7 +14,7 @@
1514
import java.util.concurrent.CompletableFuture;
1615

1716
@ApiStatus.NonExtendable
18-
public abstract class Stream<T extends Subscriber> {
17+
public abstract class Stream<T> {
1918

2019
/**
2120
* Has this stream been started?

src/main/java/com/exaroton/api/ws/stream/TickStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected void onDataMessage(String type, JsonObject message) {
2222
TickData tick = gson.fromJson(message, TickStreamData.class).getData();
2323

2424
for (TickSubscriber subscriber : subscribers) {
25-
subscriber.tick(tick);
25+
subscriber.handleTickData(tick);
2626
}
2727
break;
2828
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.exaroton.api.ws.subscriber;
22

3-
public abstract class ConsoleSubscriber extends Subscriber {
4-
3+
public interface ConsoleSubscriber {
54
/**
65
* handle new console line
76
* @param line new console line
87
*/
9-
public abstract void line(String line);
8+
void handleLine(String line);
109
}

src/main/java/com/exaroton/api/ws/subscriber/HeapSubscriber.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import com.exaroton.api.ws.data.HeapUsage;
44

5-
public abstract class HeapSubscriber extends Subscriber {
5+
public interface HeapSubscriber {
66

77
/**
88
* handle new heap data
99
* @param heap heap data
1010
*/
11-
public abstract void heap(HeapUsage heap);
11+
void handleHeapUsage(HeapUsage heap);
1212
}

0 commit comments

Comments
 (0)