Skip to content

Commit

Permalink
fix: Added comments for CellMessageRoutingBuilder and fixed AdHocMess…
Browse files Browse the repository at this point in the history
…ageRoutingBuilder
  • Loading branch information
FunKuchen committed Nov 20, 2024
1 parent 3c7264f commit 341187c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public AdHocMessageRoutingBuilder broadcast() {
}

/**
* Configures the message to use a topologically scoped routing strategy.
* Configures the message to use a topologically-scoped routing strategy.
* @return this builder.
*/
public AdHocMessageRoutingBuilder topological() {
Expand All @@ -161,7 +161,7 @@ public AdHocMessageRoutingBuilder topological() {
}

/**
* Configures the message to use a topologically scoped routing strategy.
* Configures the message to use a geographically-scoped routing strategy.
* @param area the area which the message will be transmitted to.
* @return this builder.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,17 @@ public CellMessageRoutingBuilder(String hostName, GeoPoint sourcePosition) {
);
}

/**
* Creates the MessageRouting based on the methods called on this builder before.
* @return MessageRouting - The desired routing for a message.
*/
public MessageRouting build() {
checkNecessaryValues();
return this.build(new DestinationAddressContainer(
routing, destination, null, null, targetArea, protocolType)
);
}

private MessageRouting build(DestinationAddressContainer dac) {
if (streamDuration < 0) {
return new MessageRouting(dac, sourceAddressContainer);
} else {
return new MessageStreamRouting(dac, sourceAddressContainer, streamDuration, streamBandwidthInBitPs);
}
}

/**
* Defines stream properties for the message to send.
*
Expand Down Expand Up @@ -137,22 +133,45 @@ public CellMessageRoutingBuilder destination(NetworkAddress networkAddress) {
return this;
}

/**
* Sets the destination of the message being built.
* @param receiverName The string name of the receiving entity.
* @return this builder.
*/
public CellMessageRoutingBuilder destination(String receiverName) {
return destination(IpResolver.getSingleton().nameToIp(receiverName).getAddress());
}

/**
* Sets the destination of the message being built.
* @param ipAddress The IP address of the target destination as an {@link Inet4Address}.
* @return this builder.
*/
public CellMessageRoutingBuilder destination(Inet4Address ipAddress) {
return destination(new NetworkAddress(ipAddress));
}

public CellMessageRoutingBuilder destination(byte[] ipv4Address) {
return destination(new NetworkAddress(ipv4Address));
/**
* Sets the destination of the message being built.
* @param ipAddress The IP address of the target destination as an array of bytes.
* @return this builder.
*/
public CellMessageRoutingBuilder destination(byte[] ipAddress) {
return destination(new NetworkAddress(ipAddress));
}

/**
* A convenience method that sets the destination IP address to the broadcast address.
* @return this builder.
*/
public CellMessageRoutingBuilder broadcast() {
return destination(new NetworkAddress(NetworkAddress.BROADCAST_ADDRESS));
}

/**
* Configures the message to use a Multicast/Broadcast Service for transmission.
* @return this builder.
*/
public CellMessageRoutingBuilder mbs() {
Validate.isTrue(!mbsChanged, "MBS was already chosen!");
Validate.isTrue(!(routing == DestinationType.CELL_TOPOCAST), "MBS can not be enabled for topological routing!");
Expand All @@ -161,6 +180,10 @@ public CellMessageRoutingBuilder mbs() {
return this;
}

/**
* Configures the message to use a topologically-scoped routing strategy.
* @return this builder.
*/
public CellMessageRoutingBuilder topological() {
Validate.isTrue(!routingChanged, "Routing was already set!");
Validate.isTrue(!mbsChanged, "MBS can not be enabled for topological routing!");
Expand All @@ -169,6 +192,11 @@ public CellMessageRoutingBuilder topological() {
return this;
}

/**
* Configures the message to use a geographically-scoped routing strategy.
* @param area the area which the message will be transmitted to.
* @return this builder.
*/
public CellMessageRoutingBuilder geographical(GeoArea area) {
Validate.isTrue(!routingChanged, "Routing was already set!");
if (!mbsChanged) {
Expand Down Expand Up @@ -205,4 +233,11 @@ private void checkArea() {
}
}
}
private MessageRouting build(DestinationAddressContainer dac) {
if (streamDuration < 0) {
return new MessageRouting(dac, sourceAddressContainer);
} else {
return new MessageStreamRouting(dac, sourceAddressContainer, streamDuration, streamBandwidthInBitPs);
}
}
}

0 comments on commit 341187c

Please sign in to comment.