/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.LicenseManager
 *  com.l7tech.util.Background
 *  com.l7tech.util.ExceptionUtils
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 *  org.springframework.beans.BeansException
 *  org.springframework.beans.factory.DisposableBean
 *  org.springframework.beans.factory.InitializingBean
 *  org.springframework.context.ApplicationContext
 *  org.springframework.context.ApplicationContextAware
 *  org.springframework.context.ApplicationEvent
 */
package com.l7tech.server;

import com.l7tech.gateway.common.LicenseManager;
import com.l7tech.server.Lifecycle;
import com.l7tech.server.LifecycleException;
import com.l7tech.server.ServerComponentLifecycle;
import com.l7tech.server.aq;
import com.l7tech.server.b5;
import com.l7tech.server.event.system.LicenseChangeEvent;
import com.l7tech.server.event.system.Stopped;
import com.l7tech.server.util.ApplicationEventProxy;
import com.l7tech.util.Background;
import com.l7tech.util.ExceptionUtils;
import java.util.TimerTask;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;

/*
 * Exception performing whole class analysis ignored.
 */
public abstract class LifecycleBean
implements Lifecycle,
InitializingBean,
ApplicationContextAware,
ServerComponentLifecycle,
DisposableBean {
    private final Logger a;
    private final String b;
    private final String c;
    private boolean d;
    private final ReadWriteLock e;
    private ApplicationContext f;
    private LicenseManager g;
    private static final String[] R;

    public void afterPropertiesSet() throws Exception {
        this.init();
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (this.f == null) {
            this.f = applicationContext;
            ApplicationEventProxy applicationEventProxy = (ApplicationEventProxy)applicationContext.getBean(R[1], ApplicationEventProxy.class);
            applicationEventProxy.addApplicationListener(new aq(this));
        }
    }

    public boolean isLicensed() {
        boolean bl2;
        block2: {
            bl2 = false;
            try {
                if (this.c != null && !this.g.isFeatureEnabled(this.c)) break block2;
            }
            catch (BeansException beansException) {
                throw LifecycleBean.b((Exception)((Object)beansException));
            }
            bl2 = true;
        }
        return bl2;
    }

    @Override
    public final void start() throws LifecycleException {
        try {
            if (this.isStarted()) {
                return;
            }
        }
        catch (LifecycleException lifecycleException) {
            throw LifecycleBean.b(lifecycleException);
        }
        if (this.isLicensed()) {
            this.e.writeLock().lock();
            try {
                if (this.isStarted()) {
                    return;
                }
                this.doStart();
                this.d = true;
            }
            finally {
                this.e.writeLock().unlock();
            }
        }
    }

    @Override
    public final void stop() throws LifecycleException {
        try {
            if (!this.isStarted()) {
                return;
            }
        }
        catch (LifecycleException lifecycleException) {
            throw LifecycleBean.b(lifecycleException);
        }
        this.e.writeLock().lock();
        try {
            if (!this.isStarted()) {
                return;
            }
            this.doStop();
            this.d = false;
        }
        finally {
            this.e.writeLock().unlock();
        }
    }

    @Override
    public void close() throws LifecycleException {
        this.doClose();
    }

    public void destroy() throws Exception {
        this.stop();
        this.close();
    }

    protected boolean isStartingByAnotherThread() {
        boolean bl2;
        block7: {
            block6: {
                try {
                    try {
                        try {
                            if (this.d || !((ReentrantReadWriteLock)this.e).isWriteLocked()) break block6;
                        }
                        catch (BeansException beansException) {
                            throw LifecycleBean.b((Exception)((Object)beansException));
                        }
                        if (((ReentrantReadWriteLock)this.e).writeLock().isHeldByCurrentThread()) break block6;
                    }
                    catch (BeansException beansException) {
                        throw LifecycleBean.b((Exception)((Object)beansException));
                    }
                    bl2 = true;
                    break block7;
                }
                catch (BeansException beansException) {
                    throw LifecycleBean.b((Exception)((Object)beansException));
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    protected boolean isStoppingByAnotherThread() {
        boolean bl2;
        block7: {
            block6: {
                try {
                    try {
                        try {
                            if (!this.d || !((ReentrantReadWriteLock)this.e).isWriteLocked()) break block6;
                        }
                        catch (BeansException beansException) {
                            throw LifecycleBean.b((Exception)((Object)beansException));
                        }
                        if (((ReentrantReadWriteLock)this.e).writeLock().isHeldByCurrentThread()) break block6;
                    }
                    catch (BeansException beansException) {
                        throw LifecycleBean.b((Exception)((Object)beansException));
                    }
                    bl2 = true;
                    break block7;
                }
                catch (BeansException beansException) {
                    throw LifecycleBean.b((Exception)((Object)beansException));
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    public boolean isStarted() {
        this.e.readLock().lock();
        try {
            boolean bl2 = this.d;
            return bl2;
        }
        finally {
            this.e.readLock().unlock();
        }
    }

    public String toString() {
        return this.b;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    protected LifecycleBean(@NotNull String string, @NotNull Logger logger, @NotNull String string2, @Nullable LicenseManager licenseManager) {
        if (string == null) {
            LifecycleBean.a(0);
        }
        if (logger == null) {
            LifecycleBean.a(1);
        }
        if (string2 == null) {
            LifecycleBean.a(2);
        }
        this.e = new ReentrantReadWriteLock(false);
        this.b = string;
        this.a = logger;
        this.c = string2;
        this.g = licenseManager;
        this.e.writeLock().lock();
        try {
            this.d = false;
        }
        finally {
            this.e.writeLock().unlock();
        }
    }

    protected void setLicenseManager(LicenseManager licenseManager) {
        try {
            if (this.g == null) {
                this.g = licenseManager;
            }
        }
        catch (BeansException beansException) {
            throw LifecycleBean.b((Exception)((Object)beansException));
        }
    }

    protected void init() {
    }

    protected void doStart() throws LifecycleException {
    }

    protected void doStop() throws LifecycleException {
    }

    protected void doClose() throws LifecycleException {
    }

    protected ApplicationContext getApplicationContext() {
        return this.f;
    }

    /*
     * Loose catch block
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    protected void onApplicationEvent(ApplicationEvent applicationEvent) {
        block12: {
            block13: {
                block14: {
                    if (this.c == null) return;
                    if (!(applicationEvent instanceof LicenseChangeEvent)) break block12;
                    break block14;
                    catch (LifecycleException lifecycleException) {
                        throw LifecycleBean.b(lifecycleException);
                    }
                }
                try {
                    if (!this.isStarted()) break block13;
                    return;
                    catch (LifecycleException lifecycleException) {
                        throw LifecycleBean.b(lifecycleException);
                    }
                }
                catch (LifecycleException lifecycleException) {
                    throw LifecycleBean.b(lifecycleException);
                }
            }
            try {
                if (!this.isLicensed()) return;
                Background.scheduleOneShot((TimerTask)new b5(this), (long)250L);
                return;
            }
            catch (LifecycleException lifecycleException) {
                throw LifecycleBean.b(lifecycleException);
            }
        }
        try {
            if (!(applicationEvent instanceof Stopped)) return;
            this.stop();
            return;
        }
        catch (BeansException beansException) {
            throw LifecycleBean.b((Exception)((Object)beansException));
        }
        {
            catch (LifecycleException lifecycleException) {
                this.a.log(Level.SEVERE, R[6] + ExceptionUtils.getMessage((Throwable)lifecycleException), lifecycleException);
            }
        }
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void a(int var0) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [0[TRYBLOCK]], but top level block is 1[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1050)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

    private static Exception b(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[8];
                var3_1 = 0;
                var2_2 = "^)}V?\\\u0015\u00030cS\"\u0001X\u0016)|Q\u000e\u0014\\\f4CM$\u001a@\u001f\u0001/~\u0010'UM\u0007#{\u00108\u0007K\u0014%a\u0010\u0007\u000b_\u0007#j\\'\u0007{\u0007!}\u0006\u000e/tX.\u0010>#2tJ&\u0007W\u0016`uP9By,/gq>\u000eUB0rM*\u000f\\\u0016%a\u001flGJE`|YkGJLe`\u001f&\u0017J\u0016`}P?B[\u0007`}J'\u000e\u0004\f!~Z";
                var4_3 = "^)}V?\\\u0015\u00030cS\"\u0001X\u0016)|Q\u000e\u0014\\\f4CM$\u001a@\u001f\u0001/~\u0010'UM\u0007#{\u00108\u0007K\u0014%a\u0010\u0007\u000b_\u0007#j\\'\u0007{\u0007!}\u0006\u000e/tX.\u0010>#2tJ&\u0007W\u0016`uP9By,/gq>\u000eUB0rM*\u000f\\\u0016%a\u001flGJE`|YkGJLe`\u001f&\u0017J\u0016`}P?B[\u0007`}J'\u000e\u0004\f!~Z".length();
                var1_4 = 6;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 77;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = LifecycleBean.a(v0, LifecycleBean.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "=$xW-\r\u0013\u001c%9F5\u0007CH9lW2\u0011@\u001c/t\u000fa\u000e\u0004#zP/\u001bV./xA4\u001aV";
                    var4_3 = "=$xW-\r\u0013\u001c%9F5\u0007CH9lW2\u0011@\u001c/t\u000fa\u000e\u0004#zP/\u001bV./xA4\u001aV".length();
                    var1_4 = 26;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 71;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = LifecycleBean.a(v0, LifecycleBean.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        LifecycleBean.R = var5;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x74);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 47;
                    case 1 -> 13;
                    case 2 -> 94;
                    case 3 -> 114;
                    case 4 -> 6;
                    case 5 -> 47;
                    default -> 116;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

