@@ -1 +1,3 @@
|
|||||||
language: java
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
||||||
|
|||||||
@@ -75,14 +75,8 @@ public class Server {
|
|||||||
final Server server = new Server();
|
final Server server = new Server();
|
||||||
server.startServer();
|
server.startServer();
|
||||||
System.out.println("Server started, version 0.10-SNAPSHOT");
|
System.out.println("Server started, version 0.10-SNAPSHOT");
|
||||||
// Bind a shutdown hook
|
//Bind a shutdown hook
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread(server::stopServer));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
server.stopServer();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -94,13 +94,7 @@ final class BrokerInterceptor implements Interceptor {
|
|||||||
for (final InterceptHandler handler : this.handlers.get(InterceptConnectMessage.class)) {
|
for (final InterceptHandler handler : this.handlers.get(InterceptConnectMessage.class)) {
|
||||||
LOG.debug("Sending MQTT CONNECT message to interceptor. CId={}, interceptorId={}",
|
LOG.debug("Sending MQTT CONNECT message to interceptor. CId={}, interceptorId={}",
|
||||||
msg.payload().clientIdentifier(), handler.getID());
|
msg.payload().clientIdentifier(), handler.getID());
|
||||||
executor.execute(new Runnable() {
|
executor.execute(() -> handler.onConnect(new InterceptConnectMessage(msg)));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.onConnect(new InterceptConnectMessage(msg));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +103,7 @@ final class BrokerInterceptor implements Interceptor {
|
|||||||
for (final InterceptHandler handler : this.handlers.get(InterceptDisconnectMessage.class)) {
|
for (final InterceptHandler handler : this.handlers.get(InterceptDisconnectMessage.class)) {
|
||||||
LOG.debug("Notifying MQTT client disconnection to interceptor. CId={}, username={}, interceptorId={}",
|
LOG.debug("Notifying MQTT client disconnection to interceptor. CId={}, username={}, interceptorId={}",
|
||||||
clientID, username, handler.getID());
|
clientID, username, handler.getID());
|
||||||
executor.execute(new Runnable() {
|
executor.execute(() -> handler.onDisconnect(new InterceptDisconnectMessage(clientID, username)));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.onDisconnect(new InterceptDisconnectMessage(clientID, username));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,13 +112,7 @@ final class BrokerInterceptor implements Interceptor {
|
|||||||
for (final InterceptHandler handler : this.handlers.get(InterceptConnectionLostMessage.class)) {
|
for (final InterceptHandler handler : this.handlers.get(InterceptConnectionLostMessage.class)) {
|
||||||
LOG.debug("Notifying unexpected MQTT client disconnection to interceptor CId={}, username={}, " +
|
LOG.debug("Notifying unexpected MQTT client disconnection to interceptor CId={}, username={}, " +
|
||||||
"interceptorId={}", clientID, username, handler.getID());
|
"interceptorId={}", clientID, username, handler.getID());
|
||||||
executor.execute(new Runnable() {
|
executor.execute(() -> handler.onConnectionLost(new InterceptConnectionLostMessage(clientID, username)));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.onConnectionLost(new InterceptConnectionLostMessage(clientID, username));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,13 +123,7 @@ final class BrokerInterceptor implements Interceptor {
|
|||||||
for (final InterceptHandler handler : this.handlers.get(InterceptPublishMessage.class)) {
|
for (final InterceptHandler handler : this.handlers.get(InterceptPublishMessage.class)) {
|
||||||
LOG.debug("Notifying MQTT PUBLISH message to interceptor. CId={}, messageId={}, topic={}, interceptorId={}",
|
LOG.debug("Notifying MQTT PUBLISH message to interceptor. CId={}, messageId={}, topic={}, interceptorId={}",
|
||||||
clientID, messageId, topic, handler.getID());
|
clientID, messageId, topic, handler.getID());
|
||||||
executor.execute(new Runnable() {
|
executor.execute(() -> handler.onPublish(new InterceptPublishMessage(msg, clientID, username)));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.onPublish(new InterceptPublishMessage(msg, clientID, username));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,13 +132,7 @@ final class BrokerInterceptor implements Interceptor {
|
|||||||
for (final InterceptHandler handler : this.handlers.get(InterceptSubscribeMessage.class)) {
|
for (final InterceptHandler handler : this.handlers.get(InterceptSubscribeMessage.class)) {
|
||||||
LOG.debug("Notifying MQTT SUBSCRIBE message to interceptor. CId={}, topicFilter={}, interceptorId={}",
|
LOG.debug("Notifying MQTT SUBSCRIBE message to interceptor. CId={}, topicFilter={}, interceptorId={}",
|
||||||
sub.getClientId(), sub.getTopicFilter(), handler.getID());
|
sub.getClientId(), sub.getTopicFilter(), handler.getID());
|
||||||
executor.execute(new Runnable() {
|
executor.execute(() -> handler.onSubscribe(new InterceptSubscribeMessage(sub, username)));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.onSubscribe(new InterceptSubscribeMessage(sub, username));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,13 +141,7 @@ final class BrokerInterceptor implements Interceptor {
|
|||||||
for (final InterceptHandler handler : this.handlers.get(InterceptUnsubscribeMessage.class)) {
|
for (final InterceptHandler handler : this.handlers.get(InterceptUnsubscribeMessage.class)) {
|
||||||
LOG.debug("Notifying MQTT UNSUBSCRIBE message to interceptor. CId={}, topic={}, interceptorId={}", clientID,
|
LOG.debug("Notifying MQTT UNSUBSCRIBE message to interceptor. CId={}, topic={}, interceptorId={}", clientID,
|
||||||
topic, handler.getID());
|
topic, handler.getID());
|
||||||
executor.execute(new Runnable() {
|
executor.execute(() -> handler.onUnsubscribe(new InterceptUnsubscribeMessage(topic, clientID, username)));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.onUnsubscribe(new InterceptUnsubscribeMessage(topic, clientID, username));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,13 +150,7 @@ final class BrokerInterceptor implements Interceptor {
|
|||||||
for (final InterceptHandler handler : this.handlers.get(InterceptAcknowledgedMessage.class)) {
|
for (final InterceptHandler handler : this.handlers.get(InterceptAcknowledgedMessage.class)) {
|
||||||
LOG.debug("Notifying MQTT ACK message to interceptor. CId={}, messageId={}, topic={}, interceptorId={}",
|
LOG.debug("Notifying MQTT ACK message to interceptor. CId={}, messageId={}, topic={}, interceptorId={}",
|
||||||
msg.getMsg().getClientID(), msg.getPacketID(), msg.getTopic(), handler.getID());
|
msg.getMsg().getClientID(), msg.getPacketID(), msg.getTopic(), handler.getID());
|
||||||
executor.execute(new Runnable() {
|
executor.execute(() -> handler.onMessageAcknowledged(msg));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.onMessageAcknowledged(msg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -822,8 +822,10 @@ public class ProtocolProcessor {
|
|||||||
if (req.qualityOfService() == FAILURE) {
|
if (req.qualityOfService() == FAILURE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Subscription newSubscription =
|
Subscription newSubscription = new Subscription(
|
||||||
new Subscription(clientID, new Topic(req.topicName()), req.qualityOfService());
|
clientID,
|
||||||
|
new Topic(req.topicName()),
|
||||||
|
req.qualityOfService());
|
||||||
|
|
||||||
clientSession.subscribe(newSubscription);
|
clientSession.subscribe(newSubscription);
|
||||||
newSubscriptions.add(newSubscription);
|
newSubscriptions.add(newSubscription);
|
||||||
@@ -889,13 +891,8 @@ public class ProtocolProcessor {
|
|||||||
|
|
||||||
// scans retained messages to be published to the new subscription
|
// scans retained messages to be published to the new subscription
|
||||||
// TODO this is ugly, it does a linear scan on potential big dataset
|
// TODO this is ugly, it does a linear scan on potential big dataset
|
||||||
Collection<IMessagesStore.StoredMessage> messages = m_messagesStore.searchMatching(new IMatchingCondition() {
|
Collection<IMessagesStore.StoredMessage> messages = m_messagesStore
|
||||||
|
.searchMatching(key -> key.match(newSubscription.getTopicFilter()));
|
||||||
@Override
|
|
||||||
public boolean match(Topic key) {
|
|
||||||
return key.match(newSubscription.getTopicFilter());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!messages.isEmpty()) {
|
if (!messages.isEmpty()) {
|
||||||
LOG.info("Publishing retained messages CId={}, topics={}, messagesNo={}",
|
LOG.info("Publishing retained messages CId={}, topics={}, messagesNo={}",
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package io.moquette.spi.impl;
|
|||||||
import io.moquette.interception.InterceptHandler;
|
import io.moquette.interception.InterceptHandler;
|
||||||
import io.moquette.persistence.MemoryStorageService;
|
import io.moquette.persistence.MemoryStorageService;
|
||||||
import io.moquette.server.netty.NettyUtils;
|
import io.moquette.server.netty.NettyUtils;
|
||||||
import io.moquette.spi.IMatchingCondition;
|
|
||||||
import io.moquette.spi.IMessagesStore;
|
import io.moquette.spi.IMessagesStore;
|
||||||
import io.moquette.spi.IMessagesStore.StoredMessage;
|
import io.moquette.spi.IMessagesStore.StoredMessage;
|
||||||
import io.moquette.spi.ISessionsStore;
|
import io.moquette.spi.ISessionsStore;
|
||||||
@@ -417,12 +416,8 @@ public class ProtocolProcessorTest {
|
|||||||
.payload(Unpooled.copiedBuffer("Hello".getBytes())).retained(true).messageId(100).build();
|
.payload(Unpooled.copiedBuffer("Hello".getBytes())).retained(true).messageId(100).build();
|
||||||
m_processor.processPublish(m_channel, msg);
|
m_processor.processPublish(m_channel, msg);
|
||||||
|
|
||||||
Collection<IMessagesStore.StoredMessage> messages = m_messagesStore.searchMatching(new IMatchingCondition() {
|
Collection<IMessagesStore.StoredMessage> messages = m_messagesStore
|
||||||
|
.searchMatching(key -> key.match(new Topic(FAKE_TOPIC)));
|
||||||
public boolean match(Topic key) {
|
|
||||||
return key.match(new Topic(FAKE_TOPIC));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
assertFalse(messages.isEmpty());
|
assertFalse(messages.isEmpty());
|
||||||
|
|
||||||
// Exercise
|
// Exercise
|
||||||
@@ -432,12 +427,7 @@ public class ProtocolProcessorTest {
|
|||||||
m_processor.processPublish(m_channel, cleanPubMsg);
|
m_processor.processPublish(m_channel, cleanPubMsg);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
messages = m_messagesStore.searchMatching(new IMatchingCondition() {
|
messages = m_messagesStore.searchMatching(key -> key.match(new Topic(FAKE_TOPIC)));
|
||||||
|
|
||||||
public boolean match(Topic key) {
|
|
||||||
return key.match(new Topic(FAKE_TOPIC));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
assertTrue(messages.isEmpty());
|
assertTrue(messages.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,12 +134,9 @@ public class Client {
|
|||||||
|
|
||||||
private void doConnect(MqttConnectMessage connectMessage) {
|
private void doConnect(MqttConnectMessage connectMessage) {
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
this.setCallback(new Client.ICallback() {
|
this.setCallback(msg -> {
|
||||||
|
receivedMsg = msg;
|
||||||
public void call(MqttMessage msg) {
|
latch.countDown();
|
||||||
receivedMsg = msg;
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.sendMessage(connectMessage);
|
this.sendMessage(connectMessage);
|
||||||
|
|||||||
@@ -59,14 +59,11 @@ final class EmbeddedLauncher {
|
|||||||
|
|
||||||
System.out.println("Broker started press [CTRL+C] to stop");
|
System.out.println("Broker started press [CTRL+C] to stop");
|
||||||
//Bind a shutdown hook
|
//Bind a shutdown hook
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
@Override
|
System.out.println("Stopping broker");
|
||||||
public void run() {
|
mqttBroker.stopServer();
|
||||||
System.out.println("Stopping broker");
|
System.out.println("Broker stopped");
|
||||||
mqttBroker.stopServer();
|
}));
|
||||||
System.out.println("Broker stopped");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Thread.sleep(20000);
|
Thread.sleep(20000);
|
||||||
System.out.println("Before self publish");
|
System.out.println("Before self publish");
|
||||||
|
|||||||
@@ -83,13 +83,9 @@ public class MapDBPersistentStore implements IStore {
|
|||||||
m_db = DBMaker.newFileDB(tmpFile).make();
|
m_db = DBMaker.newFileDB(tmpFile).make();
|
||||||
}
|
}
|
||||||
LOG.info("Scheduling MapDB commit task");
|
LOG.info("Scheduling MapDB commit task");
|
||||||
m_scheduler.scheduleWithFixedDelay(new Runnable() {
|
m_scheduler.scheduleWithFixedDelay(() -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
LOG.debug("Committing to MapDB");
|
LOG.debug("Committing to MapDB");
|
||||||
m_db.commit();
|
m_db.commit();
|
||||||
}
|
|
||||||
}, this.m_autosaveInterval, this.m_autosaveInterval, TimeUnit.SECONDS);
|
}, this.m_autosaveInterval, this.m_autosaveInterval, TimeUnit.SECONDS);
|
||||||
|
|
||||||
// TODO check m_db is valid and
|
// TODO check m_db is valid and
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ class MapDBSessionsStore implements ISessionsStore, ISubscriptionsStore {
|
|||||||
Set<Integer> inFlightForClient = this.m_inFlightIds.get(clientID);
|
Set<Integer> inFlightForClient = this.m_inFlightIds.get(clientID);
|
||||||
if (inFlightForClient == null) {
|
if (inFlightForClient == null) {
|
||||||
int nextPacketId = 1;
|
int nextPacketId = 1;
|
||||||
inFlightForClient = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>());
|
inFlightForClient = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||||
inFlightForClient.add(nextPacketId);
|
inFlightForClient.add(nextPacketId);
|
||||||
this.m_inFlightIds.put(clientID, inFlightForClient);
|
this.m_inFlightIds.put(clientID, inFlightForClient);
|
||||||
return nextPacketId;
|
return nextPacketId;
|
||||||
|
|||||||
@@ -152,12 +152,7 @@ public class ProtocolDecodingServer {
|
|||||||
System.out.println("Loop server started");
|
System.out.println("Loop server started");
|
||||||
startClientsTesting();
|
startClientsTesting();
|
||||||
//Bind a shutdown hook
|
//Bind a shutdown hook
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
server.stop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startClientsTesting() throws MqttException, InterruptedException {
|
private static void startClientsTesting() throws MqttException, InterruptedException {
|
||||||
|
|||||||
+1
-6
@@ -104,12 +104,7 @@ public class ProtocolPublishDecodingServer {
|
|||||||
publishBombing();
|
publishBombing();
|
||||||
publishBombing();
|
publishBombing();
|
||||||
//Bind a shutdown hook
|
//Bind a shutdown hook
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
server.stop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void publishBombing() {
|
private static void publishBombing() {
|
||||||
|
|||||||
Reference in New Issue
Block a user