Example #1
0
  @Override
  public void onReconnected() {
    log.info("reconnected");
    if (mode.contains(MODE.RESEND_SUBSCRIBE_ON_RECONNECTED)) {

      Set<String> channels;

      // channel as sourceDispatcherId
      channels = new HashSet<String>();
      channels.add(getSourceDispatcherId());
      driverImpl.subscribeChannels(channels);

      // channels as object_IDs registered with localObjectsMap
      channels = localObjectsMap.keySet();
      if (!channels.isEmpty()) {
        driverImpl.subscribeChannels(channels);
      }

      // all channels registered with subscribersMap
      channels = subscribersMap.getSubscribedChannels();
      if (!channels.isEmpty()) {
        driverImpl.subscribeChannels(channels);
      }

      // re-SUBSCRIBE completed with all the registered channels.
      pubSubDriverSuspended = false; // Resumed
    } else {
      // You may add some code here to inform other objects that
      // the network connectivity has resumed or the pubsub server
      // has become available.
    }
  }
Example #2
0
 /**
  * Channel subscription service.
  *
  * @param subscriberId Subscriber's object ID
  * @param channelsToBeSubscribed channels to be subscribed
  */
 public void subscribeChannels(
     final String subscriberId, final Map<String, Set<String>> channelsToBeSubscribed) {
   Set<String> channels = new HashSet<>();
   for (String publisherId : channelsToBeSubscribed.keySet()) {
     Set<String> eventIds = channelsToBeSubscribed.get(publisherId);
     for (String eventId : eventIds) {
       String channel = channelString(publisherId, eventId);
       if (subscribersMap.setSubscription(channel, subscriberId)) {
         channels.add(channel);
       }
     }
   }
   if (!channels.isEmpty() && !pubSubDriverSuspended) {
     driverImpl.subscribeChannels(channels);
   }
 }