currently refactoring a lot
This commit is contained in:
parent
31eb8a92eb
commit
ea6ae529cc
32 changed files with 205 additions and 185 deletions
|
|
@ -15,15 +15,15 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/io.nats/jnats
|
||||
implementation("io.nats:jnats:2.25.2")
|
||||
api("io.nats:jnats:2.25.2")
|
||||
|
||||
// https://mvnrepository.com/artifact/org.mongodb/bson
|
||||
implementation("org.mongodb:bson:5.8.0")
|
||||
api("org.mongodb:bson:5.8.0")
|
||||
|
||||
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core
|
||||
api("de.kentoj.scrow:kencommandapi-core:0.23")
|
||||
api("de.kentoj.scrow:kencommandapi-core:0.28")
|
||||
|
||||
compileOnly("net.kyori:adventure-api:5.2.0")
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,9 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ScrowMessageStyle implements MessageStyle {
|
||||
|
||||
public static ScrowMessageStyle GENERIC = new ScrowMessageStyle("Scrow", NamedTextColor.WHITE);
|
||||
public static ScrowMessageStyle GENERIC = new ScrowMessageStyle("Scrow", TextColor.color(0xe5377f));
|
||||
|
||||
@Getter
|
||||
private final Component prefix;
|
||||
|
|
@ -24,8 +22,7 @@ public class ScrowMessageStyle implements MessageStyle {
|
|||
this.prefixText = prefixText;
|
||||
this.prefixColor = prefixColor;
|
||||
this.prefix = Component.text(prefixText)
|
||||
.color(prefixColor)
|
||||
.decorate(TextDecoration.BOLD);
|
||||
.color(prefixColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.scrowlib.instancemanager;
|
||||
|
||||
import de.kentoj.scrowlib.messaging.MessageBroker;
|
||||
import io.nats.client.Connection;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bson.Document;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
|
|
@ -9,14 +9,11 @@ import java.util.List;
|
|||
|
||||
import static de.kentoj.scrowlib.utils.ResultUtils.unwrap;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class InstanceManagerImpl implements InstanceManager {
|
||||
|
||||
private final MessageBroker messageBroker;
|
||||
|
||||
public InstanceManagerImpl(Connection natsCon) {
|
||||
messageBroker = new MessageBroker(natsCon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerInstance deployInstance(String template) {
|
||||
var result = messageBroker.request("instance.deploy", new Document("template", template));
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import org.bson.Document;
|
|||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Slf4j
|
||||
public class MessageBroker {
|
||||
|
|
@ -26,6 +27,15 @@ public class MessageBroker {
|
|||
nats.publish(subject, ResultRepository.toBytes(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* subscribes to a subject, handler may run asynchronously
|
||||
*/
|
||||
public void subscribe(String subject, Consumer<Document> handler) {
|
||||
dispatcher.subscribe(subject, msg -> {
|
||||
executor.submit(() -> handler.accept(DocumentRepository.fromMessage(msg)));
|
||||
});
|
||||
}
|
||||
|
||||
public void handle(String subject, RequestHandler handler) {
|
||||
dispatcher.subscribe(subject, msg -> {
|
||||
if (msg.getReplyTo() == null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue