APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:For S9
版本号:4.5
包名称:com.jb.gokeyboard.theme.emojiztfors9.getjar

MD5 校验值:27cf44ec6e0720408f5ef017a90a3331

反编译源代码说明

HttpConnectScheduler.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package com.gau.utils.net;

import android.content.Context;
import android.os.Build;
import com.gau.utils.net.connector.AbstractConnector;
import com.gau.utils.net.connector.ConnectorFactory;
import com.gau.utils.net.request.THttpRequest;
import com.gau.utils.net.response.IResponse;
import com.gau.utils.net.util.NetLog;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpResponse;

public class HttpConnectScheduler implements IConnectListener {
    private ConnectorFactory mConnectorFactory;
    private Context mContext;
    private int mMaxConnectThreadNum = 2;
    private List<THttpRequest> mWaitRequestList = new ArrayList();
    private List<THttpRequest> mCurrentRequestlist = new ArrayList();
    private byte[] mLock = new byte[0];

    public HttpConnectScheduler(Context context) throws IllegalArgumentException {
        if (context == null) {
            throw new IllegalArgumentException("context must have value");
        }
        this.mContext = context;
        this.mConnectorFactory = new ConnectorFactory();
    }

    public void addRequest(THttpRequest tHttpRequest) {
        if (tHttpRequest == null) {
            throw new IllegalArgumentException("Addrequest must have request");
        }
        synchronized (this.mLock) {
            if (tHttpRequest.getIsAsync()) {
                this.mWaitRequestList.add(tHttpRequest);
                if (Build.VERSION.SDK_INT >= 9) {
                    Collections.sort(this.mWaitRequestList, new Comparator<THttpRequest>() {
                        @Override
                        public int compare(THttpRequest tHttpRequest2, THttpRequest tHttpRequest3) {
                            if (tHttpRequest2.getRequestPriority() < tHttpRequest3.getRequestPriority()) {
                                return 1;
                            }
                            if (tHttpRequest2.getRequestPriority() > tHttpRequest3.getRequestPriority()) {
                                return -1;
                            }
                            return 0;
                        }
                    });
                }
                connect();
            } else {
                connect(tHttpRequest);
            }
        }
    }

    public void cleanup() {
        if (this.mConnectorFactory != null) {
            this.mConnectorFactory.cleanup();
        }
    }

    public int getMaxConnectThreadNum() {
        return this.mMaxConnectThreadNum;
    }

    public void setMaxConnectThreadNum(int i) {
        this.mMaxConnectThreadNum = i;
    }

    public String putCommonHeartUrl(String str, String str2) {
        if (this.mConnectorFactory != null) {
            return this.mConnectorFactory.putCommonHeartUrl(str, str2);
        }
        return null;
    }

    public String removeHeartUrl(String str) {
        if (this.mConnectorFactory != null) {
            return this.mConnectorFactory.removeHeartUrl(str);
        }
        return null;
    }

    public String getHeartUrl(String str) {
        if (this.mConnectorFactory != null) {
            return this.mConnectorFactory.getHeartUrl(str);
        }
        return null;
    }

    public Map<String, String> getAllCommonHeartUrl() {
        if (this.mConnectorFactory != null) {
            return this.mConnectorFactory.getAllHeartUrl();
        }
        return null;
    }

    public void setCommonHeartTime(long j) {
        if (this.mConnectorFactory != null) {
            this.mConnectorFactory.setCommonHeartTime(j);
        }
    }

    public long getCommonHeartTime() {
        if (this.mConnectorFactory != null) {
            return this.mConnectorFactory.getCommonHeartTime();
        }
        return -1L;
    }

    public THttpRequest isExistEqualRequest(String str, List<THttpRequest> list) {
        if (str == null || list == null || list.size() <= 0) {
            return null;
        }
        for (THttpRequest tHttpRequest : list) {
            URI url = tHttpRequest.getUrl();
            if (url != null && url.toString() != null && url.toString().equals(str)) {
                return tHttpRequest;
            }
        }
        return null;
    }

    private THttpRequest isExistRequests(String str, List<THttpRequest> list) {
        URI url;
        if (str == null || list == null || list.isEmpty()) {
            return null;
        }
        for (THttpRequest tHttpRequest : list) {
            if (tHttpRequest != null && (url = tHttpRequest.getUrl()) != null && url.toString() != null && url.toString().equals(str)) {
                return tHttpRequest;
            }
        }
        return null;
    }

    public boolean cancelRequest(String str) {
        THttpRequest isExistRequests;
        boolean z = false;
        if (str != null && str.length() >= 1) {
            synchronized (this.mLock) {
                boolean remove = (this.mWaitRequestList == null || this.mWaitRequestList.isEmpty() || (isExistRequests = isExistRequests(str, this.mWaitRequestList)) == null) ? false : this.mWaitRequestList.remove(isExistRequests);
                if (!remove && this.mCurrentRequestlist != null && !this.mCurrentRequestlist.isEmpty()) {
                    THttpRequest isExistRequests2 = isExistRequests(str, this.mCurrentRequestlist);
                    if (isExistRequests2 != null && this.mConnectorFactory != null) {
                        isExistRequests2.setCanceled(true);
                        AbstractConnector isExistConnector = this.mConnectorFactory.isExistConnector(isExistRequests2);
                        if (isExistConnector != null) {
                            isExistConnector.cancelCurrentConnect();
                            this.mConnectorFactory.removeConnectorByRequest(isExistRequests2);
                            z = true;
                        }
                    }
                }
                z = remove;
            }
        }
        return z;
    }

    public boolean cancelRequest(THttpRequest tHttpRequest) {
        boolean z = false;
        if (tHttpRequest != null) {
            synchronized (this.mLock) {
                if (this.mWaitRequestList != null && !this.mWaitRequestList.isEmpty()) {
                    z = this.mWaitRequestList.remove(tHttpRequest);
                }
                if (!z && this.mCurrentRequestlist != null && !this.mCurrentRequestlist.isEmpty()) {
                    tHttpRequest.setCanceled(true);
                    AbstractConnector isExistConnector = this.mConnectorFactory.isExistConnector(tHttpRequest);
                    if (isExistConnector != null) {
                        isExistConnector.cancelCurrentConnect();
                        this.mConnectorFactory.removeConnectorByRequest(tHttpRequest);
                        z = true;
                    }
                }
            }
        }
        return z;
    }

    @Override
    public void onFinish(THttpRequest tHttpRequest, IResponse iResponse) {
        NetLog.info("schedule onFinish", null);
        NetLog.info("testBattery, Begin HttpConnectScheduler onFinish", null);
        if (tHttpRequest != null) {
            tHttpRequest.getReceiver().onFinish(tHttpRequest, iResponse);
            synchronized (this.mLock) {
                if (this.mCurrentRequestlist != null && !this.mCurrentRequestlist.isEmpty()) {
                    this.mCurrentRequestlist.remove(tHttpRequest);
                    if (this.mConnectorFactory != null) {
                        this.mConnectorFactory.removeConnectorByRequest(tHttpRequest);
                    }
                }
            }
            tick();
            NetLog.info("testBattery, End HttpConnectScheduler onFinish", null);
        }
    }

    @Override
    public void onStart(THttpRequest tHttpRequest) {
        tHttpRequest.getReceiver().onStart(tHttpRequest);
    }

    @Override
    public void onException(THttpRequest tHttpRequest, int i) {
        NetLog.info("schedule onException", null);
        NetLog.info("testBattery, Begin HttpConnectScheduler onException", null);
        if (tHttpRequest != null) {
            IConnectListener receiver = tHttpRequest.getReceiver();
            if (receiver != null) {
                receiver.onException(tHttpRequest, i);
            }
            synchronized (this.mLock) {
                if (this.mCurrentRequestlist != null && !this.mCurrentRequestlist.isEmpty()) {
                    this.mCurrentRequestlist.remove(tHttpRequest);
                    if (this.mConnectorFactory != null) {
                        this.mConnectorFactory.removeConnectorByRequest(tHttpRequest);
                    }
                }
            }
            tick();
            NetLog.info("testBattery, End HttpConnectScheduler onException", null);
        }
    }

    private void tick() {
        synchronized (this.mLock) {
            NetLog.info("testBattery, Begin HttpConnectScheduler tick", null);
            connect();
            NetLog.info("testBattery, end HttpConnectScheduler tick", null);
        }
    }

    private void connect() {
        int size;
        if (this.mWaitRequestList != null && !this.mWaitRequestList.isEmpty() && this.mCurrentRequestlist != null && (size = this.mCurrentRequestlist.size()) < this.mMaxConnectThreadNum) {
            for (int i = 0; i < this.mMaxConnectThreadNum - size && !this.mWaitRequestList.isEmpty(); i++) {
            }
            THttpRequest remove = this.mWaitRequestList.remove(0);
            if (remove != null) {
                this.mCurrentRequestlist.add(remove);
                connect(remove);
            }
        }
    }

    private void connect(THttpRequest tHttpRequest) {
        AbstractConnector productConnector = this.mConnectorFactory.productConnector(tHttpRequest, this, this.mContext);
        if (productConnector != null) {
            if (productConnector.getRequset().getIsAsync()) {
                productConnector.connectAsynchronous();
            } else {
                productConnector.connect();
            }
        }
    }

    @Override
    public void onException(THttpRequest tHttpRequest, HttpResponse httpResponse, int i) {
        onException(tHttpRequest, i);
    }
}