View Javadoc
1   /*
2    * The coLAB project
3    * Copyright (C) 2021-2023 AlbaSim, MEI, HEIG-VD, HES-SO
4    *
5    * Licensed under the MIT License
6    */
7   package ch.colabproject.colab.api.controller;
8   
9   import ch.colabproject.colab.api.microchanges.live.LiveManager;
10  import java.util.Map;
11  import jakarta.ejb.Singleton;
12  import jakarta.ejb.Startup;
13  import jakarta.inject.Inject;
14  import org.slf4j.Logger;
15  import org.slf4j.LoggerFactory;
16  
17  /**
18   * Single which give access to the CDI world.
19   *
20   * @author maxence
21   */
22  @Singleton
23  @Startup
24  public class CdiBridgeSingleton {
25  
26      /**
27       * Logger. Default level, set in logback.xml, is INFO
28       */
29      private static final Logger logger = LoggerFactory.getLogger(CdiBridgeSingleton.class);
30  
31      /**
32       * Websockets
33       */
34      @Inject
35      private WebsocketManager websocketManager;
36  
37      /**
38       * LiveManager
39       */
40      @Inject
41      private LiveManager liveManager;
42  
43      /**
44       * Initialize the non-CDI bean
45       */
46      public void init() {
47          /* no iop */
48      }
49  
50      /**
51       * Bridge to {@link WebsocketManager#getSubscriptionsCount() }
52       *
53       * @return the list of channels and the number of sessions subscribed to each of them
54       */
55      public Map<String, Integer> getSubscriptionsCount() {
56          logger.debug("Get bridged Subscriptions");
57          return websocketManager.getSubscriptionsCount();
58      }
59  
60      /**
61       * Bridge to {@link LiveManager#cancelDebounce(java.lang.Long) }
62       * <p>
63       * Cancel any debounce call related to the given blockId
64       *
65       * @param id id of the block
66       *
67       * @return true if there was something to cancel
68       */
69      public Boolean cancelDebounce(Long id) {
70          return liveManager.cancelDebounce(id);
71      }
72  
73      /**
74       * Bridge to {@link LiveManager#process(java.lang.Long) }.
75       * <p>
76       * Process all pending changes and save new value to database.
77       *
78       * @param id id of the block to process
79       */
80      public void processMicroChanges(Long id) {
81          liveManager.process(id);
82      }
83  
84  }