Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client improvements #125

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/asciidoc/dataobjects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ Do the same thing as link. Use it instead.
|[[keepAliveTimeSeconds]]`@keepAliveTimeSeconds`|`Number (int)`|+++
Set the keep alive timeout in seconds
+++
|[[keepAliveTimeout]]`@keepAliveTimeout`|`Number (int)`|+++
Set the time period in seconds after which unacknowledged pings will close the connection.
<p/>
Setting <code>0</code> will simply expire pings but won't close the connection.
+++
|[[keyStoreOptions]]`@keyStoreOptions`|`link:dataobjects.html#JksOptions[JksOptions]`|-
|[[localAddress]]`@localAddress`|`String`|-
|[[logActivity]]`@logActivity`|`Boolean`|-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json,
obj.setKeepAliveTimeSeconds(((Number)member.getValue()).intValue());
}
break;
case "keepAliveTimeout":
if (member.getValue() instanceof Number) {
obj.setKeepAliveTimeout(((Number)member.getValue()).intValue());
}
break;
case "maxInflightQueue":
if (member.getValue() instanceof Number) {
obj.setMaxInflightQueue(((Number)member.getValue()).intValue());
Expand Down Expand Up @@ -100,6 +105,7 @@ public static void toJson(MqttClientOptions obj, java.util.Map<String, Object> j
json.put("clientId", obj.getClientId());
}
json.put("keepAliveTimeSeconds", obj.getKeepAliveTimeSeconds());
json.put("keepAliveTimeout", obj.getKeepAliveTimeout());
json.put("maxInflightQueue", obj.getMaxInflightQueue());
json.put("maxMessageSize", obj.getMaxMessageSize());
if (obj.getPassword() != null) {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/io/vertx/mqtt/MqttClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class MqttClientOptions extends NetClientOptions {
public static final boolean DEFAULT_WILL_RETAIN = false;
public static final int DEFAULT_MAX_MESSAGE_SIZE = -1;

/**
* The default timeout value for an unacknowledge ping in seconds = 10
*/
public static final int PING_TIMEOUT_SECONDS = 10;

private String clientId;
private String username;
private String password;
Expand All @@ -55,6 +60,7 @@ public class MqttClientOptions extends NetClientOptions {
private int willQoS = DEFAULT_WILL_QOS;
private boolean willRetain = DEFAULT_WILL_RETAIN;
private int keepAliveTimeSeconds = DEFAULT_KEEP_ALIVE_TIME_SECONDS;
private int keepAliveTimeout = PING_TIMEOUT_SECONDS;
private boolean isAutoKeepAlive = true;
private boolean isAutoGeneratedClientId = true;
private int maxInflightQueue = DEFAULT_MAX_INFLIGHT_QUEUE;
Expand Down Expand Up @@ -93,6 +99,7 @@ public MqttClientOptions(MqttClientOptions other) {
this.willFlag = other.willFlag;
this.willQoS = other.willQoS;
this.willRetain = other.willRetain;
this.keepAliveTimeout = other.keepAliveTimeout;
this.keepAliveTimeSeconds = other.keepAliveTimeSeconds;
this.isAutoKeepAlive = other.isAutoKeepAlive;
this.isAutoGeneratedClientId = other.isAutoGeneratedClientId;
Expand Down Expand Up @@ -149,6 +156,13 @@ public int getKeepAliveTimeSeconds() {
return keepAliveTimeSeconds;
}

/**
* @return the ping timeout (in seconds)
*/
public int getKeepAliveTimeout() {
return keepAliveTimeout;
}

/**
* @return provided username
*/
Expand Down Expand Up @@ -294,6 +308,22 @@ public MqttClientOptions setKeepAliveTimeSeconds(int keepAliveTimeSeconds) {
return this;
}

/**
* Set the time period in seconds after which unacknowledged pings will close the connection.
* <p/>
* Setting {@code 0} will simply expire pings but won't close the connection.
*
* @param keepAliveTimeout the ping timeout
* @return current options instance
*/
public MqttClientOptions setKeepAliveTimeout(int keepAliveTimeout) {
if (keepAliveTimeout <= 0) {
throw new IllegalArgumentException("The ping timeout value must be greater than 0");
}
this.keepAliveTimeout = keepAliveTimeout;
return this;
}

/**
* @return max count of unacknowledged messages
*/
Expand Down
Loading