From 5a39ff16c97562c07f78f637ea326729599fcf43 Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Tue, 19 Nov 2024 09:58:25 +0100 Subject: [PATCH] fix: Added Inet4Address destination option, validated values, removed reset --- .../addressing/CellMessageRoutingBuilder.java | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/addressing/CellMessageRoutingBuilder.java b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/addressing/CellMessageRoutingBuilder.java index b7663abff..fdc41675d 100644 --- a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/addressing/CellMessageRoutingBuilder.java +++ b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/addressing/CellMessageRoutingBuilder.java @@ -22,8 +22,7 @@ import org.eclipse.mosaic.lib.objects.v2x.MessageRouting; import org.eclipse.mosaic.lib.objects.v2x.MessageStreamRouting; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.lang3.Validate; import java.net.Inet4Address; @@ -33,8 +32,6 @@ */ public class CellMessageRoutingBuilder { - private static final Logger log = LoggerFactory.getLogger(CellMessageRoutingBuilder.class); - private final SourceAddressContainer sourceAddressContainer; private long streamDuration = -1; @@ -83,14 +80,9 @@ public MessageRouting build() { private MessageRouting build(DestinationAddressContainer dac) { if (streamDuration < 0) { - MessageRouting messageRouting = new MessageRouting(dac, sourceAddressContainer); - resetValues(); - return messageRouting; + return new MessageRouting(dac, sourceAddressContainer); } else { - MessageStreamRouting messageStreamRouting = - new MessageStreamRouting(dac, sourceAddressContainer, streamDuration, streamBandwidthInBitPs); - resetValues(); - return messageStreamRouting; + return new MessageStreamRouting(dac, sourceAddressContainer, streamDuration, streamBandwidthInBitPs); } } @@ -113,7 +105,7 @@ public CellMessageRoutingBuilder streaming(long streamDuration, long streamBandw * @return the {@link CellMessageRoutingBuilder} */ public CellMessageRoutingBuilder protocol(ProtocolType type) { - assert !protocolChanged : "Protocol was already set! Using first setting."; + Validate.isTrue(!protocolChanged, "Protocol was already set!"); protocolType = type; protocolChanged = true; return this; @@ -139,7 +131,7 @@ public CellMessageRoutingBuilder udp() { } public CellMessageRoutingBuilder destination(NetworkAddress networkAddress) { - assert !destinationChanged : "Destination was already set! Using first setting."; + Validate.isTrue(!destinationChanged, "Destination was already set!"); this.destination = networkAddress; this.destinationChanged = true; return this; @@ -149,6 +141,10 @@ public CellMessageRoutingBuilder destination(String receiverName) { return destination(IpResolver.getSingleton().nameToIp(receiverName).getAddress()); } + public CellMessageRoutingBuilder destination(Inet4Address ipAddress) { + return destination(new NetworkAddress(ipAddress)); + } + public CellMessageRoutingBuilder destination(byte[] ipv4Address) { return destination(new NetworkAddress(ipv4Address)); } @@ -158,22 +154,22 @@ public CellMessageRoutingBuilder broadcast() { } public CellMessageRoutingBuilder mbs() { - assert !mbsChanged : "MBS was already chosen!"; + Validate.isTrue(!mbsChanged, "MBS was already chosen!"); routing = DestinationType.CELL_GEOCAST_MBS; mbsChanged = true; return this; } public CellMessageRoutingBuilder topological() { - assert !routingChanged : "Routing was already set! Using first setting."; - assert !mbsChanged : "MBS can not be enabled for topological routing!"; + Validate.isTrue(!routingChanged, "Routing was already set!"); + Validate.isTrue(!mbsChanged, "MBS can not be enabled for topological routing!"); routing = DestinationType.CELL_TOPOCAST; routingChanged = true; return this; } public CellMessageRoutingBuilder geographical(GeoArea area) { - assert !routingChanged : "Routing was already set! Using first setting."; + Validate.isTrue(!routingChanged, "Routing was already set!"); if (!mbsChanged) { routing = DestinationType.CELL_GEOCAST; } @@ -198,19 +194,4 @@ private void checkRouting() { throw new IllegalArgumentException("No routing protocol was given! Aborting."); } } - - private void resetValues() { - this.streamDuration = -1; - this.streamBandwidthInBitPs = -1; - - this.destination = null; - this.routing = null; - this.targetArea = null; - this.protocolType = null; - - this.destinationChanged = false; - this.routingChanged = false; - this.mbsChanged = false; - this.protocolChanged = false; - } }