-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
162 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package dev.httpmarco.netline.node; | ||
|
||
import dev.httpmarco.netline.NetChannel; | ||
import dev.httpmarco.netline.NetCompHandler; | ||
import dev.httpmarco.netline.client.NetClient; | ||
import dev.httpmarco.netline.server.AbstractNetServer; | ||
import io.netty5.channel.Channel; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
public final class NetNode extends AbstractNetServer<NetNodeConfig> { | ||
|
||
private final List<NetClient> clients = new ArrayList<>(); | ||
private NetNodeState state = NetNodeState.INITIALIZING; | ||
|
||
public NetNode() { | ||
super(new NetNodeConfig()); | ||
} | ||
|
||
@Contract(pure = true) | ||
@Override | ||
public @Nullable CompletableFuture<Void> onClose() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void onBindFail(Throwable throwable) { | ||
|
||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> onBindSuccess() { | ||
var future = new CompletableFuture<Void>(); | ||
this.state = NetNodeState.BIND_CLUSTER; | ||
|
||
if(this.config().bindings().isEmpty()) { | ||
// we are the only node | ||
this.state = NetNodeState.READY; | ||
return CompletableFuture.completedFuture(null); | ||
} else { | ||
CompletableFuture.allOf(config().bindings().stream().map(binding -> { | ||
var netNodeClient = new NetNodeClient(binding); | ||
clients.add(netNodeClient); | ||
return netNodeClient.boot(); | ||
}).toArray(CompletableFuture[]::new)).whenComplete((unused, throwable) -> { | ||
this.state = NetNodeState.SYNC_CLUSTER; | ||
// todo | ||
|
||
this.state = NetNodeState.READY; | ||
future.complete(null); | ||
}); | ||
} | ||
return future; | ||
} | ||
|
||
@Contract(pure = true) | ||
@Override | ||
public @Nullable NetCompHandler handler() { | ||
return null; | ||
} | ||
|
||
@Contract(pure = true) | ||
@Override | ||
public @Nullable NetChannel findChannel(Channel channel) { | ||
return null; | ||
} | ||
|
||
@Contract(pure = true) | ||
@Override | ||
public @Nullable NetChannel generateChannel(Channel channel, @Nullable String id) { | ||
return null; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/dev/httpmarco/netline/node/NetNodeBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.httpmarco.netline.node; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@AllArgsConstructor | ||
public final class NetNodeBinding { | ||
|
||
private final String id; | ||
private final String hostname; | ||
private final int port; | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/dev/httpmarco/netline/node/NetNodeClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dev.httpmarco.netline.node; | ||
|
||
import dev.httpmarco.netline.client.NetClient; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@AllArgsConstructor | ||
public class NetNodeClient extends NetClient { | ||
|
||
public NetNodeClient(@NotNull NetNodeBinding binding) { | ||
this.config().id(binding.id()).hostname(binding.hostname()).port(binding.port()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
package dev.httpmarco.netline.tests; | ||
|
||
import dev.httpmarco.netline.Net; | ||
import dev.httpmarco.netline.node.NetNode; | ||
import dev.httpmarco.netline.node.NetNodeBinding; | ||
import dev.httpmarco.netline.node.NetNodeState; | ||
import org.junit.jupiter.api.*; | ||
|
||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
@DisplayName("5 - Node cluster test") | ||
public class NodeTest { | ||
@DisplayName("6 - Node cluster test") | ||
public final class NodeTest { | ||
|
||
/* | ||
private static NetNode node; | ||
private static NetNode nodeA; | ||
private static NetNode nodeB; | ||
|
||
@BeforeAll | ||
public static void beforeHandling() { | ||
node = new NetNode(); | ||
nodeA = Net.line().node(); | ||
nodeA.config(it -> it.bindings().add(new NetNodeBinding("nodeA", "localhost", 9093))); | ||
nodeB = Net.line().node(); | ||
nodeB.config(it -> it.port(9093)); | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
@DisplayName("5.1 Start first node") | ||
@DisplayName("6.1 Start first node") | ||
public void testState() { | ||
assert node.state() == NetNodeState.INITIALIZING; | ||
node.bootSync(); | ||
assert node.state() == NetNodeState.READY; | ||
assert nodeA.state() == NetNodeState.INITIALIZING; | ||
nodeA.bootSync(); | ||
assert nodeA.state() == NetNodeState.READY; | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
@DisplayName("6.2 Start second node") | ||
public void testSecondNode() { | ||
assert nodeB.state() == NetNodeState.INITIALIZING; | ||
nodeB.bootSync(); | ||
assert nodeB.state() == NetNodeState.READY; | ||
} | ||
|
||
*/ | ||
} |