Skip to content

Commit

Permalink
Remove usage of io.vertx.core.impl
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jun 19, 2024
1 parent e4adcb3 commit 7e1d37a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
15 changes: 9 additions & 6 deletions src/main/java/io/vertx/mqtt/MqttClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.json.annotations.JsonGen;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.impl.Arguments;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.*;

Expand Down Expand Up @@ -456,8 +455,9 @@ public int getMaxMessageSize() {
@Override
public MqttClientOptions setReceiveBufferSize(int receiveBufferSize) {
if ((this.maxMessageSize > 0) && (receiveBufferSize > 0)) {
Arguments.require(receiveBufferSize >= this.maxMessageSize,
"Receiver buffer size can't be lower than max message size");
if (receiveBufferSize < this.maxMessageSize) {
throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size");
}
}
super.setReceiveBufferSize(receiveBufferSize);
return this;
Expand All @@ -470,10 +470,13 @@ public MqttClientOptions setReceiveBufferSize(int receiveBufferSize) {
* @return MQTT client options instance
*/
public MqttClientOptions setMaxMessageSize(int maxMessageSize) {
Arguments.require(maxMessageSize > 0 || maxMessageSize == DEFAULT_MAX_MESSAGE_SIZE, "maxMessageSize must be > 0");
if (maxMessageSize <= 0 && maxMessageSize != DEFAULT_MAX_MESSAGE_SIZE) {
throw new IllegalArgumentException( "maxMessageSize must be > 0");
}
if ((maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) {
Arguments.require(this.getReceiveBufferSize() >= maxMessageSize,
"Receiver buffer size can't be lower than max message size");
if (this.getReceiveBufferSize() < maxMessageSize) {
throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size");
}
}
this.maxMessageSize = maxMessageSize;
return this;
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/io/vertx/mqtt/MqttServerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.vertx.codegen.json.annotations.JsonGen;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.ClientAuth;
import io.vertx.core.impl.Arguments;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.JksOptions;
import io.vertx.core.net.KeyCertOptions;
Expand Down Expand Up @@ -115,8 +114,9 @@ public MqttServerOptions(JsonObject json) {
MqttServerOptionsConverter.fromJson(json, this);

if ((this.maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) {
Arguments.require(this.getReceiveBufferSize() >= this.maxMessageSize,
"Receiver buffer size can't be lower than max message size");
if (this.getReceiveBufferSize() < this.maxMessageSize) {
throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size");
}
}
}

Expand Down Expand Up @@ -204,8 +204,9 @@ public MqttServerOptions addCrlValue(Buffer crlValue) throws NullPointerExceptio
@Override
public MqttServerOptions setReceiveBufferSize(int receiveBufferSize) {
if ((this.maxMessageSize > 0) && (receiveBufferSize > 0)) {
Arguments.require(receiveBufferSize >= this.maxMessageSize,
"Receiver buffer size can't be lower than max message size");
if (receiveBufferSize < this.maxMessageSize) {
throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size");
}
}
super.setReceiveBufferSize(receiveBufferSize);
return this;
Expand All @@ -224,10 +225,13 @@ public MqttServerOptions setSni(boolean sni) {
* @return MQTT server options instance
*/
public MqttServerOptions setMaxMessageSize(int maxMessageSize) {
Arguments.require(maxMessageSize > 0, "maxMessageSize must be > 0");
if (this.getReceiveBufferSize() > 0) {
Arguments.require(this.getReceiveBufferSize() >= maxMessageSize,
"Receiver buffer size can't be lower than max message size");
if (maxMessageSize <= 0 && maxMessageSize != DEFAULT_MAX_MESSAGE_SIZE) {
throw new IllegalArgumentException( "maxMessageSize must be > 0");
}
if ((maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) {
if (this.getReceiveBufferSize() < maxMessageSize) {
throw new IllegalArgumentException("Receiver buffer size can't be lower than max message size");
}
}
this.maxMessageSize = maxMessageSize;
return this;
Expand Down Expand Up @@ -272,7 +276,9 @@ public int getMaxClientIdLength() {
* @return MQTT server options instance
*/
public MqttServerOptions setMaxClientIdLength(int maxClientIdLength) {
Arguments.require(maxClientIdLength > 0, "maxClientIdLength must be > 0");
if (maxClientIdLength <= 0) {
throw new IllegalArgumentException("maxClientIdLength must be > 0");
}
this.maxClientIdLength = maxClientIdLength;
return this;
}
Expand Down Expand Up @@ -362,7 +368,9 @@ public int getWebSocketMaxFrameSize() {
* @param webSocketMaxFrameSize the new frame size
*/
public void setWebSocketMaxFrameSize(int webSocketMaxFrameSize) {
Arguments.require(webSocketMaxFrameSize > 0, "WebSocket max frame size must be > 0");
if (webSocketMaxFrameSize <= 0) {
throw new IllegalArgumentException("WebSocket max frame size must be > 0");
}
this.webSocketMaxFrameSize = webSocketMaxFrameSize;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/vertx/mqtt/impl/MqttEndpointImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public MqttEndpointImpl accept(boolean sessionPresent) {
public MqttEndpointImpl accept(boolean sessionPresent, MqttProperties properties) {
synchronized (conn) {
if (this.isConnected) {
throw new IllegalStateException("Connection already accepted");
throw new IllegalArgumentException("Connection already accepted");
}

return this.connack(MqttConnectReturnCode.CONNECTION_ACCEPTED, sessionPresent, properties);
Expand Down Expand Up @@ -889,7 +889,7 @@ private Future<Void> write(io.netty.handler.codec.mqtt.MqttMessage mqttMessage)
private void checkClosed() {

if (this.isClosed) {
throw new IllegalStateException("MQTT endpoint is closed");
throw new IllegalArgumentException("MQTT endpoint is closed");
}
}

Expand All @@ -899,7 +899,7 @@ private void checkClosed() {
private void checkConnected() {

if (!this.isConnected) {
throw new IllegalStateException("Connection not accepted yet");
throw new IllegalArgumentException("Connection not accepted yet");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/mqtt/impl/MqttServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ private boolean checkConnected() {
return true;
} else {
so.close();
throw new IllegalStateException("Received an MQTT packet from a not connected client (CONNECT not sent yet)");
throw new IllegalArgumentException("Received an MQTT packet from a not connected client (CONNECT not sent yet)");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public void setAckCallback(MqttPubAckCallback ackCallback) {
public void ack() {
if (this.qosLevel == MqttQoS.AT_LEAST_ONCE || this.qosLevel == MqttQoS.EXACTLY_ONCE) {
if (ackCallback == null) {
throw new IllegalStateException("Callback not present. Check that Auto Ack is disabled.");
throw new IllegalArgumentException("Callback not present. Check that Auto Ack is disabled.");
} else if (isAcked) {
throw new IllegalStateException("Ack of message " + messageId + " altready sent.");
throw new IllegalArgumentException("Ack of message " + messageId + " altready sent.");
} else {
isAcked = true;
ackCallback.ack();
Expand Down

0 comments on commit 7e1d37a

Please sign in to comment.