Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,15 +16,26 @@

package org.springframework.integration.mqtt.event;

import org.springframework.lang.Nullable;

/**
* The {@link MqttIntegrationEvent} to notify about lost connection to the server.
* When normal disconnection is happened (initiated by the server), the {@code cause} is null.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.2.2
*
*/
@SuppressWarnings("serial")
public class MqttConnectionFailedEvent extends MqttIntegrationEvent {

public MqttConnectionFailedEvent(Object source, Throwable cause) {
public MqttConnectionFailedEvent(Object source) {
super(source);
}

public MqttConnectionFailedEvent(Object source, @Nullable Throwable cause) {
super(source, cause);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2020 the original author or authors.
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,12 +17,15 @@
package org.springframework.integration.mqtt.event;

import org.springframework.integration.events.IntegrationEvent;
import org.springframework.lang.Nullable;

/**
* Base class for Mqtt Events. For {@link #getSourceAsType()}, you should use a sub type
* Base class for Mqtt Events. For {@link #getSourceAsType()}, you should use a subtype
* of {@link org.springframework.integration.mqtt.core.MqttComponent} for the receiving
* variable.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.1
*/
Expand All @@ -33,7 +36,7 @@ public MqttIntegrationEvent(Object source) {
super(source);
}

public MqttIntegrationEvent(Object source, Throwable cause) {
public MqttIntegrationEvent(Object source, @Nullable Throwable cause) {
super(source, cause);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public void messageArrived(String topic, MqttMessage mqttMessage) {
public void disconnected(MqttDisconnectResponse disconnectResponse) {
MqttException cause = disconnectResponse.getException();
ApplicationEventPublisher applicationEventPublisher = getApplicationEventPublisher();
if (cause != null && applicationEventPublisher != null) {
if (applicationEventPublisher != null) {
applicationEventPublisher.publishEvent(new MqttConnectionFailedEvent(this, cause));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void deliveryComplete(IMqttToken token) {
public void disconnected(MqttDisconnectResponse disconnectResponse) {
MqttException cause = disconnectResponse.getException();
ApplicationEventPublisher applicationEventPublisher = getApplicationEventPublisher();
if (cause != null && applicationEventPublisher != null) {
if (applicationEventPublisher != null) {
applicationEventPublisher.publishEvent(new MqttConnectionFailedEvent(this, cause));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/reference/asciidoc/mqtt.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ public class MqttJavaApplication {
Certain application events are published by the adapters.

* `MqttConnectionFailedEvent` - published by both adapters if we fail to connect or a connection is subsequently lost.
For the MQTT v5 Paho client, this event is also emitted when the server performs a normal disconnection, in which case the `cause` of the lost connection is `null`.
* `MqttMessageSentEvent` - published by the outbound adapter when a message has been sent, if running in asynchronous mode.
* `MqttMessageDeliveredEvent` - published by the outbound adapter when the client indicates that a message has been delivered, if running in asynchronous mode.
* `MqttSubscribedEvent` - published by the inbound adapter after subscribing to the topics.
Expand Down