-
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.
feat(connection): Integrating new telestion-api
- Loading branch information
Showing
11 changed files
with
61 additions
and
179 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
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
65 changes: 16 additions & 49 deletions
65
.../telestion-services/src/main/java/de/wuespace/telestion/services/connection/Receiver.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 |
---|---|---|
@@ -1,68 +1,35 @@ | ||
package de.wuespace.telestion.services.connection; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Promise; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import de.wuespace.telestion.api.config.Config; | ||
import de.wuespace.telestion.api.message.JsonMessage; | ||
import de.wuespace.telestion.api.verticle.TelestionConfiguration; | ||
import de.wuespace.telestion.api.verticle.TelestionVerticle; | ||
import de.wuespace.telestion.api.verticle.trait.WithEventBus; | ||
|
||
public final class Receiver extends AbstractVerticle { | ||
public final class Receiver extends TelestionVerticle<Receiver.Configuration> implements WithEventBus { | ||
|
||
@Override | ||
public void start(Promise<Void> startPromise) { | ||
config = Config.get(config, config(), Configuration.class); | ||
public void onStart() throws Exception { | ||
var config = getConfig(); | ||
|
||
for (var con : config.connectionAddresses()) { | ||
vertx.eventBus().consumer(con, | ||
raw -> JsonMessage.on(ConnectionData.class, raw, | ||
msg -> { | ||
logger.debug("Connection-Message received on {}", con); | ||
vertx.eventBus().publish(config.outputAddr(), msg.json()); | ||
})); | ||
register(con, raw -> { | ||
JsonMessage.on(ConnectionData.class, raw, | ||
msg -> { | ||
logger.debug("Connection-Message received on {}", con); | ||
publish(config.outAddress(), msg); | ||
}); | ||
}); | ||
} | ||
startPromise.complete(); | ||
} | ||
|
||
@Override | ||
public void stop(Promise<Void> stopPromise) { | ||
stopPromise.complete(); | ||
} | ||
|
||
/** | ||
* @param outputAddr | ||
* @param outAddress | ||
* @param connectionAddresses | ||
*/ | ||
public record Configuration( | ||
@JsonProperty String outputAddr, | ||
@JsonProperty String... connectionAddresses) { | ||
|
||
private Configuration() { | ||
this(null); | ||
} | ||
@JsonProperty String outAddress, | ||
@JsonProperty String... connectionAddresses) implements TelestionConfiguration { | ||
} | ||
|
||
public Receiver() { | ||
this(null); | ||
} | ||
|
||
/** | ||
* | ||
* @param config {@link Configuration} for the creation | ||
*/ | ||
public Receiver(Configuration config) { | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private Configuration config; | ||
|
||
/** | ||
* | ||
*/ | ||
private static final Logger logger = LoggerFactory.getLogger(Receiver.class); | ||
|
||
} |
66 changes: 14 additions & 52 deletions
66
...es/telestion-services/src/main/java/de/wuespace/telestion/services/connection/Sender.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 |
---|---|---|
@@ -1,76 +1,38 @@ | ||
package de.wuespace.telestion.services.connection; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import de.wuespace.telestion.api.config.Config; | ||
import de.wuespace.telestion.api.message.JsonMessage; | ||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Promise; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import de.wuespace.telestion.api.verticle.TelestionConfiguration; | ||
import de.wuespace.telestion.api.verticle.TelestionVerticle; | ||
import de.wuespace.telestion.api.verticle.trait.WithEventBus; | ||
|
||
public final class Sender extends AbstractVerticle { | ||
public final class Sender extends TelestionVerticle<Sender.Configuration> implements WithEventBus { | ||
|
||
@Override | ||
public void start(Promise<Void> startPromise) { | ||
config = Config.get(config, config(), Configuration.class); | ||
|
||
vertx.eventBus().consumer(config.inputAddress, | ||
raw -> { | ||
JsonMessage.on(SenderData.class, raw, this::handleMessage); | ||
JsonMessage.on(ConnectionData.class, raw, msg -> handleMessage(SenderData.fromConnectionData(msg))); | ||
}); | ||
startPromise.complete(); | ||
} | ||
|
||
@Override | ||
public void stop(Promise<Void> stopPromise) { | ||
stopPromise.complete(); | ||
public void onStart() throws Exception { | ||
register(getConfig().inAddress(), raw -> { | ||
JsonMessage.on(SenderData.class, raw, this::handleMessage); | ||
JsonMessage.on(ConnectionData.class, raw, msg -> handleMessage(SenderData.fromConnectionData(msg))); | ||
}); | ||
} | ||
|
||
/** | ||
* @param inputAddress | ||
* @param inAddress | ||
* @param connectionAddresses | ||
*/ | ||
public record Configuration( | ||
@JsonProperty String inputAddress, | ||
@JsonProperty String... connectionAddresses) implements JsonMessage { | ||
|
||
@SuppressWarnings("unused") | ||
private Configuration() { | ||
this(null); | ||
} | ||
} | ||
|
||
public Sender() { | ||
this(null); | ||
} | ||
|
||
/** | ||
* | ||
* @param config {@link Configuration} for the creation | ||
*/ | ||
public Sender(Configuration config) { | ||
this.config = config; | ||
@JsonProperty String inAddress, | ||
@JsonProperty String... connectionAddresses) implements TelestionConfiguration { | ||
} | ||
|
||
/** | ||
* | ||
* @param msg to send | ||
*/ | ||
private void handleMessage(SenderData msg) { | ||
for (var s : config.connectionAddresses()) { | ||
for (var s : getConfig().connectionAddresses()) { | ||
logger.debug("Sending Message to {}", s); | ||
vertx.eventBus().publish(s, msg.json()); | ||
publish(s, msg.json()); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private Configuration config; | ||
|
||
/** | ||
* | ||
*/ | ||
private static final Logger logger = LoggerFactory.getLogger(Sender.class); | ||
} |
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
42 changes: 8 additions & 34 deletions
42
...estion-services/src/main/java/de/wuespace/telestion/services/connection/StaticSender.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 |
---|---|---|
@@ -1,49 +1,23 @@ | ||
package de.wuespace.telestion.services.connection; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import de.wuespace.telestion.api.config.Config; | ||
import de.wuespace.telestion.api.message.JsonMessage; | ||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Promise; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import de.wuespace.telestion.api.verticle.TelestionConfiguration; | ||
import de.wuespace.telestion.api.verticle.TelestionVerticle; | ||
import de.wuespace.telestion.api.verticle.trait.WithEventBus; | ||
|
||
public final class StaticSender extends AbstractVerticle { | ||
public final class StaticSender extends TelestionVerticle<StaticSender.Configuration> implements WithEventBus { | ||
|
||
public record Configuration(@JsonProperty String inAddress, | ||
@JsonProperty String outAddress, | ||
@JsonProperty ConnectionDetails staticDetails) implements JsonMessage { | ||
private Configuration() { | ||
this(null, null, null); | ||
} | ||
@JsonProperty ConnectionDetails staticDetails) implements TelestionConfiguration { | ||
} | ||
|
||
@Override | ||
public void start(Promise<Void> startPromise) { | ||
config = Config.get(config, config(), Configuration.class); | ||
|
||
vertx.eventBus().consumer(config.inAddress(), raw -> JsonMessage.on(RawMessage.class, raw, msg -> { | ||
public void onStart() throws Exception { | ||
register(getConfig().inAddress, body -> JsonMessage.on(RawMessage.class, body, msg -> { | ||
logger.debug("Sending static message"); | ||
vertx.eventBus().publish(config.outAddress(), new ConnectionData(msg.data(), | ||
config.staticDetails()).json()); | ||
publish(getConfig().outAddress(), new ConnectionData(msg.data(), getConfig().staticDetails())); | ||
})); | ||
|
||
startPromise.complete(); | ||
} | ||
|
||
@Override | ||
public void stop(Promise<Void> stopPromise) { | ||
stopPromise.complete(); | ||
} | ||
|
||
public StaticSender() { | ||
this(null); | ||
} | ||
|
||
public StaticSender(Configuration config) { | ||
this.config = config; | ||
} | ||
|
||
private Configuration config; | ||
private final static Logger logger = LoggerFactory.getLogger(StaticSender.class); | ||
} |
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.