private void notifyChannelsConnected() {
   Set<Channel> channelSet = channelIndex.keySet();
   Iterator<Channel> iterator = channelSet.iterator();
   while (iterator.hasNext()) {
     Channel channel = iterator.next();
     channel.onConnect();
   }
 }
 /** Creates a channel for the bucket. Starts the websocket connection if not connected */
 @Override
 public Channel buildChannel(Bucket bucket) {
   // create a channel
   Channel channel = new Channel(mExecutor, appId, sessionId, bucket, mSerializer, this);
   int channelId = channels.size();
   channelIndex.put(channel, channelId);
   channels.put(channelId, channel);
   // If we're not connected then connect, if we don't have a user
   // access token we'll have to hold off until the user does have one
   if (!isConnected() && bucket.getUser().hasAccessToken()) {
     connect();
   } else if (isConnected()) {
     channel.onConnect();
   }
   return channel;
 }