Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.pubnub.api;
  
  
  import  org.json.JSONArray;

Author(s):
PubnubCore
 
 class Subscriptions {
     private Hashtable channels;
 
     public Subscriptions() {
          = new Hashtable();
     }
 
     public void addChannel(Channel channel) {
         .put(channel.namechannel);
     }
 
     public void removeChannel(String name) {
         .remove(name);
     }
 
     public void removeAllChannels() {
         .clear();
     }
 
     public Channel getFirstChannel() {
         Channel ch = null;
         synchronized () {
             if (.size() > 0) {
                 ch = (Channel.elements().nextElement();
             }
         }
         return ch;
 
     }
 
     public Channel getChannel(String name) {
         return (Channel.get(name);
     }
 
     public String[] getChannelNames() {
 
         return PubnubUtil.hashtableKeysToArray();
     }
 
     public String getChannelString() {
         return PubnubUtil.hashTableKeysToDelimitedString(",");
 
     }
 
     public void invokeConnectCallbackOnChannels(Object message) {
         invokeConnectCallbackOnChannels(getChannelNames(), message);
     }
 
     public void invokeDisconnectCallbackOnChannels(Object message) {
     }
 
     public void invokeErrorCallbackOnChannels(PubnubError error) {
         /*
          * Iterate over all the channels and call error callback for channels
          */
         synchronized () {
             Enumeration ch = .elements();
             while (ch.hasMoreElements()) {
                 Channel _channel = (Channelch.nextElement();
                 _channel.error = true;
                 _channel.callback.errorCallback(_channel.nameerror);
             }
         }
     }
 
     public void invokeConnectCallbackOnChannels(String[] channelsObject message) {
         synchronized (channels) {
             for (int i = 0; i < channels.lengthi++) {
                 Channel _channel = (Channelthis..get(channels[i]);
                 if (_channel != null) {
                     if (_channel.connected == false) {
                         _channel.connected = true;
                         if (_channel.subscribed == false) {
                             _channel.callback.connectCallback(_channel.name,
                                     new JSONArray().put(1).put("Subscribe connected").put(message));
                         } else {
                             _channel.subscribed = true;
                             _channel.callback.reconnectCallback(_channel.name,
                                     new JSONArray().put(1).put("Subscribe reconnected").put(message));
                         }
                     }
                 }
             }
         }
     }
 
     public void invokeReconnectCallbackOnChannels(Object message) {
    }
    public void invokeReconnectCallbackOnChannels(String[] channelsObject message) {
        synchronized (channels) {
            for (int i = 0; i < channels.lengthi++) {
                Channel _channel = (Channelthis..get(channels[i]);
                if (_channel != null) {
                    _channel.connected = true;
                    if ( _channel.error ) {
                        _channel.callback.reconnectCallback(_channel.name,
                                new JSONArray().put(1).put("Subscribe reconnected").put(message));
                        _channel.error = false;
                    }
                }
            }
        }
    }
    public void invokeDisconnectCallbackOnChannels(String[] channelsObject message) {
        synchronized (channels) {
            for (int i = 0; i < channels.lengthi++) {
                Channel _channel = (Channelthis..get(channels[i]);
                if (_channel != null) {
                    if (_channel.connected == true) {
                        _channel.connected = false;
                        _channel.callback.disconnectCallback(_channel.name,
                                new JSONArray().put(0).put("Subscribe unable to connect").put(message));
                    }
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X