// Sends the given presence event to all Consumers that are subscribed to that channel
 private void dispatchPresenceEvent(
     String channelId, String channelName, String eventName, Object data) {
   Set<PusherClientConsumer> consumers = presenceChannelConsumers.get(channelId);
   for (PusherClientConsumer consumer : consumers) {
     try {
       consumer.handleEvent(channelName, eventName, data);
     } catch (Exception e) {
       LOG.error("Error dispatching {} event to consumer {}", new Object[] {eventName, consumer});
     }
   }
 }
 public void registerForPresenceEvents(PusherClientConsumer consumer) {
   String channelName = consumer.getEndpoint().getChannel().getName();
   String channelId = consumer.getEndpoint().getChannelId();
   // Add to collection for presence channel consumers for this channelId, so that
   // the consumer will be triggered when we receive presence events on this channel
   addToPresenceChannelConsumers(channelId, consumer);
   // Trigger synthetic subscription succeeded event, so that the first message the consumer
   // receives
   // will be a list of all users currently present
   consumer.handleEvent(
       channelName, SUBSCRIPTION_SUCCEEDED_EVENT, presenceChannelUsers.get(channelId));
 }