Skip to content

Commit a7046d1

Browse files
authored
chore: improve channel messaging and address memory leaks (#1687)
### Motivation The channel messaging system (as well as a few network parts in general) really need a cleanup to improve the code quality and reliability of the system. Furthermore, there were memory leaks reported that need to be addressed as well. ### Modification This pr mostly improves channel messaging to be more reliable overall and improves the api surface exposed to consumers. Furthermore, all possible memory leaks were addressed (not limited to channel messaging) and some other networking parts were improved as well. ### Result Channel messaging should be more reliable and easier to use. Additionally, there shouldn't be any memory leaks anymore.
1 parent 613b214 commit a7046d1

File tree

34 files changed

+1567
-1004
lines changed

34 files changed

+1567
-1004
lines changed

driver/api/src/main/java/eu/cloudnetservice/driver/channel/ChannelMessage.java

Lines changed: 274 additions & 118 deletions
Large diffs are not rendered by default.

driver/api/src/main/java/eu/cloudnetservice/driver/channel/ChannelMessageSender.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525

2626
/**
2727
* Represents a sender of a channel message. A channel message sender is not required to be the actual component sending
28-
* the message nor is there a requirement for the name to match the driver environment when creating a new target. But
28+
* the message, nor is there a requirement for the name to match the driver environment when creating a new target. But
2929
* it is strongly recommended to not mismatch information as it may lead to confusing results on the receiver site.
3030
* <p>
31-
* Note: It is not recommended using the constructor directly. Consider using either {@link #self()} if you want a jvm
32-
* static sender representing the current network component or {@link #of(String, DriverEnvironment)} if you want to
31+
* Note: It is not recommended using the constructor directly. Consider using either {@link #self()} if you want a
32+
* sender instance representing the current network component or {@link #of(String, DriverEnvironment)} if you want to
3333
* create a sender for another network component.
3434
*
3535
* @param name the name of the new sender.
@@ -68,7 +68,7 @@ public record ChannelMessageSender(@NonNull String name, @NonNull DriverEnvironm
6868
*
6969
* @param serviceInfoSnapshot the service to check.
7070
* @return true if this sender represents the given service, false otherwise.
71-
* @throws NullPointerException if the given snapshot is null.
71+
* @throws NullPointerException if the given service snapshot to compare to is null.
7272
*/
7373
public boolean is(@NonNull ServiceInfoSnapshot serviceInfoSnapshot) {
7474
return this.type.equals(DriverEnvironment.WRAPPER) && this.name.equals(serviceInfoSnapshot.name());
@@ -79,7 +79,7 @@ public boolean is(@NonNull ServiceInfoSnapshot serviceInfoSnapshot) {
7979
*
8080
* @param node the node to check.
8181
* @return true if this sender represents the given node, false otherwise.
82-
* @throws NullPointerException if the given input is null.
82+
* @throws NullPointerException if the given node to compare to is null.
8383
*/
8484
public boolean is(@NonNull NetworkClusterNode node) {
8585
return this.type.equals(DriverEnvironment.NODE) && this.name.equals(node.uniqueId());
@@ -93,9 +93,7 @@ public boolean is(@NonNull NetworkClusterNode node) {
9393
* @return a new {@link ChannelMessageTarget} based on the information of this sender.
9494
*/
9595
public @NonNull ChannelMessageTarget toTarget() {
96-
var type = this.type.equals(DriverEnvironment.NODE)
97-
? ChannelMessageTarget.Type.NODE
98-
: ChannelMessageTarget.Type.SERVICE;
99-
return new ChannelMessageTarget(type, this.name);
96+
var isNode = this.type.equals(DriverEnvironment.NODE);
97+
return isNode ? ChannelMessageTarget.node(this.name) : ChannelMessageTarget.service(this.name);
10098
}
10199
}

0 commit comments

Comments
 (0)