public void resendNotAckedPublishes() { final Session session = sessionRegistry.retrieve(getClientId()); session.resendInflightNotAcked(); }
void sendRetainedPublishOnSessionAtQos(Topic topic, MqttQoS qos, ByteBuf payload) { if (qos != MqttQoS.AT_MOST_ONCE) { // QoS 1 or 2 mqttConnection.sendPublishRetainedWithPacketId(topic, qos, payload); } else { mqttConnection.sendPublishRetainedQos0(topic, qos, payload); } }
@Override public void initChannel(SocketChannel ch) throws Exception { pipelieInitializer.init(ch); } })
void processSubscribe(MqttSubscribeMessage msg) { final String clientID = NettyUtils.clientID(channel); if (!connected) { LOG.warn("SUBSCRIBE received on already closed connection, CId={}, channel: {}", clientID, channel); dropConnection(); return; } postOffice.subscribeClientToTopics(msg, clientID, NettyUtils.userName(channel), this); }
@Before public void setUp() { sessionRegistry = initPostOfficeAndSubsystems(); mockAuthenticator = new MockAuthenticator(singleton(FAKE_CLIENT_ID), singletonMap(TEST_USER, TEST_PWD)); connection = createMQTTConnection(ALLOW_ANONYMOUS_AND_ZERO_BYTES_CLID); connectMessage = ConnectionTestUtils.buildConnect(FAKE_CLIENT_ID); connection.processConnect(connectMessage); ConnectionTestUtils.assertConnectAccepted(channel); }
public void writabilityChanged() { if (channel.isWritable()) { LOG.debug("Channel {} is again writable", channel); final Session session = sessionRegistry.retrieve(getClientId()); session.writabilityChanged(); } }
private MQTTConnection connectNotCleanAs(String clientId) { EmbeddedChannel channel = new EmbeddedChannel(); MQTTConnection connection = createMQTTConnection(CONFIG, channel); connection.processConnect(ConnectionTestUtils.buildConnectNotClean(clientId)); ConnectionTestUtils.assertConnectAccepted(channel); return connection; }
private MQTTConnection connectAs(String clientId) { EmbeddedChannel channel = new EmbeddedChannel(); MQTTConnection connection = createMQTTConnection(CONFIG, channel); connection.processConnect(ConnectionTestUtils.buildConnect(clientId)); ConnectionTestUtils.assertConnectAccepted(channel); return connection; }
private MQTTConnection connectAs(String clientId) { EmbeddedChannel channel = new EmbeddedChannel(); MQTTConnection connection = createMQTTConnection(CONFIG, channel); connection.processConnect(ConnectionTestUtils.buildConnect(clientId)); ConnectionTestUtils.assertConnectAccepted(channel); return connection; }
@Test public void testClientSubscribeAfterDisconnected() { subscribe(AT_MOST_ONCE, "foo", connection); connection.processDisconnect(null); internalPublishTo("foo", AT_MOST_ONCE, false); verifyNoPublishIsReceived(channel); }
@Test public void testSubscribe() { connection.processConnect(connectMessage); ConnectionTestUtils.assertConnectAccepted(channel); // Exercise & verify subscribe(channel, NEWS_TOPIC, AT_MOST_ONCE); }
@Test public void testClientSubscribeBeforeRetainedQoS2IsSent() { subscribe(EXACTLY_ONCE, "/topic", connection); // Exercise internalPublishTo("/topic", EXACTLY_ONCE, true); // Verify ConnectionTestUtils.verifyPublishIsReceived(channel, EXACTLY_ONCE, PAYLOAD); }
public void disconnect(String clientID) { final Session session = retrieve(clientID); if (session == null) { LOG.debug("Some other thread already removed the session CId={}", clientID); return; } session.disconnect(); }
protected void connect(MQTTConnection connection, MqttConnectMessage connectMessage) { connection.processConnect(connectMessage); ConnectionTestUtils.assertConnectAccepted((EmbeddedChannel) connection.channel); }
@Override public void channelActive(ChannelHandlerContext ctx) { MQTTConnection connection = connectionFactory.create(ctx.channel()); mqttConnection(ctx.channel(), connection); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt instanceof InflightResender.ResendNotAckedPublishes) { final MQTTConnection mqttConnection = mqttConnection(ctx.channel()); mqttConnection.resendNotAckedPublishes(); } ctx.fireUserEventTriggered(evt); }
@Override public void channelWritabilityChanged(ChannelHandlerContext ctx) { // if (ctx.channel().isWritable()) { // m_processor.notifyChannelWritable(ctx.channel()); // } final MQTTConnection mqttConnection = mqttConnection(ctx.channel()); mqttConnection.writabilityChanged(); ctx.fireChannelWritabilityChanged(); }
protected void connect(MQTTConnection connection, String clientId) { MqttConnectMessage connectMessage = ConnectionTestUtils.buildConnect(clientId); connect(connection, connectMessage); }
public void disconnect() { final boolean res = assignState(SessionStatus.CONNECTED, SessionStatus.DISCONNECTING); if (!res) { // someone already moved away from CONNECTED // TODO what to do? return; } mqttConnection = null; will = null; assignState(SessionStatus.DISCONNECTING, SessionStatus.DISCONNECTED); }
@Test public void testClientSubscribeAfterRetainedQoS2IsSent() { // Exercise internalPublishTo("/topic", EXACTLY_ONCE, true); subscribe(EXACTLY_ONCE, "/topic", connection); // Verify ConnectionTestUtils.verifyPublishIsReceived(channel, EXACTLY_ONCE, PAYLOAD); }