[ 
https://issues.apache.org/jira/browse/ARTEMIS-3445?focusedWorklogId=646032&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-646032
 ]

ASF GitHub Bot logged work on ARTEMIS-3445:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Sep/21 20:32
            Start Date: 02/Sep/21 20:32
    Worklog Time Spent: 10m 
      Work Description: clebertsuconic commented on a change in pull request 
#3714:
URL: https://github.com/apache/activemq-artemis/pull/3714#discussion_r701402855



##########
File path: 
artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTProtocolManagerFactory.java
##########
@@ -64,4 +74,46 @@ public ProtocolManager createProtocolManager(ActiveMQServer 
server,
    public String getModuleName() {
       return MODULE_NAME;
    }
+
+
+   @Override
+   public void loadProtocolServices(ActiveMQServer server, 
List<ActiveMQComponent> services) {
+      services.add(new MQTTPeriodicTasks(server.getScheduledPool()));
+   }
+
+   public class MQTTPeriodicTasks implements ActiveMQComponent {
+      ScheduledExecutorService pool;
+      Runnable runnable;
+
+      public MQTTPeriodicTasks(ScheduledExecutorService pool) {
+         this.pool = pool;
+      }
+
+      @Override
+      public void start() throws Exception {
+         runnable = () -> {
+            for (Map.Entry<String, MQTTSessionState> entry : 
sessionStates.entrySet()) {
+               MQTTSessionState state = entry.getValue();
+               MQTTLogger.LOGGER.debug("Inspecting session state: " + state);
+               if (!state.getAttached() && defaultMqttSessionExiryInterval != 
-1 && state.getDisconnectedTime() + (defaultMqttSessionExiryInterval * 1000) < 
System.currentTimeMillis()) {
+                  MQTTLogger.LOGGER.debug("Removing expired session state: " + 
state);
+                  sessionStates.remove(entry.getKey());
+               }
+            }
+         };
+         pool.scheduleAtFixedRate(runnable, 0, 5, TimeUnit.SECONDS);
+      }
+
+      @Override
+      public void stop() throws Exception {
+         if (pool instanceof ThreadPoolExecutor) {
+            ((ThreadPoolExecutor)pool).remove(runnable);

Review comment:
       the best would been to cancel on the future...
   
   but if you extend the ScheduledComponent.. it would been easier to manage 
this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 646032)
    Time Spent: 20m  (was: 10m)

> Automatically clean-up abandoned MQTT subscriptions
> ---------------------------------------------------
>
>                 Key: ARTEMIS-3445
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-3445
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Some MQTT use-cases involve clients which don't clean up their subscriptions. 
> In such situations the {{auto-delete-queues-delay}} and 
> {{auto-delete-queues-message-count}} address-settings can be used to clean up 
> the abandoned subscription queues. However, the MQTT session meta-data is 
> still present in memory and needs to be cleaned up as well.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to