提交 21a87faf 编写于 作者: 如梦技术's avatar 如梦技术 🐛

代码优化。

上级 ae4bdd62
......@@ -17,6 +17,7 @@
package net.dreamlu.iot.mqtt.codec;
import org.tio.core.ChannelContext;
import static net.dreamlu.iot.mqtt.codec.MqttConstant.MIN_CLIENT_ID_LENGTH;
/**
......
......@@ -23,9 +23,6 @@ package net.dreamlu.iot.mqtt.codec;
*/
public final class MqttConstant {
private MqttConstant() {
}
/**
* mqtt protocol length
*/
......@@ -47,4 +44,7 @@ public final class MqttConstant {
*/
public static final int DEFAULT_MAX_CLIENT_ID_LENGTH = 23;
private MqttConstant() {
}
}
......@@ -21,6 +21,7 @@ import org.tio.core.ChannelContext;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static net.dreamlu.iot.mqtt.codec.MqttConstant.DEFAULT_MAX_CLIENT_ID_LENGTH;
/**
......
......@@ -20,7 +20,6 @@ import net.dreamlu.iot.mqtt.codec.*;
import org.tio.client.intf.ClientAioHandler;
import org.tio.core.ChannelContext;
import org.tio.core.TioConfig;
import org.tio.core.exception.TioDecodeException;
import org.tio.core.intf.Packet;
import java.nio.ByteBuffer;
......
......@@ -16,7 +16,10 @@
package net.dreamlu.iot.mqtt.core.client;
import net.dreamlu.iot.mqtt.codec.*;
import net.dreamlu.iot.mqtt.codec.ByteBufferAllocator;
import net.dreamlu.iot.mqtt.codec.MqttConstant;
import net.dreamlu.iot.mqtt.codec.MqttProperties;
import net.dreamlu.iot.mqtt.codec.MqttVersion;
import org.tio.client.ClientChannelContext;
import org.tio.client.ClientTioConfig;
import org.tio.client.ReconnConf;
......@@ -28,7 +31,6 @@ import org.tio.core.ssl.SslConfig;
import org.tio.utils.hutool.StrUtil;
import org.tio.utils.thread.pool.DefaultThreadFactory;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.function.Consumer;
......
......@@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;
import org.tio.core.Tio;
import org.tio.core.TioConfig;
import org.tio.core.exception.TioDecodeException;
import org.tio.core.intf.Packet;
import org.tio.server.AcceptCompletionHandler;
import org.tio.server.intf.ServerAioHandler;
......@@ -41,10 +40,9 @@ public class MqttServerAioHandler implements ServerAioHandler {
private final MqttServerProcessor processor;
public MqttServerAioHandler(int maxBytesInMessage,
int maxClientIdLength,
ByteBufferAllocator bufferAllocator,
MqttServerProcessor processor) {
this.mqttDecoder = new MqttDecoder(maxBytesInMessage, maxClientIdLength);
this.mqttDecoder = new MqttDecoder(maxBytesInMessage);
this.mqttEncoder = MqttEncoder.INSTANCE;
this.allocator = bufferAllocator;
this.processor = processor;
......
......@@ -70,10 +70,6 @@ public class MqttServerCreator {
* 消息解析最大 bytes 长度,默认:8092
*/
private int maxBytesInMessage = MqttConstant.DEFAULT_MAX_BYTES_IN_MESSAGE;
/**
* 最大 clientId 长度,默认:23
*/
private int maxClientIdLength = MqttConstant.DEFAULT_MAX_CLIENT_ID_LENGTH;
/**
* 堆内存和堆外内存
*/
......@@ -176,18 +172,6 @@ public class MqttServerCreator {
return this;
}
public int getMaxClientIdLength() {
return maxClientIdLength;
}
public MqttServerCreator maxClientIdLength(int maxClientIdLength) {
if (maxClientIdLength < 1) {
throw new IllegalArgumentException("maxClientIdLength must be greater than 0.");
}
this.maxClientIdLength = maxClientIdLength;
return this;
}
public ByteBufferAllocator getBufferAllocator() {
return bufferAllocator;
}
......@@ -324,7 +308,7 @@ public class MqttServerCreator {
DefaultMqttServerProcessor serverProcessor = new DefaultMqttServerProcessor(this.messageStore, this.sessionManager,
this.authHandler, this.subscribeManager, this.messageDispatcher, this.connectStatusListener, this.messageListener, executor);
// 1. 处理消息
ServerAioHandler handler = new MqttServerAioHandler(this.maxBytesInMessage, this.maxClientIdLength, this.bufferAllocator, serverProcessor);
ServerAioHandler handler = new MqttServerAioHandler(this.maxBytesInMessage, this.bufferAllocator, serverProcessor);
// 2. t-io 监听
ServerAioListener listener = new MqttServerAioListener(this.messageStore, this.sessionManager, this.subscribeManager,
this.messageDispatcher, this.connectStatusListener);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册