Commit cbe51cee57b693efba9ec8b80ceca536c204021e

Authored by Sergey Matvienko
Committed by Andrew Shvayka
1 parent 607fd7a7

execute processMsgQueue on connected callback in separate thread because produce…

…r.send() will execute in Producer worker thread and can block messages producing
@@ -825,7 +825,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -825,7 +825,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
825 ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_ACCEPTED, connectMessage)); 825 ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_ACCEPTED, connectMessage));
826 deviceSessionCtx.setConnected(true); 826 deviceSessionCtx.setConnected(true);
827 log.info("[{}] Client connected!", sessionId); 827 log.info("[{}] Client connected!", sessionId);
828 - processMsgQueue(ctx); 828 + transportService.getCallbackExecutor().execute(() -> processMsgQueue(ctx)); //this callback will execute in Producer worker thread and hard or blocking work have to be submitted to the separate thread.
829 } 829 }
830 830
831 @Override 831 @Override
@@ -56,6 +56,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MC @@ -56,6 +56,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MC
56 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg; 56 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg;
57 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg; 57 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
58 58
  59 +import java.util.concurrent.ExecutorService;
  60 +
59 /** 61 /**
60 * Created by ashvayka on 04.10.18. 62 * Created by ashvayka on 04.10.18.
61 */ 63 */
@@ -131,4 +133,6 @@ public interface TransportService { @@ -131,4 +133,6 @@ public interface TransportService {
131 void log(SessionInfoProto sessionInfo, String msg); 133 void log(SessionInfoProto sessionInfo, String msg);
132 134
133 void notifyAboutUplink(SessionInfoProto sessionInfo, TransportProtos.UplinkNotificationMsg build, TransportServiceCallback<Void> empty); 135 void notifyAboutUplink(SessionInfoProto sessionInfo, TransportProtos.UplinkNotificationMsg build, TransportServiceCallback<Void> empty);
  136 +
  137 + ExecutorService getCallbackExecutor();
134 } 138 }
@@ -1141,4 +1141,9 @@ public class DefaultTransportService implements TransportService { @@ -1141,4 +1141,9 @@ public class DefaultTransportService implements TransportService {
1141 callback.onError(e); 1141 callback.onError(e);
1142 } 1142 }
1143 } 1143 }
  1144 +
  1145 + @Override
  1146 + public ExecutorService getCallbackExecutor() {
  1147 + return transportCallbackExecutor;
  1148 + }
1144 } 1149 }