-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from TelestionTeam/feat-database-improvements
Feat database improvements
- Loading branch information
Showing
9 changed files
with
145 additions
and
106 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
52 changes: 52 additions & 0 deletions
52
modules/telestion-core/src/main/java/org/telestion/core/database/DataListener.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,52 @@ | ||
package org.telestion.core.database; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Promise; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.telestion.api.message.JsonMessage; | ||
import org.telestion.api.config.Config; | ||
import org.telestion.core.message.Address; | ||
|
||
public final class DataListener extends AbstractVerticle { | ||
private final Configuration forcedConfig; | ||
private Configuration config; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(DataListener.class); | ||
|
||
private final String save = Address.incoming(DataService.class, "save"); | ||
|
||
public DataListener() { | ||
this.forcedConfig = null; | ||
} | ||
|
||
public DataListener(List<String> listeningAddresses) { | ||
this.forcedConfig = new Configuration(listeningAddresses); | ||
} | ||
|
||
@Override | ||
public void start(Promise<Void> startPromise) throws Exception { | ||
config = Config.get(forcedConfig, config(), Configuration.class); | ||
this.registerConsumers(); | ||
startPromise.complete(); | ||
} | ||
|
||
private void registerConsumers() { | ||
config.listeningAddresses().forEach(address -> { | ||
vertx.eventBus().consumer(address, document -> { | ||
JsonMessage.on(JsonMessage.class, document, msg -> { | ||
vertx.eventBus().publish(save, msg.json()); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
private static record Configuration(@JsonProperty List<String> listeningAddresses) { | ||
private Configuration() { | ||
this(Collections.emptyList()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.