// Path: Simperium/src/main/java/com/simperium/SimperiumException.java
// public class SimperiumException extends Exception {
//   public SimperiumException() { super(); }
//   public SimperiumException(String message) { super(message); }
//   public SimperiumException(String message, Throwable cause) { super(message, cause); }
//   public SimperiumException(Throwable cause) { super(cause); }
// }
// 
// Path: Simperium/src/main/java/com/simperium/util/Logger.java
// public class Logger {
// 
//     public static final String TAG = "Simperium";
// 
//     public static final void log(String msg){
//         Log.d(TAG, msg);
//     }
// 
//     public static final void log(String tag, String msg){
//         Log.d(tag, msg);
//     }
// 
//     public static final void log(String msg, Throwable error){
//         Log.e(TAG, msg, error);
//     }
// 
//     public static final void log(String tag, String msg, Throwable error){
//         Log.e(tag, msg, error);
//     }
// 
// }


import com.simperium.BuildConfig;
import com.simperium.SimperiumException;
import com.simperium.Version;
import com.simperium.util.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EventObject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TreeMap;
import java.util.concurrent.Executor;
import android.util.Log;
        public SerializedQueue(Map<String,Change> pendingChanges, List<Change> queuedChanges) {
            this.pending = pendingChanges;
            this.queued = queuedChanges;
        }
    }

    public Channel(Executor executor, String appId, String sessionId, final Bucket bucket, Serializer serializer, OnMessageListener listener) {
        mExecutor = executor;
        mSerializer = serializer;
        mAppId = appId;
        mSessionId = sessionId;
        mBucket = bucket;
        mListener = listener;
        // Receive auth: command
        command(COMMAND_AUTH, new Command() {
            public void execute(String param) {
                User user = getUser();
                // ignore auth:expired, implement new auth:{JSON} for failures
                if(EXPIRED_AUTH.equals(param.trim())) return;
                // if it starts with { let's see if it's error JSON
                if (param.indexOf(EXPIRED_AUTH_INDICATOR) == 0) {
                    try {
                        JSONObject authResponse = new JSONObject(param);
                        int code = authResponse.getInt(EXPIRED_AUTH_CODE_KEY);
                        if (code == EXPIRED_AUTH_INVALID_TOKEN_CODE || code == EXPIRED_AUTH_MALFORMED_TOKEN_CODE) {
                            user.setStatus(User.Status.NOT_AUTHORIZED);
                            stop();
                            return;
                        } else {
                            // TODO retry auth?
// Path: Simperium/src/main/java/com/simperium/SimperiumException.java
// public class SimperiumException extends Exception {
//   public SimperiumException() { super(); }
//   public SimperiumException(String message) { super(message); }
//   public SimperiumException(String message, Throwable cause) { super(message, cause); }
//   public SimperiumException(Throwable cause) { super(cause); }
// }
// 
// Path: Simperium/src/main/java/com/simperium/util/Logger.java
// public class Logger {
// 
//     public static final String TAG = "Simperium";
// 
//     public static final void log(String msg){
//         Log.d(TAG, msg);
//     }
// 
//     public static final void log(String tag, String msg){
//         Log.d(tag, msg);
//     }
// 
//     public static final void log(String msg, Throwable error){
//         Log.e(TAG, msg, error);
//     }
// 
//     public static final void log(String tag, String msg, Throwable error){
//         Log.e(tag, msg, error);
//     }
// 
// }


// Path: Simperium/src/main/java/com/simperium/client/Channel.java
import com.simperium.BuildConfig;
import com.simperium.SimperiumException;
import com.simperium.Version;
import com.simperium.util.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EventObject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TreeMap;
import java.util.concurrent.Executor;
import android.util.Log;

        public SerializedQueue(Map<String,Change> pendingChanges, List<Change> queuedChanges) {
            this.pending = pendingChanges;
            this.queued = queuedChanges;
        }
    }

    public Channel(Executor executor, String appId, String sessionId, final Bucket bucket, Serializer serializer, OnMessageListener listener) {
        mExecutor = executor;
        mSerializer = serializer;
        mAppId = appId;
        mSessionId = sessionId;
        mBucket = bucket;
        mListener = listener;
        // Receive auth: command
        command(COMMAND_AUTH, new Command() {
            public void execute(String param) {
                User user = getUser();
                // ignore auth:expired, implement new auth:{JSON} for failures
                if(EXPIRED_AUTH.equals(param.trim())) return;
                // if it starts with { let's see if it's error JSON
                if (param.indexOf(EXPIRED_AUTH_INDICATOR) == 0) {
                    try {
                        JSONObject authResponse = new JSONObject(param);
                        int code = authResponse.getInt(EXPIRED_AUTH_CODE_KEY);
                        if (code == EXPIRED_AUTH_INVALID_TOKEN_CODE || code == EXPIRED_AUTH_MALFORMED_TOKEN_CODE) {
                            user.setStatus(User.Status.NOT_AUTHORIZED);
                            stop();
                            return;
                        } else {
                            // TODO retry auth?
                            Logger.log(TAG, String.format("Unable to auth: %d", code));