Class AbstractMqttClientManager<T extends com.hivemq.client.mqtt.MqttClient, C extends com.hivemq.client.mqtt.MqttClientConfig>
java.lang.Object
org.springframework.integration.mqtt.client.core.AbstractMqttClientManager<T,C>
- Type Parameters:
T- MQTT client typeC- MQTT client config
- All Implemented Interfaces:
com.hivemq.client.mqtt.lifecycle.MqttClientConnectedListener, Aware, InitializingBean, ApplicationEventPublisherAware, Lifecycle, Phased, SmartLifecycle, ClientManager<T>
- Direct Known Subclasses:
Mqtt3ClientManager, Mqtt5ClientManager
public abstract class AbstractMqttClientManager<T extends com.hivemq.client.mqtt.MqttClient, C extends com.hivemq.client.mqtt.MqttClientConfig>
extends Object
implements ClientManager<T>, InitializingBean, SmartLifecycle, ApplicationEventPublisherAware, com.hivemq.client.mqtt.lifecycle.MqttClientConnectedListener
Abstract class for MQTT client managers which can be a base for any common v3/v5 client manager implementation.
Contains some basic utility and implementation-agnostic fields and methods.
- Since:
- 7.2
- Author:
- Jiandong Ma
-
Nested Class Summary
Nested classes/interfaces inherited from interface ClientManager
ClientManager.ConnectCallback -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Set<ClientManager.ConnectCallback> protected final Lockprotected final LogAccessorprotected final CFields inherited from interface SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCallback(ClientManager.ConnectCallback connectCallback) Register a callback for theonConnectedevent from the client.voidprotected abstract TBuild the mqttClient using the suppliedMqttClientConfig.protected com.hivemq.client.mqtt.MqttClientBuildercreateBaseClientBuilder(com.hivemq.client.mqtt.MqttClientConfig inputConfig) Create a baseMqttClientBuilderpopulated with the suppliedMqttClientConfig.protected ApplicationEventPublisherReturn the managed client.intgetPhase()The phase of component auto-start inSmartLifecycle.booleanReturn the managed clients isConnected.booleanbooleanremoveCallback(ClientManager.ConnectCallback connectCallback) Remove the callback from registration.voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) voidsetPhase(int phase) Set the phase of component autostart inSmartLifecycle.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.hivemq.client.mqtt.lifecycle.MqttClientConnectedListener
onConnectedMethods inherited from interface SmartLifecycle
isAutoStartup, isPauseable, pause, restart, stop
-
Field Details
-
logger
-
lock
-
connectCallbacks
-
mqttClientConfig
-
-
Constructor Details
-
AbstractMqttClientManager
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
buildClient
Build the mqttClient using the suppliedMqttClientConfig.- Returns:
- the mqttClient
-
createBaseClientBuilder
protected com.hivemq.client.mqtt.MqttClientBuilder createBaseClientBuilder(com.hivemq.client.mqtt.MqttClientConfig inputConfig) Create a baseMqttClientBuilderpopulated with the suppliedMqttClientConfig.- Parameters:
inputConfig- the MqttClientConfig- Returns:
- the MqttClientBuilder
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware
-
getApplicationEventPublisher
-
setPhase
public void setPhase(int phase) Set the phase of component autostart inSmartLifecycle. If the custom one is required, note that for the correct behavior it should be less than phase ofAbstractMqttMessageDrivenChannelAdapterimplementations.- See Also:
-
addCallback
Description copied from interface:ClientManagerRegister a callback for theonConnectedevent from the client.- Specified by:
addCallbackin interfaceClientManager<T extends com.hivemq.client.mqtt.MqttClient>- Parameters:
connectCallback- aClientManager.ConnectCallbackto register.
-
removeCallback
Description copied from interface:ClientManagerRemove the callback from registration.- Specified by:
removeCallbackin interfaceClientManager<T extends com.hivemq.client.mqtt.MqttClient>- Parameters:
connectCallback- aClientManager.ConnectCallbackto unregister.- Returns:
- true if callback was removed.
-
getClient
Description copied from interface:ClientManagerReturn the managed client.- Specified by:
getClientin interfaceClientManager<T extends com.hivemq.client.mqtt.MqttClient>- Returns:
- the managed client.
-
getPhase
public int getPhase()The phase of component auto-start inSmartLifecycle. If the custom one is required, note that for the correct behavior it should be less than phase ofAbstractMqttMessageDrivenChannelAdapterimplementations. The default phase isDEFAULT_MANAGER_PHASE.- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle- Returns:
SmartLifecycleautostart phase- See Also:
-
isRunning
-
isConnected
public boolean isConnected()Description copied from interface:ClientManagerReturn the managed clients isConnected.- Specified by:
isConnectedin interfaceClientManager<T extends com.hivemq.client.mqtt.MqttClient>- Returns:
- the managed clients isConnected.
-