Skip to content
Permalink
Browse files

Minor UDP updates

  • Loading branch information
richturner committed Dec 23, 2019
1 parent 76cf58d commit 4161fb6c49b460eab1d6f1c2ee62cf29e6ebe00d
@@ -65,16 +65,16 @@
String host = Values.getMetaItemValueOrThrow(
protocolConfiguration,
META_PROTOCOL_HOST,
true,
true
false,
false
).flatMap(Values::getString).orElse(null);

int port = Values.getMetaItemValueOrThrow(
Integer port = Values.getMetaItemValueOrThrow(
protocolConfiguration,
META_PROTOCOL_PORT,
true,
true
).flatMap(Values::getIntegerCoerced).orElse(0);
false,
false
).flatMap(Values::getIntegerCoerced).orElse(null);

Integer bindPort = Values.getMetaItemValueOrThrow(
protocolConfiguration,
@@ -83,18 +83,14 @@
false
).flatMap(Values::getIntegerCoerced).orElse(null);

if (port < 1 || port > 65536) {
if (port != null && (port < 1 || port > 65536)) {
throw new IllegalArgumentException("Port must be in the range 1-65536");
}

if (bindPort != null && (bindPort < 1 || bindPort > 65536)) {
throw new IllegalArgumentException("Bind port must be in the range 1-65536 if specified");
}

if (TextUtil.isNullOrEmpty(host)) {
throw new IllegalArgumentException("Host cannot be empty");
}

return new UdpIoClient<>(host, port, bindPort, executorService);
}
}
@@ -53,11 +53,12 @@
protected int port;
protected int bindPort;

public UdpIoClient(String host, int port, Integer bindPort, ProtocolExecutorService executorService) {
public UdpIoClient(String host, Integer port, Integer bindPort, ProtocolExecutorService executorService) {
super(executorService);
TextUtil.requireNonNullAndNonEmpty(host);

if (port < 1 || port > 65536) {
if (port == null) {
port = 0;
} else if (port < 1 || port > 65536) {
throw new IllegalArgumentException("Port must be between 1 and 65536");
}

@@ -77,7 +78,7 @@ protected void addEncodersDecoders(Channel channel) {
channel.pipeline().addLast(new MessageToMessageEncoder<ByteBuf>() {
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
out.add(new DatagramPacket(msg.retain(), new InetSocketAddress(host, port)));
out.add(new DatagramPacket(msg.retain(), host != null ? new InetSocketAddress(host, port) : new InetSocketAddress(port)));
}
});

@@ -103,7 +104,7 @@ protected ChannelFuture startChannel() {

@Override
public String getClientUri() {
return "udp://" + host + ":" + port + " (bindPort: " + bindPort + ")";
return "udp://" + (host != null ? host : "0.0.0.0") + ":" + port + " (bindPort: " + bindPort + ")";
}

@Override
@@ -283,6 +283,23 @@ public static MetaItemDescriptor metaItemString(String urn, Access access, boole
isSecret);
}

@JsIgnore
public static MetaItemDescriptor metaItemNumber(String urn, Access access, boolean required, Double minValue, Double maxValue) {
return new MetaItemDescriptorImpl(
urn,
ValueType.NUMBER,
access,
required,
null,
null,
1,
minValue != null ? Values.create(minValue) : null,
false,
minValue != null ? Values.create(minValue) : null,
maxValue != null ? Values.create(maxValue) : null,
null,
false);
}

@JsIgnore
public static MetaItemDescriptor metaItemInteger(String urn, Access access, boolean required, Integer minValue, Integer maxValue) {

0 comments on commit 4161fb6

Please sign in to comment.
You can’t perform that action at this time.