Skip to content

Commit

Permalink
Fix a few inconsistencies in server and client options
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Feb 14, 2023
1 parent 033adb0 commit dad5c88
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 16 deletions.
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MqttClientOptionsConverter {
private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER;
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER;

public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, MqttClientOptions obj) {
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, MqttClientOptions obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "ackTimeout":
Expand Down Expand Up @@ -104,11 +104,11 @@ public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json,
}
}

public static void toJson(MqttClientOptions obj, JsonObject json) {
static void toJson(MqttClientOptions obj, JsonObject json) {
toJson(obj, json.getMap());
}

public static void toJson(MqttClientOptions obj, java.util.Map<String, Object> json) {
static void toJson(MqttClientOptions obj, java.util.Map<String, Object> json) {
json.put("ackTimeout", obj.getAckTimeout());
json.put("autoAck", obj.isAutoAck());
json.put("autoGeneratedClientId", obj.isAutoGeneratedClientId());
Expand Down
92 changes: 92 additions & 0 deletions src/main/generated/io/vertx/mqtt/MqttServerOptionsConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package io.vertx.mqtt;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Base64;

/**
* Converter and mapper for {@link io.vertx.mqtt.MqttServerOptions}.
* NOTE: This class has been automatically generated from the {@link io.vertx.mqtt.MqttServerOptions} original class using Vert.x codegen.
*/
public class MqttServerOptionsConverter {


private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER;
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER;

static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, MqttServerOptions obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "autoClientId":
if (member.getValue() instanceof Boolean) {
obj.setAutoClientId((Boolean)member.getValue());
}
break;
case "maxMessageSize":
if (member.getValue() instanceof Number) {
obj.setMaxMessageSize(((Number)member.getValue()).intValue());
}
break;
case "perFrameWebSocketCompressionSupported":
if (member.getValue() instanceof Boolean) {
obj.setPerFrameWebSocketCompressionSupported((Boolean)member.getValue());
}
break;
case "perMessageWebSocketCompressionSupported":
if (member.getValue() instanceof Boolean) {
obj.setPerMessageWebSocketCompressionSupported((Boolean)member.getValue());
}
break;
case "timeoutOnConnect":
if (member.getValue() instanceof Number) {
obj.setTimeoutOnConnect(((Number)member.getValue()).intValue());
}
break;
case "useWebSocket":
if (member.getValue() instanceof Boolean) {
obj.setUseWebSocket((Boolean)member.getValue());
}
break;
case "webSocketAllowServerNoContext":
if (member.getValue() instanceof Boolean) {
obj.setWebSocketAllowServerNoContext((Boolean)member.getValue());
}
break;
case "webSocketCompressionLevel":
if (member.getValue() instanceof Number) {
obj.setWebSocketCompressionLevel(((Number)member.getValue()).intValue());
}
break;
case "webSocketMaxFrameSize":
if (member.getValue() instanceof Number) {
obj.setWebSocketMaxFrameSize(((Number)member.getValue()).intValue());
}
break;
case "webSocketPreferredClientNoContext":
if (member.getValue() instanceof Boolean) {
obj.setWebSocketPreferredClientNoContext((Boolean)member.getValue());
}
break;
}
}
}

static void toJson(MqttServerOptions obj, JsonObject json) {
toJson(obj, json.getMap());
}

static void toJson(MqttServerOptions obj, java.util.Map<String, Object> json) {
json.put("autoClientId", obj.isAutoClientId());
json.put("maxMessageSize", obj.getMaxMessageSize());
json.put("perFrameWebSocketCompressionSupported", obj.isPerFrameWebSocketCompressionSupported());
json.put("perMessageWebSocketCompressionSupported", obj.isPerMessageWebSocketCompressionSupported());
json.put("useWebSocket", obj.isUseWebSocket());
json.put("webSocketAllowServerNoContext", obj.isWebSocketAllowServerNoContext());
json.put("webSocketCompressionLevel", obj.getWebSocketCompressionLevel());
json.put("webSocketMaxFrameSize", obj.getWebSocketMaxFrameSize());
json.put("webSocketPreferredClientNoContext", obj.isWebSocketPreferredClientNoContext());
}
}
29 changes: 26 additions & 3 deletions src/main/java/io/vertx/mqtt/MqttClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* Represents options used by the MQTT client.
*/
@DataObject(generateConverter = true)
@DataObject(generateConverter = true, publicConverter = false)
public class MqttClientOptions extends NetClientOptions {

public static final int DEFAULT_PORT = 1883;
Expand Down Expand Up @@ -69,6 +69,21 @@ public class MqttClientOptions extends NetClientOptions {
*/
public MqttClientOptions() {
super();
init();
}

private void init() {
this.cleanSession = DEFAULT_CLEAN_SESSION;
this.willFlag = DEFAULT_WILL_FLAG;
this.willQoS = DEFAULT_WILL_QOS;
this.willRetain = DEFAULT_WILL_RETAIN;
this.keepAliveInterval = DEFAULT_KEEP_ALIVE_INTERVAL;
this.isAutoKeepAlive = true;
this.isAutoGeneratedClientId = true;
this.maxInflightQueue = DEFAULT_MAX_INFLIGHT_QUEUE;
this.maxMessageSize = DEFAULT_MAX_MESSAGE_SIZE;
this.ackTimeout = DEFAULT_ACK_TIMEOUT;
this.autoAck = DEFAULT_AUTO_ACK;
}

/**
Expand All @@ -78,6 +93,7 @@ public MqttClientOptions() {
*/
public MqttClientOptions(JsonObject json) {
super(json);
init();
MqttClientOptionsConverter.fromJson(json, this);
}

Expand Down Expand Up @@ -374,7 +390,7 @@ public MqttClientOptions setAutoGeneratedClientId(boolean isAutoGeneratedClientI
this.isAutoGeneratedClientId = isAutoGeneratedClientId;
return this;
}

/**
* @return if the ack (PUBACK/PUBCOMP) will be sent automatically by vertx-mqtt
*/
Expand All @@ -386,7 +402,7 @@ public boolean isAutoAck() {
* Set to false to let the application code to ack the message via {@link MqttPublishMessage#ack()}.
* If true, the ack (PUBACK/PUBCOMP) will be sent by vertx-mqtt before {@link MqttClient#publishHandler()} execution.
* (default is true)
* @param autoAck
* @param autoAck
*/
public void setAutoAck(boolean autoAck) {
this.autoAck = autoAck;
Expand Down Expand Up @@ -532,6 +548,13 @@ public MqttClientOptions addCrlValue(Buffer crlValue) throws NullPointerExceptio
return this;
}

@Override
public JsonObject toJson() {
JsonObject json = super.toJson();
MqttClientOptionsConverter.toJson(this, json);
return json;
}

@Override
public String toString() {
return "Options {" +
Expand Down
45 changes: 35 additions & 10 deletions src/main/java/io/vertx/mqtt/MqttServerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
/**
* Represents options used by the MQTT server
*/
@DataObject
@DataObject(generateConverter = true, publicConverter = false)
public class MqttServerOptions extends NetServerOptions {

public static final int DEFAULT_PORT = 1883; // Default port is 1883 for MQTT
public static final int DEFAULT_TLS_PORT = 8883; // Default TLS port is 8883 for MQTT

public static final int DEFAULT_MAX_MESSAGE_SIZE = 8092;
public static final boolean DEFAULT_AUTO_CLIENT_ID = true;
public static final int DEFAULT_TIMEOUT_ON_CONNECT = 90;
public static final boolean DEFAULT_USE_WEB_SOCKET = false;
public static final int DEFAULT_WEB_SOCKET_MAX_FRAME_SIZE = 65536;
public static final boolean DEFAULT_PER_FRAME_WEBSOCKET_COMPRESSION_SUPPORTED = true;
public static final boolean DEFAULT_PER_MESSAGE_WEBSOCKET_COMPRESSION_SUPPORTED = true;
Expand All @@ -61,25 +63,33 @@ public class MqttServerOptions extends NetServerOptions {
private boolean useWebSocket;
// max WebSocket frame size
private int webSocketMaxFrameSize;

// per frame WebSocket compression supported
private boolean perFrameWebSocketCompressionSupported;
// per message WebSocket compression supported
private boolean perMessageWebSocketCompressionSupported;
// WebSocket compression level
private int webSocketCompressionLevel;
// WebSocket allow server no context
private boolean webSocketAllowServerNoContext;
// WebSocket preferred client no context
private boolean webSocketPreferredClientNoContext;

/**
* Default constructor
*/
public MqttServerOptions() {
super();
init();
}

private void init() {
// override the default port
this.setPort(DEFAULT_PORT);
this.maxMessageSize = DEFAULT_MAX_MESSAGE_SIZE;
this.isAutoClientId = true;
this.isAutoClientId = DEFAULT_AUTO_CLIENT_ID;
this.timeoutOnConnect = DEFAULT_TIMEOUT_ON_CONNECT;
this.useWebSocket = DEFAULT_USE_WEB_SOCKET;
this.webSocketMaxFrameSize = DEFAULT_WEB_SOCKET_MAX_FRAME_SIZE;

this.perFrameWebSocketCompressionSupported = DEFAULT_PER_FRAME_WEBSOCKET_COMPRESSION_SUPPORTED;
this.perMessageWebSocketCompressionSupported = DEFAULT_PER_MESSAGE_WEBSOCKET_COMPRESSION_SUPPORTED;
this.webSocketCompressionLevel = DEFAULT_WEBSOCKET_COMPRESSION_LEVEL;
Expand All @@ -94,12 +104,9 @@ public MqttServerOptions() {
*/
public MqttServerOptions(JsonObject json) {
super(json);
// override the default port
this.setPort(json.getInteger("port", DEFAULT_PORT));
this.maxMessageSize = json.getInteger("maxMessageSize", DEFAULT_MAX_MESSAGE_SIZE);
this.isAutoClientId = json.getBoolean("isAutoClientId", true);
this.timeoutOnConnect = json.getInteger("timeoutOnConnect", DEFAULT_TIMEOUT_ON_CONNECT);
this.webSocketMaxFrameSize = json.getInteger("webSocketMaxFrameSize", DEFAULT_WEB_SOCKET_MAX_FRAME_SIZE);
init();

MqttServerOptionsConverter.fromJson(json, this);

if ((this.maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) {
Arguments.require(this.getReceiveBufferSize() >= this.maxMessageSize,
Expand All @@ -114,6 +121,17 @@ public MqttServerOptions(JsonObject json) {
*/
public MqttServerOptions(MqttServerOptions other) {
super(other);

this.maxMessageSize = other.maxMessageSize;
this.isAutoClientId = other.isAutoClientId;
this.timeoutOnConnect = other.timeoutOnConnect;
this.useWebSocket = other.useWebSocket;
this.webSocketMaxFrameSize = other.webSocketMaxFrameSize;
this.perFrameWebSocketCompressionSupported = other.perFrameWebSocketCompressionSupported;
this.perMessageWebSocketCompressionSupported = other.perMessageWebSocketCompressionSupported;
this.webSocketCompressionLevel = other.webSocketCompressionLevel;
this.webSocketAllowServerNoContext = other.webSocketAllowServerNoContext;
this.webSocketPreferredClientNoContext = other.webSocketAllowServerNoContext;
}

@Override
Expand Down Expand Up @@ -456,4 +474,11 @@ public MqttServerOptions setWebSocketPreferredClientNoContext(boolean accept) {
this.webSocketPreferredClientNoContext = accept;
return this;
}

@Override
public JsonObject toJson() {
JsonObject json = super.toJson();
MqttServerOptionsConverter.toJson(this, json);
return json;
}
}

0 comments on commit dad5c88

Please sign in to comment.