Skip to content

Commit

Permalink
Add documentation and improve packet handling in receivers
Browse files Browse the repository at this point in the history
Enhanced the MapReceiver class by adding detailed JavaDoc comments describing its functionality and parameters. Improved packet handling in the BsmReceiver by skipping processing for packets with empty payloads, thus simplifying code flow

Signed-off-by: Matt Cook <[email protected]>
  • Loading branch information
mcook42 committed Dec 6, 2024
1 parent b661640 commit b40a2c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,23 @@ public void run() {
try {
log.debug("Waiting for UDP BSM packets...");
this.socket.receive(packet);
if (packet.getLength() > 0) {
String bsmJson = UdpHexDecoder.buildJsonBsmFromPacket(packet);
if (bsmJson != null) {
log.debug("Publishing String data to {}", publishTopic);
if ((packet.getLength() <= 0)) {
log.debug("Skipping empty payload");
continue;
}

String bsmJson = UdpHexDecoder.buildJsonBsmFromPacket(packet);
if (bsmJson != null) {
log.debug("Publishing String data to {}", publishTopic);

var sendResult = bsmPublisher.send(publishTopic, bsmJson);
sendResult.whenCompleteAsync((result, error) -> {
if (error != null) {
log.error("Error sending BSM to Kafka", error);
}
});
}
var sendResult = bsmPublisher.send(publishTopic, bsmJson);
sendResult.whenCompleteAsync((result, error) -> {
if (error != null) {
log.error("Error sending BSM to Kafka", error);
}
});
}

} catch (DisabledTopicException e) {
log.warn(e.getMessage());
} catch (InvalidPayloadException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,34 @@
import us.dot.its.jpo.ode.udp.UdpHexDecoder;
import us.dot.its.jpo.ode.udp.controller.UDPReceiverProperties;

/**
* The MapReceiver class is responsible for receiving UDP packets, decoding
* them, and publishing the decoded JSON map to a specified Kafka topic.
* It extends the {@link AbstractUdpReceiverPublisher} class to leverage UDP
* receiving capabilities.
*
* </p>MapReceiver listens on a specified port for incoming UDP packets encapsulating
* map data, and decodes these packets. Upon successful decoding, the map data is published
* to a Kafka topic using KafkaTemplate.
*/
@Slf4j
public class MapReceiver extends AbstractUdpReceiverPublisher {

KafkaTemplate<String, String> kafkaTemplate;
private final String publishTopic;

/**
* Constructs a new MapReceiver instance to receive UDP packets, decode them,
* and publish the decoded map data to a specified Kafka topic.
*
* @param receiverProperties The properties that define the UDP receiver
* configuration, including the port on which to
* listen and the buffer size for incoming packets.
* @param kafkaTemplate The KafkaTemplate instance used to send messages
* to the Kafka topic.
* @param publishTopic The topic to which decoded map data should be
* published.
*/
public MapReceiver(UDPReceiverProperties.ReceiverProperties receiverProperties,
KafkaTemplate<String, String> kafkaTemplate, String publishTopic) {
super(receiverProperties.getReceiverPort(), receiverProperties.getBufferSize());
Expand Down

0 comments on commit b40a2c4

Please sign in to comment.