翰林优商.apk(点击下载) / Senduobus.java


package com.xlx.speech.voicereadsdk.senduobus;

import com.xlx.speech.l.a;
import com.xlx.speech.m.e;
import com.xlx.speech.m.f;
import com.xlx.speech.m.g;
import com.xlx.speech.m.h;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Senduobus {
    private static final Senduobus ourInstance = new Senduobus();
    private Map<Object, List<SubscribeMethod>> cacheMap = new HashMap();
    private Map<Object, Disposable> disposableMap = new HashMap();

    /* renamed from: com.xlx.speech.voicereadsdk.senduobus.Senduobus$2  reason: invalid class name */
    public static /* synthetic */ class AnonymousClass2 {
        public static final /* synthetic */ int[] $SwitchMap$com$xlx$speech$voicereadsdk$senduobus$ThreadMode;

        /* JADX WARNING: Can't wrap try/catch for region: R(8:0|1|2|3|4|5|6|(3:7|8|10)) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0012 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x001d */
        /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x0028 */
        static {
            int[] iArr = new int[ThreadMode.values().length];
            $SwitchMap$com$xlx$speech$voicereadsdk$senduobus$ThreadMode = iArr;
            iArr[ThreadMode.Async.ordinal()] = 1;
            $SwitchMap$com$xlx$speech$voicereadsdk$senduobus$ThreadMode[ThreadMode.MainThread.ordinal()] = 2;
            $SwitchMap$com$xlx$speech$voicereadsdk$senduobus$ThreadMode[ThreadMode.BackgroundThread.ordinal()] = 3;
            try {
                $SwitchMap$com$xlx$speech$voicereadsdk$senduobus$ThreadMode[ThreadMode.PostThread.ordinal()] = 4;
            } catch (NoSuchFieldError unused) {
            }
        }
    }

    private Senduobus() {
    }

    public static Senduobus getDefault() {
        return ourInstance;
    }

    private Schedule getInvokeSchedule(ThreadMode threadMode) {
        int i = AnonymousClass2.$SwitchMap$com$xlx$speech$voicereadsdk$senduobus$ThreadMode[threadMode.ordinal()];
        if (i == 1) {
            return e.a;
        }
        if (i != 2) {
            return i != 3 ? h.a : f.a;
        }
        return g.a;
    }

    private List<SubscribeMethod> getSubscribeMethods(Object obj) {
        ArrayList arrayList = new ArrayList();
        for (Class<?> cls = obj.getClass(); cls != null; cls = cls.getSuperclass()) {
            String name = cls.getName();
            if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) {
                break;
            }
            Method[] declaredMethods = cls.getDeclaredMethods();
            for (Method method : declaredMethods) {
                Subscribe subscribe = (Subscribe) method.getAnnotation(Subscribe.class);
                if (subscribe != null) {
                    Class<?>[] parameterTypes = method.getParameterTypes();
                    if (parameterTypes.length == 1) {
                        arrayList.add(new SubscribeMethod(method, subscribe.threadMode(), parameterTypes[0]));
                    } else {
                        throw new RuntimeException("senduobus 只能接收到一个参数");
                    }
                }
            }
        }
        return arrayList;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void invoke(SubscribeMethod subscribeMethod, Object obj, Object obj2) {
        try {
            subscribeMethod.getMethod().invoke(obj, obj2);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e2) {
            e2.printStackTrace();
        }
    }

    private void transmit(Object obj, Schedule schedule, Runnable runnable) {
        a submit = schedule.submit(runnable);
        Disposable disposable = this.disposableMap.get(obj);
        if (disposable == null) {
            disposable = new Disposable();
            this.disposableMap.put(obj, disposable);
        }
        disposable.add(submit);
    }

    public void post(final Object obj) {
        for (final Object obj2 : this.cacheMap.keySet()) {
            for (final SubscribeMethod subscribeMethod : this.cacheMap.get(obj2)) {
                if (subscribeMethod.getEventType().isAssignableFrom(obj.getClass())) {
                    transmit(obj2, getInvokeSchedule(subscribeMethod.getThreadMode()), new Runnable() {
                        /* class com.xlx.speech.voicereadsdk.senduobus.Senduobus.AnonymousClass1 */

                        public void run() {
                            Senduobus.this.invoke(subscribeMethod, obj2, obj);
                        }
                    });
                }
            }
        }
    }

    public void register(Object obj) {
        if (this.cacheMap.get(obj) == null) {
            this.cacheMap.put(obj, getSubscribeMethods(obj));
        }
    }

    public void unregister(Object obj) {
        this.cacheMap.remove(obj);
        Disposable remove = this.disposableMap.remove(obj);
        if (remove != null) {
            remove.dispose();
        }
    }
}