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 type
C - 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
  • Field Details

    • logger

      protected final LogAccessor logger
    • lock

      protected final Lock lock
    • connectCallbacks

      protected final Set<ClientManager.ConnectCallback> connectCallbacks
    • mqttClientConfig

      protected final C extends com.hivemq.client.mqtt.MqttClientConfig mqttClientConfig
  • Constructor Details

    • AbstractMqttClientManager

      protected AbstractMqttClientManager(C mqttClientConfig)
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • buildClient

      protected abstract T buildClient()
      Build the mqttClient using the supplied MqttClientConfig.
      Returns:
      the mqttClient
    • createBaseClientBuilder

      protected com.hivemq.client.mqtt.MqttClientBuilder createBaseClientBuilder(com.hivemq.client.mqtt.MqttClientConfig inputConfig)
      Create a base MqttClientBuilder populated with the supplied MqttClientConfig.
      Parameters:
      inputConfig - the MqttClientConfig
      Returns:
      the MqttClientBuilder
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface ApplicationEventPublisherAware
    • getApplicationEventPublisher

      protected ApplicationEventPublisher getApplicationEventPublisher()
    • setPhase

      public void setPhase(int phase)
      Set the phase of component autostart in SmartLifecycle. If the custom one is required, note that for the correct behavior it should be less than phase of AbstractMqttMessageDrivenChannelAdapter implementations.
      See Also:
    • addCallback

      public void addCallback(ClientManager.ConnectCallback connectCallback)
      Description copied from interface: ClientManager
      Register a callback for the onConnected event from the client.
      Specified by:
      addCallback in interface ClientManager<T extends com.hivemq.client.mqtt.MqttClient>
      Parameters:
      connectCallback - a ClientManager.ConnectCallback to register.
    • removeCallback

      public boolean removeCallback(ClientManager.ConnectCallback connectCallback)
      Description copied from interface: ClientManager
      Remove the callback from registration.
      Specified by:
      removeCallback in interface ClientManager<T extends com.hivemq.client.mqtt.MqttClient>
      Parameters:
      connectCallback - a ClientManager.ConnectCallback to unregister.
      Returns:
      true if callback was removed.
    • getClient

      public T getClient()
      Description copied from interface: ClientManager
      Return the managed client.
      Specified by:
      getClient in interface ClientManager<T extends com.hivemq.client.mqtt.MqttClient>
      Returns:
      the managed client.
    • getPhase

      public int getPhase()
      The phase of component auto-start in SmartLifecycle. If the custom one is required, note that for the correct behavior it should be less than phase of AbstractMqttMessageDrivenChannelAdapter implementations. The default phase is DEFAULT_MANAGER_PHASE.
      Specified by:
      getPhase in interface Phased
      Specified by:
      getPhase in interface SmartLifecycle
      Returns:
      SmartLifecycle autostart phase
      See Also:
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
    • isConnected

      public boolean isConnected()
      Description copied from interface: ClientManager
      Return the managed clients isConnected.
      Specified by:
      isConnected in interface ClientManager<T extends com.hivemq.client.mqtt.MqttClient>
      Returns:
      the managed clients isConnected.