111
hxb
2022-11-24 0a3e07f10937484145f33c7560607b4b2353cb81
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.mm.android.deviceaddmodule.mobilecommon.AppConsume;
 
import android.os.Handler;
 
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorCode;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
import com.mm.android.deviceaddmodule.mobilecommon.utils.LogUtil;
 
import java.lang.ref.WeakReference;
 
public abstract class BusinessRunnable implements Runnable {
 
    private WeakReference<Handler> mHandler;
 
    public BusinessRunnable(Handler handle) {
        mHandler = new WeakReference<>(handle);
        Handler handler = getHander();
        if (handler != null && handler instanceof DHBaseHandler) {
            ((DHBaseHandler) handler).onStart();
        }
        ThreadPool.submit(this);
    }
 
    public Handler getHander() {
        return mHandler.get();
    }
 
    @Override
    public void run() {
        try {
            doBusiness();
        } catch (BusinessException e) {
            Handler handler = getHander();
            LogUtil.debugLog("BusinessRunnable", "hander == null ? " + (handler == null));
            if (handler != null) {
                handler.obtainMessage(HandleMessageCode.HMC_EXCEPTION,
                        e.errorCode, e.errorCode, e).sendToTarget();
 
            }
 
        } catch (Exception e) {
            LogUtil.debugLog("HsviewResponse Exception", e.getMessage());
            Handler handler = getHander();
            if (handler != null) {
                handler.obtainMessage(HandleMessageCode.HMC_EXCEPTION,
                        BusinessErrorCode.BEC_COMMON_UNKNOWN,
                        BusinessErrorCode.BEC_COMMON_UNKNOWN,new BusinessException(e)).sendToTarget();
            }
        }
    }
 
    public abstract void doBusiness() throws BusinessException;
}